Java Code Examples for javax.xml.soap.SOAPBody#addDocument()

The following examples show how to use javax.xml.soap.SOAPBody#addDocument() . 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: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example 2
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example 3
Source File: SOAPUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SOAPMessage newSOAPMessage(String payload) throws TechnicalConnectorException {
   try {
      SOAPMessage response = MF.createMessage();
      SOAPPart soapPart = response.getSOAPPart();
      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(ConnectorXmlUtils.toDocument(payload));
      return response;
   } catch (Exception var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_TECHNICAL, var5, new Object[0]);
   }
}
 
Example 4
Source File: SOAPUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SOAPMessage newSOAPMessage(String payload) throws TechnicalConnectorException {
   try {
      SOAPMessage response = MF.createMessage();
      SOAPPart soapPart = response.getSOAPPart();
      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(ConnectorXmlUtils.toDocument(payload));
      return response;
   } catch (Exception var5) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_TECHNICAL, var5, new Object[0]);
   }
}
 
Example 5
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example 6
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example 7
Source File: AbstractWsSender.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
protected SOAPMessageContext createSOAPMessageCtx(GenericRequest genericRequest) throws TechnicalConnectorException {
   try {
      SOAPMessage soapMessage = mf.createMessage();
      SOAPPart soapPart = soapMessage.getSOAPPart();
      if (genericRequest.isXopEnabled()) {
         soapMessage.getMimeHeaders().addHeader("Content-Type", "application/xop+xml");
         soapPart.addMimeHeader("Content-ID", "<[email protected]>");
         soapPart.addMimeHeader("Content-Transfer-Encoding", "8bit");
      }

      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(genericRequest.getPayload());
      Map<String, DataHandler> handlers = genericRequest.getDataHandlerMap();

      AttachmentPart part;
      for(Iterator i$ = handlers.entrySet().iterator(); i$.hasNext(); soapMessage.addAttachmentPart(part)) {
         Entry<String, DataHandler> handlerEntry = (Entry)i$.next();
         DataHandler handler = (DataHandler)handlerEntry.getValue();
         part = soapMessage.createAttachmentPart(handler);
         part.setContentType(handler.getContentType());
         if (genericRequest.isXopEnabled()) {
            part.addMimeHeader("Content-Transfer-Encoding", "binary");
            part.setContentId("<" + (String)handlerEntry.getKey() + ">");
         } else {
            part.setContentId((String)handlerEntry.getKey());
         }
      }

      return createSOAPMessageCtx(soapMessage);
   } catch (SOAPException var11) {
      throw translate(var11);
   }
}
 
Example 8
Source File: SOAPUtils.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static SOAPMessage newSOAPMessage(String payload) throws TechnicalConnectorException {
   try {
      SOAPMessage response = MF.createMessage();
      SOAPPart soapPart = response.getSOAPPart();
      SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
      SOAPBody soapBody = soapEnvelope.getBody();
      soapBody.addDocument(ConnectorXmlUtils.toDocument(payload));
      return response;
   } catch (Exception ex) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_TECHNICAL, ex);
   }
}
 
Example 9
Source File: DocumentWebServiceAdapter.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Create the SOAP request object based on the document variable value.
 */
protected SOAPMessage createSoapRequest(Object requestObj) throws ActivityException {
    try {
        MessageFactory messageFactory = getSoapMessageFactory();
        SOAPMessage soapMessage = messageFactory.createMessage();
        Map<Name,String> soapReqHeaders = getSoapRequestHeaders();
        if (soapReqHeaders != null) {
            SOAPHeader header = soapMessage.getSOAPHeader();
            for (Name name : soapReqHeaders.keySet()) {
                header.addHeaderElement(name).setTextContent(soapReqHeaders.get(name));
            }
        }

        SOAPBody soapBody = soapMessage.getSOAPBody();

        Document requestDoc = null;
        if (requestObj instanceof String) {
            requestDoc = DomHelper.toDomDocument((String)requestObj);
            soapBody.addDocument(requestDoc);
        }
        else {
            Variable reqVar = getProcessDefinition().getVariable(getAttributeValue(REQUEST_VARIABLE));
            XmlDocumentTranslator docRefTrans = (XmlDocumentTranslator)getPackage().getTranslator(reqVar.getType());
            requestDoc = docRefTrans.toDomDocument(requestObj);
            Document copiedDocument = DomHelper.copyDomDocument(requestDoc);
            soapBody.addDocument(copiedDocument);
        }

        return soapMessage;
    }
    catch (Exception ex) {
        throw new ActivityException(ex.getMessage(), ex);
    }
}
 
Example 10
Source File: SoapServlet.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * Allow version specific factory passed in TODO: allow specifying response
 * headers
 */
protected String createSoapResponse(String soapVersion, String xml) throws SOAPException {
    try {
        SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        soapBody.addDocument(DomHelper.toDomDocument(xml));
        return DomHelper.toXml(soapMessage.getSOAPPart().getDocumentElement());
    }
    catch (Exception ex) {
        throw new SOAPException(ex.getMessage(), ex);
    }
}
 
Example 11
Source File: SoapServlet.java    From mdw with Apache License 2.0 5 votes vote down vote up
protected String createOldStyleSoapResponse(String soapVersion, String xml)
        throws SOAPException {
    try {
        SOAPMessage soapMessage = getSoapMessageFactory(soapVersion).createMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        soapBody.addDocument(DomHelper.toDomDocument(xml));
        return DomHelper.toXmlNoWhiteSpace(soapMessage.getSOAPPart());
    }
    catch (Exception ex) {
        throw new SOAPException(ex.getMessage(), ex);
    }
}