public void writeTo(JAXBElement<?> obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { super.writeTo(obj, cls, genericType, anns, m, headers, os); } }
@Override public void writeTo(Book obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { headers.putSingle("Content-Type", MediaType.valueOf(m.toString() + ";a=b")); super.writeTo(obj, cls, genericType, anns, m, headers, os); } }
@Override public void writeTo(Object obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { List<String> failHeaders = getContext().getHttpHeaders().getRequestHeader("fail-write"); if (failHeaders != null && !failHeaders.isEmpty()) { os.write("fail".getBytes()); throw new IOException(); } super.writeTo(obj, cls, genericType, anns, m, headers, os); } }
@SuppressWarnings("unchecked") private Document getDomDocument(Message m) throws Exception { Object body = getRequestBody(m); if (body == null) { return null; } if (body instanceof Document) { return (Document)body; } if (body instanceof DOMSource) { return (Document)((DOMSource)body).getNode(); } ProviderFactory pf = ProviderFactory.getInstance(m); Object providerObject = pf.createMessageBodyWriter(body.getClass(), body.getClass(), new Annotation[]{}, MediaType.APPLICATION_XML_TYPE, m); if (!(providerObject instanceof JAXBElementProvider)) { return null; } JAXBElementProvider<Object> provider = (JAXBElementProvider<Object>)providerObject; W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); m.setContent(XMLStreamWriter.class, writer); provider.writeTo(body, body.getClass(), new Annotation[]{}, MediaType.APPLICATION_XML_TYPE, (MultivaluedMap<String, Object>)m.get(Message.PROTOCOL_HEADERS), null); return writer.getDocument(); }
@SuppressWarnings("unchecked") private Document getDomDocument(Message m) throws Exception { Object body = getRequestBody(m); if (body == null) { return null; } if (body instanceof Document) { return (Document)body; } if (body instanceof DOMSource) { return (Document)((DOMSource)body).getNode(); } ProviderFactory pf = ProviderFactory.getInstance(m); Object providerObject = pf.createMessageBodyWriter(body.getClass(), body.getClass(), new Annotation[]{}, MediaType.APPLICATION_XML_TYPE, m); if (!(providerObject instanceof JAXBElementProvider)) { return null; } JAXBElementProvider<Object> provider = (JAXBElementProvider<Object>)providerObject; W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); m.setContent(XMLStreamWriter.class, writer); provider.writeTo(body, body.getClass(), new Annotation[]{}, MediaType.APPLICATION_XML_TYPE, (MultivaluedMap<String, Object>)m.get(Message.PROTOCOL_HEADERS), null); return writer.getDocument(); }
public void writeTo(GenericHandler<Book> o, Class<?> c, Type t, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { jaxb.writeTo(o.getEntity(), o.getEntity().getClass(), InjectionUtils.getActualType(t), anns, m, headers, os); }