コード例 #1
0
  /**
   * Creates a {@link Message} backed by a JAXB bean.
   *
   * @param context The JAXBContext to be used for marshalling.
   * @param jaxbObject The JAXB object that represents the payload. must not be null. This object
   *     must be bound to an element (which means it either is a {@link JAXBElement} or an
   *     instanceof a class with {@link XmlRootElement}).
   * @param soapVersion The SOAP version of the message. Must not be null.
   */
  public static Message create(JAXBRIContext context, Object jaxbObject, SOAPVersion soapVersion) {
    if (!context.hasSwaRef()) {
      return new JAXBMessage(context, jaxbObject, soapVersion);
    }

    // If we have swaRef, then that means we might have attachments.
    // to comply with the packet API, we need to eagerly turn the JAXB object into infoset
    // to correctly find out about attachments.

    try {
      MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();

      Marshaller m = context.createMarshaller();
      AttachmentSetImpl attachments = new AttachmentSetImpl();
      AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
      m.setAttachmentMarshaller(am);
      am.cleanup();
      m.marshal(jaxbObject, xsb.createFromXMLStreamWriter());

      // any way to reuse this XMLStreamBuffer in StreamMessage?
      return new StreamMessage(null, attachments, xsb.readAsXMLStreamReader(), soapVersion);
    } catch (JAXBException e) {
      throw new WebServiceException(e);
    } catch (XMLStreamException e) {
      throw new WebServiceException(e);
    }
  }
コード例 #2
0
 /*     */ public static Message create(
     JAXBRIContext context,
     Object jaxbObject,
     SOAPVersion soapVersion,
     HeaderList headers,
     AttachmentSet attachments)
       /*     */ {
   /*  93 */ if (!context.hasSwaRef()) {
     /*  94 */ return new JAXBMessage(context, jaxbObject, soapVersion, headers, attachments);
     /*     */ }
   /*     */
   /*     */ try
   /*     */ {
     /* 102 */ MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer();
     /*     */
     /* 104 */ Marshaller m = context.createMarshaller();
     /* 105 */ AttachmentMarshallerImpl am = new AttachmentMarshallerImpl(attachments);
     /* 106 */ m.setAttachmentMarshaller(am);
     /* 107 */ am.cleanup();
     /* 108 */ m.marshal(jaxbObject, xsb.createFromXMLStreamWriter());
     /*     */
     /* 111 */ return new StreamMessage(
         headers, attachments, xsb.readAsXMLStreamReader(), soapVersion);
     /*     */ } catch (JAXBException e) {
     /* 113 */ throw new WebServiceException(e);
     /*     */ } catch (XMLStreamException e) {
     /* 115 */ throw new WebServiceException(e);
     /*     */ }
   /*     */ }
コード例 #3
0
 @NotNull
 public JAXBRIContext createJAXBContext(
     @NotNull SEIModel sei,
     @NotNull List<Class> classesToBind,
     @NotNull List<TypeReference> typeReferences)
     throws JAXBException {
   return JAXBRIContext.newInstance(
       classesToBind.toArray(new Class[classesToBind.size()]),
       typeReferences,
       null,
       sei.getTargetNamespace(),
       false,
       null);
 }