Java Code Examples for javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller()

The following examples show how to use javax.xml.bind.Unmarshaller#setAttachmentUnmarshaller() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMMessage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    if(hasAttachments())
        unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
    try {
        return (T)unmarshaller.unmarshal(payload);
    } finally{
        unmarshaller.setAttachmentUnmarshaller(null);
    }
}
 
Example 2
Source File: SAAJMessage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    access();
    if (payload != null) {
        if(hasAttachments())
            unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
        return (T) unmarshaller.unmarshal(payload);

    }
    return null;
}
 
Example 3
Source File: SAAJMessage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    access();
    if (payload != null) {
        if(hasAttachments())
            unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
        return (T) unmarshaller.unmarshal(payload);

    }
    return null;
}
 
Example 4
Source File: MarshallerHelper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private Unmarshaller getUnMarshaller() throws JAXBException {
   AttachmentUnmarshallerImpl attachmentUnmarshaller = new AttachmentUnmarshallerImpl(true);
   attachmentUnmarshaller.getAttachmentPartMap().putAll(this.attachmentParts);
   Unmarshaller unmarshaller = JaxbContextFactory.getJaxbContextForClass(this.unmarshallClass).createUnmarshaller();
   unmarshaller.setAttachmentUnmarshaller(attachmentUnmarshaller);
   return unmarshaller;
}
 
Example 5
Source File: DOMMessage.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public <T> T readPayloadAsJAXB(Unmarshaller unmarshaller) throws JAXBException {
    if(hasAttachments())
        unmarshaller.setAttachmentUnmarshaller(new AttachmentUnmarshallerImpl(getAttachments()));
    try {
        return (T)unmarshaller.unmarshal(payload);
    } finally{
        unmarshaller.setAttachmentUnmarshaller(null);
    }
}
 
Example 6
Source File: OldBridge.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,n),u);
}
 
Example 7
Source File: OldBridge.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 8
Source File: AbstractXTeeJAXBEndpoint.java    From j-road with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void invokeInternal(final XTeeMessage<Document> request, final XTeeMessage<Element> response)
    throws Exception {
  if (getParingKehaClass() == null) {
    throw new IllegalStateException("Query body class ('requestClass') is unset/unspecified!");
  }

  JAXBContext requestJc = getJAXBContextInstance();
  Unmarshaller requestUnmarshaller = requestJc.createUnmarshaller();
  requestUnmarshaller.setAttachmentUnmarshaller(new XTeeAttachmentUnmarshaller(request));

  updateUnmarshaller(requestUnmarshaller);

  Document requestOnly = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
  if (XRoadProtocolVersion.V2_0 == version) {
    requestOnly.appendChild(requestOnly.importNode((Node) XPathFactory.newInstance().newXPath().evaluate("//*[local-name()='keha']",
                                                                                                         request.getContent(),
                                                                                                         XPathConstants.NODE),
                                                   true));
  } else {
    requestOnly.appendChild(requestOnly.importNode(SOAPUtil.getFirstNonTextChild(request.getContent()), true));
  }

  XTeeMessage<T> jaxbRequestMessage = new BeanXTeeMessage<T>(request.getHeader(),
                                                             requestUnmarshaller.unmarshal(requestOnly.getDocumentElement(),
                                                                                           getParingKehaClass()).getValue(),
                                                             request.getAttachments());
  XTeeMessage<Object> jaxbResponseMessage =
      new BeanXTeeMessage<Object>(response.getHeader(), null, new ArrayList<XTeeAttachment>());

  invoke(jaxbRequestMessage, jaxbResponseMessage);
  Object bean = jaxbResponseMessage.getContent();
  if (bean != null) { // If you do not need to send an object as response, <keha /> is sufficient.
    Node parent = response.getContent().getParentNode();
    Node child = parent.removeChild(response.getContent());
    JAXBContext responseJc = getJAXBContextInstance();
    Marshaller responseMarshaller = responseJc.createMarshaller();
    responseMarshaller.setAttachmentMarshaller(new XTeeAttachmentMarshaller(response));
    updateMarshaller(responseMarshaller);
    // TODO Lauri: some namespace hacking might be needed if existing service schema is changed according to new
    // standard while upgrading. J-road clients do not mind tho :)
    if (XRoadProtocolVersion.V2_0 == version) {
      responseMarshaller.marshal(new JAXBElement(new QName("keha"), bean.getClass(), bean), parent);
    } else {
      responseMarshaller.marshal(new JAXBElement(new QName(response.getContent().getNamespaceURI(),
                                                           child.getLocalName(),
                                                           response.getContent().getPrefix()),
                                                 bean.getClass(),
                                                 bean),
                                 parent);
    }
  }
}
 
Example 9
Source File: OldBridge.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 10
Source File: Bridge.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 11
Source File: Bridge.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private T exit(T r, Unmarshaller u) {
    u.setAttachmentUnmarshaller(null);
    context.unmarshallerPool.recycle(u);
    return r;
}
 
Example 12
Source File: Bridge.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 13
Source File: OldBridge.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,n),u);
}
 
Example 14
Source File: OldBridge.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 15
Source File: Bridge.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,n),u);
}
 
Example 16
Source File: OldBridge.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,n),u);
}
 
Example 17
Source File: OldBridge.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull XMLStreamReader in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 18
Source File: OldBridge.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private T exit(T r, Unmarshaller u) {
    u.setAttachmentUnmarshaller(null);
    context.unmarshallerPool.recycle(u);
    return r;
}
 
Example 19
Source File: Bridge.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Source in, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,in),u);
}
 
Example 20
Source File: OldBridge.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 2.0.3
 */
public final @NotNull T unmarshal(@NotNull Node n, @Nullable AttachmentUnmarshaller au) throws JAXBException {
    Unmarshaller u = context.unmarshallerPool.take();
    u.setAttachmentUnmarshaller(au);
    return exit(unmarshal(u,n),u);
}