public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { MultipartRelatedOutput xopPackage = new MultipartRelatedOutput(); XopWithMultipartRelatedJAXBProvider xopWithMultipartRelatedJAXBProvider = new XopWithMultipartRelatedJAXBProvider( workers); xopWithMultipartRelatedJAXBProvider.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, xopPackage); writeRelated(xopPackage, mediaType, httpHeaders, entityStream); }
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); } }
protected void writeRelated(MultipartRelatedOutput multipartRelatedOutput, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { for (OutputPart outputPart : multipartRelatedOutput.getParts()) if (outputPart.getHeaders().get("Content-ID") == null) outputPart.getHeaders().putSingle("Content-ID", ContentIDUtils.generateContentID()); OutputPart rootOutputPart = multipartRelatedOutput.getRootPart(); Map<String, String> mediaTypeParameters = new LinkedHashMap<String, String>( mediaType.getParameters()); if (mediaTypeParameters.containsKey("boundary")) multipartRelatedOutput.setBoundary(mediaTypeParameters .get("boundary")); mediaTypeParameters.put("start", (String) rootOutputPart.getHeaders() .getFirst("Content-ID")); mediaTypeParameters.put("type", rootOutputPart.getMediaType().getType() + "/" + rootOutputPart.getMediaType().getSubtype()); if (multipartRelatedOutput.getStartInfo() != null) mediaTypeParameters.put("start-info", multipartRelatedOutput .getStartInfo()); MediaType modifiedMediaType = new MediaType(mediaType.getType(), mediaType.getSubtype(), mediaTypeParameters); write(multipartRelatedOutput, modifiedMediaType, httpHeaders, entityStream); } }
ClientRequest request = createClientRequest(atomUrl); MultipartRelatedOutput output = new MultipartRelatedOutput(); output.addPart(atomEntry, mediaType); output.addPart(content, mediaType2);
protected String addBinary(Object object, String mimeType) { String addrSpec = ContentIDUtils.generateRFC822AddrSpec(); String contentID = ContentIDUtils .generateContentIDFromAddrSpec(addrSpec); xopPackage.addPart(object, MediaType.valueOf(mimeType), contentID, "binary"); return ContentIDUtils.generateCidFromAddrSpec(addrSpec); }
/** * The part that will be used as the root. * * @return the first in the list of added parts. */ public OutputPart getRootPart() { return getParts().get(0); }
ClientRequest request = createClientRequest(atomUrl); MultipartRelatedOutput output = new MultipartRelatedOutput(); output.addPart(atomEntry, mediaType); output.addPart(content, mediaType2);
protected String addBinary(Object object, String mimeType) { String addrSpec = ContentIDUtils.generateRFC822AddrSpec(); String contentID = ContentIDUtils .generateContentIDFromAddrSpec(addrSpec); xopPackage.addPart(object, MediaType.valueOf(mimeType), contentID, "binary"); return ContentIDUtils.generateCidFromAddrSpec(addrSpec); }
/** * The part that will be used as the root. * * @return the first in the list of added parts. */ public OutputPart getRootPart() { return getParts().get(0); }
protected void writeRelated(MultipartRelatedOutput multipartRelatedOutput, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { for (OutputPart outputPart : multipartRelatedOutput.getParts()) if (outputPart.getHeaders().get("Content-ID") == null) outputPart.getHeaders().putSingle("Content-ID", ContentIDUtils.generateContentID()); OutputPart rootOutputPart = multipartRelatedOutput.getRootPart(); Map<String, String> mediaTypeParameters = new LinkedHashMap<String, String>( mediaType.getParameters()); if (mediaTypeParameters.containsKey("boundary")) multipartRelatedOutput.setBoundary(mediaTypeParameters .get("boundary")); mediaTypeParameters.put("start", (String) rootOutputPart.getHeaders() .getFirst("Content-ID")); mediaTypeParameters.put("type", rootOutputPart.getMediaType().getType() + "/" + rootOutputPart.getMediaType().getSubtype()); if (multipartRelatedOutput.getStartInfo() != null) mediaTypeParameters.put("start-info", multipartRelatedOutput .getStartInfo()); MediaType modifiedMediaType = new MediaType(mediaType.getType(), mediaType.getSubtype(), mediaTypeParameters); write(multipartRelatedOutput, modifiedMediaType, httpHeaders, entityStream); } }
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, OutputStream entityStream) throws IOException, WebApplicationException { MultipartRelatedOutput xopPackage = new MultipartRelatedOutput(); XopWithMultipartRelatedJAXBProvider xopWithMultipartRelatedJAXBProvider = new XopWithMultipartRelatedJAXBProvider( workers); xopWithMultipartRelatedJAXBProvider.writeTo(t, type, genericType, annotations, mediaType, httpHeaders, xopPackage); writeRelated(xopPackage, mediaType, httpHeaders, entityStream); }