public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, final MultipartRelatedOutput xopPackage) throws IOException { try { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); Map<String, String> mediaTypeParameters = new LinkedHashMap<String, String>(); mediaTypeParameters.put("charset", StandardCharsets.UTF_8.name()); mediaTypeParameters.put("type", "text/xml"); MediaType xopRootMediaType = new MediaType("application", "xop+xml", mediaTypeParameters); Marshaller marshaller = getMarshaller(type, annotations, xopRootMediaType); marshaller.setAttachmentMarshaller(new XopAttachmentMarshaller( xopPackage)); ByteArrayOutputStream xml = new ByteArrayOutputStream(); marshaller.marshal(t, xml); OutputPart outputPart = xopPackage.addPart(xml.toByteArray(), xopRootMediaType, ContentIDUtils.generateContentID(), null); List<OutputPart> outputParts = xopPackage.getParts(); outputParts.remove(outputPart); outputParts.add(0, outputPart); } catch (JAXBException e) { Response response = Response.serverError().build(); throw new WebApplicationException(e, response); } }
public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, final MultipartRelatedOutput xopPackage) throws IOException { try { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); Map<String, String> mediaTypeParameters = new LinkedHashMap<String, String>(); mediaTypeParameters.put("charset", StandardCharsets.UTF_8.name()); mediaTypeParameters.put("type", "text/xml"); MediaType xopRootMediaType = new MediaType("application", "xop+xml", mediaTypeParameters); Marshaller marshaller = getMarshaller(type, annotations, xopRootMediaType); marshaller.setAttachmentMarshaller(new XopAttachmentMarshaller( xopPackage)); ByteArrayOutputStream xml = new ByteArrayOutputStream(); marshaller.marshal(t, xml); OutputPart outputPart = xopPackage.addPart(xml.toByteArray(), xopRootMediaType, ContentIDUtils.generateContentID(), null); List<OutputPart> outputParts = xopPackage.getParts(); outputParts.remove(outputPart); outputParts.add(0, outputPart); } catch (JAXBException e) { Response response = Response.serverError().build(); throw new WebApplicationException(e, response); } }