private void reportError(String message, Exception ex) { reportError(message, ex, 500); }
private void reportError(String message, Exception ex) { reportError(message, ex, 500); }
private void reportError(String message, Exception ex) { reportError(message, ex, 500); }
private String getCollectionMethod(Class<?> cls, boolean getter) { Map<String, String> map = getter ? collectionGetters : collectionSetters; String methodName = getCollectionMethod(map, cls); if (methodName == null) { try { methodName = (getter ? "get" : "set") + cls.getSimpleName(); Class<?>[] params = getter ? new Class[]{} : new Class[]{List.class}; cls.getMethod(methodName, params); } catch (Exception ex) { String type = getter ? "getter" : "setter"; reportError("Collection " + type + " method for " + cls.getName() + " has not been specified and no default " + methodName + " is available", null); } } return methodName; }
private String getCollectionMethod(Class<?> cls, boolean getter) { Map<String, String> map = getter ? collectionGetters : collectionSetters; String methodName = getCollectionMethod(map, cls); if (methodName == null) { try { methodName = (getter ? "get" : "set") + cls.getSimpleName(); Class<?>[] params = getter ? new Class[]{} : new Class[]{List.class}; cls.getMethod(methodName, params); } catch (Exception ex) { String type = getter ? "getter" : "setter"; reportError("Collection " + type + " method for " + cls.getName() + " has not been specified and no default " + methodName + " is available", null); } } return methodName; }
private String getCollectionMethod(Class<?> cls, boolean getter) { Map<String, String> map = getter ? collectionGetters : collectionSetters; String methodName = getCollectionMethod(map, cls); if (methodName == null) { try { methodName = (getter ? "get" : "set") + cls.getSimpleName(); Class<?>[] params = getter ? new Class[]{} : new Class[]{List.class}; cls.getMethod(methodName, params); } catch (Exception ex) { String type = getter ? "getter" : "setter"; reportError("Collection " + type + " method for " + cls.getName() + " has not been specified and no default " + methodName + " is available", null); } } return methodName; }
protected Feed createFeedFromCollectionWrapper(Factory factory, Object o, Class<?> pojoClass) throws Exception { Feed feed = factory.newFeed(); boolean writerUsed = buildFeed(feed, o, pojoClass); if (feed.getEntries().size() > 0) { return feed; } String methodName = getCollectionMethod(o.getClass(), true); Object collection = null; Method m = null; try { m = o.getClass().getMethod(methodName, new Class[]{}); collection = m.invoke(o, new Object[]{}); } catch (Exception ex) { reportError("Collection for " + o.getClass().getName() + " can not be retrieved", ex); } setFeedFromCollection(factory, feed, o, pojoClass, collection, m.getReturnType(), m.getGenericReturnType(), writerUsed); return feed; }
protected Feed createFeedFromCollectionWrapper(Factory factory, Object o, Class<?> pojoClass) throws Exception { Feed feed = factory.newFeed(); boolean writerUsed = buildFeed(feed, o, pojoClass); if (feed.getEntries().size() > 0) { return feed; } String methodName = getCollectionMethod(o.getClass(), true); Object collection = null; Method m = null; try { m = o.getClass().getMethod(methodName, new Class[]{}); collection = m.invoke(o, new Object[]{}); } catch (Exception ex) { reportError("Collection for " + o.getClass().getName() + " can not be retrieved", ex); } setFeedFromCollection(factory, feed, o, pojoClass, collection, m.getReturnType(), m.getGenericReturnType(), writerUsed); return feed; }
protected Feed createFeedFromCollectionWrapper(Factory factory, Object o, Class<?> pojoClass) throws Exception { Feed feed = factory.newFeed(); boolean writerUsed = buildFeed(feed, o, pojoClass); if (feed.getEntries().size() > 0) { return feed; } String methodName = getCollectionMethod(o.getClass(), true); Object collection = null; Method m = null; try { m = o.getClass().getMethod(methodName, new Class[]{}); collection = m.invoke(o, new Object[]{}); } catch (Exception ex) { reportError("Collection for " + o.getClass().getName() + " can not be retrieved", ex); } setFeedFromCollection(factory, feed, o, pojoClass, collection, m.getReturnType(), m.getGenericReturnType(), writerUsed); return feed; }
public void writeTo(Object o, Class<?> cls, Type genericType, Annotation[] annotations, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { boolean isFeed = isFeedRequested(mt); boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(cls); if (isFeed && isCollection) { reportError("Atom feed can only be created from a collection wrapper", null); } else if (!isFeed && isCollection) { reportError("Atom entry can only be created from a single object", null); } Factory factory = Abdera.getNewFactory(); Element atomElement = null; try { if (isFeed && !isCollection) { atomElement = createFeedFromCollectionWrapper(factory, o, cls); } else if (!isFeed && !isCollection) { atomElement = createEntryFromObject(factory, o, cls); } } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } try { writeAtomElement(atomElement, os); } catch (IOException ex) { reportError("Atom element can not be serialized", ex); } }
@SuppressWarnings("unchecked") private Object readFromEntry(Entry entry, Class<Object> cls) throws IOException { AtomElementReader<?, ?> reader = getAtomReader(cls); if (reader != null) { return ((AtomElementReader<Entry, Object>)reader).readFrom(entry); } String entryContent = entry.getContent(); if (entryContent != null) { XMLStreamReader xreader = StaxUtils.createXMLStreamReader(new StringReader(entryContent)); try { Unmarshaller um = jaxbProvider.getJAXBContext(cls, cls).createUnmarshaller(); return cls.cast(um.unmarshal(xreader)); } catch (Exception ex) { reportError("Object of type " + cls.getName() + " can not be deserialized from Entry", ex, 400); } finally { try { StaxUtils.close(xreader); } catch (XMLStreamException e) { //ignore } } } return null; }
@SuppressWarnings("unchecked") private Object readFromEntry(Entry entry, Class<Object> cls) throws IOException { AtomElementReader<?, ?> reader = getAtomReader(cls); if (reader != null) { return ((AtomElementReader<Entry, Object>)reader).readFrom(entry); } String entryContent = entry.getContent(); if (entryContent != null) { XMLStreamReader xreader = StaxUtils.createXMLStreamReader(new StringReader(entryContent)); try { Unmarshaller um = jaxbProvider.getJAXBContext(cls, cls).createUnmarshaller(); return cls.cast(um.unmarshal(xreader)); } catch (Exception ex) { reportError("Object of type " + cls.getName() + " can not be deserialized from Entry", ex, 400); } finally { if (xreader != null) { StaxUtils.close(xreader); } } } return null; }
@SuppressWarnings("unchecked") private Object readFromEntry(Entry entry, Class<Object> cls) throws IOException { AtomElementReader<?, ?> reader = getAtomReader(cls); if (reader != null) { return ((AtomElementReader<Entry, Object>)reader).readFrom(entry); } String entryContent = entry.getContent(); if (entryContent != null) { XMLStreamReader xreader = StaxUtils.createXMLStreamReader(new StringReader(entryContent)); try { Unmarshaller um = jaxbProvider.getJAXBContext(cls, cls).createUnmarshaller(); return cls.cast(um.unmarshal(xreader)); } catch (Exception ex) { reportError("Object of type " + cls.getName() + " can not be deserialized from Entry", ex, 400); } finally { try { StaxUtils.close(xreader); } catch (XMLStreamException e) { //ignore } } } return null; }
reportError("Atom feed can only be created from a collection wrapper", null); } else if (!isFeed && isCollection) { reportError("Atom entry can only be created from a single object", null); writeAtomElement(atomElement, os); } catch (IOException ex) { reportError("Atom element can not be serialized", ex);
public void writeTo(Object o, Class<?> cls, Type genericType, Annotation[] annotations, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { boolean isFeed = isFeedRequested(mt); boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(cls); if (isFeed && isCollection) { reportError("Atom feed can only be created from a collection wrapper", null); } else if (!isFeed && isCollection) { reportError("Atom entry can only be created from a single object", null); } Factory factory = Abdera.getNewFactory(); Element atomElement = null; try { if (isFeed && !isCollection) { atomElement = createFeedFromCollectionWrapper(factory, o, cls); } else if (!isFeed && !isCollection) { atomElement = createEntryFromObject(factory, o, cls); } } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } try { writeAtomElement(atomElement, os); } catch (IOException ex) { reportError("Atom element can not be serialized", ex); } }
reportError("Object of type " + cls.getName() + " can not be deserialized from Feed", ex, 400);
reportError("Object of type " + cls.getName() + " can not be deserialized from Feed", ex, 400);
reportError("Object of type " + cls.getName() + " can not be deserialized from Feed", ex, 400);