Example usage for javax.xml.soap MimeHeaders addHeader

List of usage examples for javax.xml.soap MimeHeaders addHeader

Introduction

In this page you can find the example usage for javax.xml.soap MimeHeaders addHeader.

Prototype

public void addHeader(String name, String value) 

Source Link

Document

Adds a MimeHeader object with the specified name and value to this MimeHeaders object's list of headers.

Usage

From source file:org.cerberus.service.soap.impl.SoapService.java

@Override
public SOAPMessage createSoapRequest(String envelope, String method)
        throws SOAPException, IOException, SAXException, ParserConfigurationException {
    String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);
    boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();

    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("SOAPAction", "\"" + method + "\"");
    headers.addHeader("Content-Type",
            is12SoapVersion ? SOAPConstants.SOAP_1_2_CONTENT_TYPE : SOAPConstants.SOAP_1_1_CONTENT_TYPE);

    InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8"));
    MessageFactory messageFactory = MessageFactory
            .newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL);
    return messageFactory.createMessage(headers, input);
}

From source file:org.eclipse.mylyn.internal.provisional.commons.soap.CommonsHttpSender.java

/**
 * invoke creates a socket connection, sends the request SOAP message and then reads the response SOAP message back
 * from the SOAP server// w w w  .  j a  va  2 s . com
 * 
 * @param msgContext
 *            the messsage context
 * @throws AxisFault
 */
public void invoke(MessageContext msgContext) throws AxisFault {
    HttpMethodBase method = null;
    //      if (log.isDebugEnabled()) {
    //         log.debug(Messages.getMessage("enter00", "CommonsHTTPSender::invoke"));
    //      }
    try {
        URL targetURL = new URL(msgContext.getStrProp(MessageContext.TRANS_URL));

        // no need to retain these, as the cookies/credentials are
        // stored in the message context across multiple requests.
        // the underlying connection manager, however, is retained
        // so sockets get recycled when possible.
        HttpClient httpClient = new HttpClient(this.connectionManager);
        // the timeout value for allocation of connections from the pool
        httpClient.getParams().setConnectionManagerTimeout(this.clientProperties.getConnectionPoolTimeout());

        HostConfiguration hostConfiguration = getHostConfiguration(httpClient, msgContext, targetURL);

        boolean posting = true;

        // If we're SOAP 1.2, allow the web method to be set from the
        // MessageContext.
        if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
            String webMethod = msgContext.getStrProp(SOAP12Constants.PROP_WEBMETHOD);
            if (webMethod != null) {
                posting = webMethod.equals(HTTPConstants.HEADER_POST);
            }
        }

        if (posting) {
            Message reqMessage = msgContext.getRequestMessage();
            method = new PostMethod(targetURL.toString());

            // set false as default, addContetInfo can overwrite
            method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false);

            addContextInfo(method, httpClient, msgContext, targetURL);

            MessageRequestEntity requestEntity = null;
            if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
                requestEntity = new GzipMessageRequestEntity(method, reqMessage, httpChunkStream);
            } else {
                requestEntity = new MessageRequestEntity(method, reqMessage, httpChunkStream);
            }
            ((PostMethod) method).setRequestEntity(requestEntity);
        } else {
            method = new GetMethod(targetURL.toString());
            addContextInfo(method, httpClient, msgContext, targetURL);
        }

        String httpVersion = msgContext.getStrProp(MessageContext.HTTP_TRANSPORT_VERSION);
        if (httpVersion != null) {
            if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_V10)) {
                method.getParams().setVersion(HttpVersion.HTTP_1_0);
            }
            // assume 1.1
        }

        // don't forget the cookies!
        // Cookies need to be set on HttpState, since HttpMethodBase 
        // overwrites the cookies from HttpState
        if (msgContext.getMaintainSession()) {
            HttpState state = httpClient.getState();
            method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
            String host = hostConfiguration.getHost();
            String path = targetURL.getPath();
            boolean secure = hostConfiguration.getProtocol().isSecure();
            fillHeaders(msgContext, state, HTTPConstants.HEADER_COOKIE, host, path, secure);
            fillHeaders(msgContext, state, HTTPConstants.HEADER_COOKIE2, host, path, secure);
            httpClient.setState(state);
        }

        int returnCode = httpClient.executeMethod(hostConfiguration, method, null);

        String contentType = getHeader(method, HTTPConstants.HEADER_CONTENT_TYPE);
        String contentLocation = getHeader(method, HTTPConstants.HEADER_CONTENT_LOCATION);
        //         String contentLength = getHeader(method, HTTPConstants.HEADER_CONTENT_LENGTH);

        if ((returnCode > 199) && (returnCode < 300)) {

            // SOAP return is OK - so fall through
        } else if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
            // For now, if we're SOAP 1.2, fall through, since the range of
            // valid result codes is much greater
        } else if ((contentType != null) && !contentType.equals("text/html") //$NON-NLS-1$
                && ((returnCode > 499) && (returnCode < 600))) {

            // SOAP Fault should be in here - so fall through
        } else {
            //            String statusMessage = method.getStatusText();
            //            AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" + statusMessage, null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            try {
                //               fault.setFaultDetailString(Messages.getMessage("return01", "" + returnCode, //$NON-NLS-1$ //$NON-NLS-2$
                //                     method.getResponseBodyAsString()));
                //               fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, Integer.toString(returnCode));
                //               throw fault;
                throw AxisHttpFault.makeFault(method);
            } finally {
                method.releaseConnection(); // release connection back to pool.
            }
        }

        // wrap the response body stream so that close() also releases 
        // the connection back to the pool.
        InputStream releaseConnectionOnCloseStream = createConnectionReleasingInputStream(method);

        Header contentEncoding = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
        if (contentEncoding != null) {
            if (contentEncoding.getValue().equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
                releaseConnectionOnCloseStream = new GZIPInputStream(releaseConnectionOnCloseStream);
            } else if (contentEncoding.getValue().equals("") //$NON-NLS-1$
                    && msgContext.isPropertyTrue(SoapHttpSender.ALLOW_EMPTY_CONTENT_ENCODING)) {
                // assume no encoding
            } else {
                AxisFault fault = new AxisFault("HTTP", "unsupported content-encoding of '" //$NON-NLS-1$ //$NON-NLS-2$
                        + contentEncoding.getValue() + "' found", null, null); //$NON-NLS-1$
                throw fault;
            }

        }
        Message outMsg = new Message(releaseConnectionOnCloseStream, false, contentType, contentLocation);
        // Transfer HTTP headers of HTTP message to MIME headers of SOAP message
        Header[] responseHeaders = method.getResponseHeaders();
        MimeHeaders responseMimeHeaders = outMsg.getMimeHeaders();
        for (Header responseHeader : responseHeaders) {
            responseMimeHeaders.addHeader(responseHeader.getName(), responseHeader.getValue());
        }
        outMsg.setMessageType(Message.RESPONSE);
        msgContext.setResponseMessage(outMsg);
        //         if (log.isDebugEnabled()) {
        //            if (null == contentLength) {
        //               log.debug("\n" + Messages.getMessage("no00", "Content-Length"));
        //            }
        //            log.debug("\n" + Messages.getMessage("xmlRecd00"));
        //            log.debug("-----------------------------------------------");
        //            log.debug(outMsg.getSOAPPartAsString());
        //         }

        // if we are maintaining session state,
        // handle cookies (if any)
        if (msgContext.getMaintainSession()) {
            Header[] headers = method.getResponseHeaders();

            for (Header header : headers) {
                if (header.getName().equalsIgnoreCase(HTTPConstants.HEADER_SET_COOKIE)) {
                    handleCookie(HTTPConstants.HEADER_COOKIE, header.getValue(), msgContext);
                } else if (header.getName().equalsIgnoreCase(HTTPConstants.HEADER_SET_COOKIE2)) {
                    handleCookie(HTTPConstants.HEADER_COOKIE2, header.getValue(), msgContext);
                }
            }
        }

        // always release the connection back to the pool if 
        // it was one way invocation
        if (msgContext.isPropertyTrue("axis.one.way")) { //$NON-NLS-1$
            method.releaseConnection();
        }

    } catch (Exception e) {
        //         log.debug(e);
        throw AxisFault.makeFault(e);
    }

    //      if (log.isDebugEnabled()) {
    //         log.debug(Messages.getMessage("exit00", "CommonsHTTPSender::invoke"));
    //      }
}

From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java

private static SOAPMessage createSOAPRequest(String date) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://ws.i-em.eu/v4/";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);

    // SOAP Body//from  w w w  .  j a va  2 s .c o m
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("Get72hPlantForecast", "example");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("plantID", "example");
    soapBodyElem1.addTextNode("telecom_02");
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("quantityID", "example");
    soapBodyElem2.addTextNode("frc_pac");
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("timestamp", "example");
    soapBodyElem3.addTextNode(date);
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("langID", "example");
    soapBodyElem4.addTextNode("en");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "Get72hPlantForecast");

    soapMessage.saveChanges();

    return soapMessage;
}

From source file:org.freebxml.omar.server.common.Utility.java

/**
 *     Create a SOAPMessage object from a InputStream to a SOAPMessage
 *     @param soapStream the InputStream to the SOAPMessage
 *     @return the created SOAPMessage//from  w w w  . j a  v a2  s . c  om
 */
public SOAPMessage createSOAPMessageFromSOAPStream(InputStream soapStream)
        throws javax.xml.soap.SOAPException, IOException, javax.mail.internet.ParseException {
    javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();

    javax.mail.internet.ContentType contentType = new javax.mail.internet.ContentType("text/xml"); //"multipart/related");

    String contentTypeStr = contentType.toString();

    //System.err.println("contentTypeStr = '" + contentTypeStr + "'");
    mimeHeaders.addHeader("Content-Type", contentTypeStr);
    mimeHeaders.addHeader("Content-Id", "ebXML Registry SOAP request");

    javax.xml.soap.MessageFactory factory = javax.xml.soap.MessageFactory.newInstance();
    SOAPMessage msg = factory.createMessage(mimeHeaders, soapStream);

    msg.saveChanges();

    return msg;
}

From source file:org.mule.transport.soap.axis.extensions.MuleHttpSender.java

/**
 * Reads the SOAP response back from the server
 *
 * @param msgContext message context//  ww  w . j  a  va2 s .c o  m
 * @throws IOException
 */
private InputStream readFromSocket(SocketHolder socketHolder, MessageContext msgContext, InputStream inp,
        Hashtable headers) throws IOException {
    Message outMsg = null;
    byte b;

    Integer rc = (Integer) msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
    int returnCode = 0;
    if (rc != null) {
        returnCode = rc.intValue();
    } else {
        // No return code?? Should have one by now.
    }

    /* All HTTP headers have been read. */
    String contentType = (String) headers.get(HEADER_CONTENT_TYPE_LC);

    contentType = (null == contentType) ? null : contentType.trim();

    String location = (String) headers.get(HEADER_LOCATION_LC);

    location = (null == location) ? null : location.trim();

    if ((returnCode > 199) && (returnCode < 300)) {
        if (returnCode == 202) {
            return inp;
        }
        // SOAP return is OK - so fall through
    } else if (msgContext.getSOAPConstants() == SOAPConstants.SOAP12_CONSTANTS) {
        // For now, if we're SOAP 1.2, fall through, since the range of
        // valid result codes is much greater
    } else if ((contentType != null) && !contentType.startsWith("text/html")
            && ((returnCode > 499) && (returnCode < 600))) {
        // SOAP Fault should be in here - so fall through
    } else if ((location != null) && ((returnCode == 302) || (returnCode == 307))) {
        // Temporary Redirect (HTTP: 302/307)
        // close old connection
        inp.close();
        socketHolder.getSocket().close();
        // remove former result and set new target url
        msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
        msgContext.setProperty(MessageContext.TRANS_URL, location);
        // next try
        invoke(msgContext);
        return inp;
    } else if (returnCode == 100) {
        msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
        msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
        readHeadersFromSocket(socketHolder, msgContext, inp, headers);
        return readFromSocket(socketHolder, msgContext, inp, headers);
    } else {
        // Unknown return code - so wrap up the content into a
        // SOAP Fault.
        ByteArrayOutputStream buf = new ByteArrayOutputStream(4097);

        while (-1 != (b = (byte) inp.read())) {
            buf.write(b);
        }
        String statusMessage = msgContext.getStrProp(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
        AxisFault fault = new AxisFault("HTTP", "(" + returnCode + ")" + statusMessage, null, null);

        fault.setFaultDetailString(Messages.getMessage("return01", String.valueOf(returnCode), buf.toString()));
        fault.addFaultDetail(Constants.QNAME_FAULTDETAIL_HTTPERRORCODE, Integer.toString(returnCode));
        throw fault;
    }

    String contentLocation = (String) headers.get(HEADER_CONTENT_LOCATION_LC);

    contentLocation = (null == contentLocation) ? null : contentLocation.trim();

    String contentLength = (String) headers.get(HEADER_CONTENT_LENGTH_LC);

    contentLength = (null == contentLength) ? null : contentLength.trim();

    String transferEncoding = (String) headers.get(HEADER_TRANSFER_ENCODING_LC);

    if (null != transferEncoding) {
        transferEncoding = transferEncoding.trim().toLowerCase();
        if (transferEncoding.equals(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
            inp = new ChunkedInputStream(inp);
        }
    }

    outMsg = new Message(new SocketInputStream(inp, socketHolder.getSocket()), false, contentType,
            contentLocation);
    // Transfer HTTP headers of HTTP message to MIME headers of SOAP message
    MimeHeaders mimeHeaders = outMsg.getMimeHeaders();
    for (Enumeration e = headers.keys(); e.hasMoreElements();) {
        String key = (String) e.nextElement();
        mimeHeaders.addHeader(key, ((String) headers.get(key)).trim());
    }
    outMsg.setMessageType(Message.RESPONSE);
    msgContext.setResponseMessage(outMsg);
    if (log.isDebugEnabled()) {
        if (null == contentLength) {
            log.debug(SystemUtils.LINE_SEPARATOR + Messages.getMessage("no00", "Content-Length"));
        }
        log.debug(SystemUtils.LINE_SEPARATOR + Messages.getMessage("xmlRecd00"));
        log.debug("-----------------------------------------------");
        log.debug(outMsg.getSOAPEnvelope().toString());
    }

    // if we are maintaining session state,
    // handle cookies (if any)
    if (msgContext.getMaintainSession()) {
        handleCookie(HTTPConstants.HEADER_COOKIE, HTTPConstants.HEADER_SET_COOKIE, headers, msgContext);
        handleCookie(HTTPConstants.HEADER_COOKIE2, HTTPConstants.HEADER_SET_COOKIE2, headers, msgContext);
    }
    return inp;
}

From source file:org.springframework.ws.soap.saaj.SaajSoapMessageFactory.java

private MimeHeaders parseMimeHeaders(InputStream inputStream) throws IOException {
    MimeHeaders mimeHeaders = new MimeHeaders();
    if (inputStream instanceof TransportInputStream) {
        TransportInputStream transportInputStream = (TransportInputStream) inputStream;
        for (Iterator<String> headerNames = transportInputStream.getHeaderNames(); headerNames.hasNext();) {
            String headerName = headerNames.next();
            for (Iterator<String> headerValues = transportInputStream.getHeaders(headerName); headerValues
                    .hasNext();) {/*from  ww w.ja  v  a2  s.c  om*/
                String headerValue = headerValues.next();
                StringTokenizer tokenizer = new StringTokenizer(headerValue, ",");
                while (tokenizer.hasMoreTokens()) {
                    mimeHeaders.addHeader(headerName, tokenizer.nextToken().trim());
                }
            }
        }
    }
    return mimeHeaders;
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

/**
 * Loads a SAAJ <code>SOAPMessage</code> from the given resource with a given message factory.
 *
 * @param resource       the resource to read from
 * @param messageFactory SAAJ message factory used to construct the message
 * @return the loaded SAAJ message/*w w  w. j  ava 2s  .  c o  m*/
 * @throws SOAPException if the message cannot be constructed
 * @throws IOException   if the input stream resource cannot be loaded
 */
public static SOAPMessage loadMessage(Resource resource, MessageFactory messageFactory)
        throws SOAPException, IOException {
    InputStream is = resource.getInputStream();
    try {
        MimeHeaders mimeHeaders = new MimeHeaders();
        mimeHeaders.addHeader(TransportConstants.HEADER_CONTENT_TYPE, "text/xml");
        mimeHeaders.addHeader(TransportConstants.HEADER_CONTENT_LENGTH,
                Long.toString(resource.getFile().length()));
        return messageFactory.createMessage(mimeHeaders, is);
    } finally {
        is.close();
    }
}

From source file:org.wso2.caching.receivers.CacheMessageReceiver.java

/**
 * This method will be called when the message is received to the MR
 * and this will serve the response from the cache
 *
 * @param messageCtx - MessageContext to be served
 * @throws AxisFault if there is any error in serving from the cache
 */// w  w  w . j  a v a  2s.  c  o  m
public void receive(MessageContext messageCtx) throws AxisFault {

    MessageContext outMsgContext = MessageContextBuilder.createOutMessageContext(messageCtx);

    if (outMsgContext != null) {
        OperationContext opCtx = outMsgContext.getOperationContext();

        if (opCtx != null) {
            opCtx.addMessageContext(outMsgContext);
            if (log.isDebugEnabled()) {
                log.debug("Serving from the cache...");
            }

            Object cachedObj = opCtx.getPropertyNonReplicable(CachingConstants.CACHED_OBJECT);
            if (cachedObj != null && cachedObj instanceof CachableResponse) {
                try {
                    MessageFactory mf = MessageFactory.newInstance();
                    SOAPMessage smsg;
                    if (messageCtx.isSOAP11()) {
                        smsg = mf.createMessage(new MimeHeaders(),
                                new ByteArrayInputStream(((CachableResponse) cachedObj).getResponseEnvelope()));
                        ((CachableResponse) cachedObj).setInUse(false);
                    } else {
                        MimeHeaders mimeHeaders = new MimeHeaders();
                        mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
                        mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
                        smsg = mf.createMessage(mimeHeaders,
                                new ByteArrayInputStream(((CachableResponse) cachedObj).getResponseEnvelope()));
                        ((CachableResponse) cachedObj).setInUse(false);
                    }

                    if (smsg != null) {
                        org.apache.axiom.soap.SOAPEnvelope omSOAPEnv = SAAJUtil
                                .toOMSOAPEnvelope(smsg.getSOAPPart().getDocumentElement());
                        if (omSOAPEnv.getHeader() == null) {
                            SOAPFactory fac = getSOAPFactory(messageCtx);
                            fac.createSOAPHeader(omSOAPEnv);
                        }
                        outMsgContext.setEnvelope(omSOAPEnv);
                    } else {
                        handleException("Unable to serve from the cache : "
                                + "Couldn't build the SOAP response from the cached byte stream");
                    }

                } catch (SOAPException e) {
                    handleException("Unable to serve from the cache : "
                            + "Unable to get build the response from the byte stream", e);
                } catch (IOException e) {
                    handleException("Unable to serve from the cache : "
                            + "I/O Error in building the response envelope from the byte stream");
                }

                AxisEngine.send(outMsgContext);

            } else {
                handleException("Unable to find the response in the cache");
            }
        } else {
            handleException("Unable to serve from " + "the cache : OperationContext not found for processing");
        }
    } else {
        handleException("Unable to serve from " + "the cache : Unable to get the out message context");
    }
}

From source file:org.wso2.carbon.caching.module.receivers.CacheMessageReceiver.java

/**
 * This method will be called when the message is received to the MR
 * and this will serve the response from the cache
 *
 * @param messageCtx - MessageContext to be served
 * @throws AxisFault if there is any error in serving from the cache
 *//*ww  w . j ava  2 s . c o  m*/
public void receive(MessageContext messageCtx) throws AxisFault {

    MessageContext outMsgContext = MessageContextBuilder.createOutMessageContext(messageCtx);

    if (outMsgContext != null) {
        OperationContext opCtx = outMsgContext.getOperationContext();

        if (opCtx != null) {
            opCtx.addMessageContext(outMsgContext);
            if (log.isDebugEnabled()) {
                log.debug("Serving from the cache...");
            }

            Object cachedObj = opCtx.getPropertyNonReplicable(CachingConstants.CACHED_OBJECT);
            /**
             * This was introduced to  avoid cache being expired before this below code executed.
             */
            byte[] bt = (byte[]) opCtx.getPropertyNonReplicable(CachingConstants.CACHEENVELOPE);

            if (bt != null) {
                try {
                    MessageFactory mf = MessageFactory.newInstance();
                    SOAPMessage smsg;
                    if (messageCtx.isSOAP11()) {
                        smsg = mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(bt));
                        ((CachableResponse) cachedObj).setInUse(false);
                    } else {
                        MimeHeaders mimeHeaders = new MimeHeaders();
                        mimeHeaders.addHeader("Content-ID", IDGenerator.generateID());
                        mimeHeaders.addHeader("content-type", HTTPConstants.MEDIA_TYPE_APPLICATION_SOAP_XML);
                        smsg = mf.createMessage(mimeHeaders, new ByteArrayInputStream(bt));
                        ((CachableResponse) cachedObj).setInUse(false);
                    }

                    if (smsg != null) {
                        org.apache.axiom.soap.SOAPEnvelope omSOAPEnv = SAAJUtil
                                .toOMSOAPEnvelope(smsg.getSOAPPart().getDocumentElement());
                        if (omSOAPEnv.getHeader() == null) {
                            SOAPFactory fac = getSOAPFactory(messageCtx);
                            fac.createSOAPHeader(omSOAPEnv);
                        }
                        outMsgContext.setEnvelope(omSOAPEnv);
                    } else {
                        handleException("Unable to serve from the cache : "
                                + "Couldn't build the SOAP response from the cached byte stream");
                    }

                } catch (SOAPException e) {
                    handleException("Unable to serve from the cache : "
                            + "Unable to get build the response from the byte stream", e);
                } catch (IOException e) {
                    handleException("Unable to serve from the cache : "
                            + "I/O Error in building the response envelope from the byte stream");
                }

                AxisEngine.send(outMsgContext);

            } else {
                handleException("Unable to find the response in the cache");
            }
        } else {
            handleException("Unable to serve from " + "the cache : OperationContext not found for processing");
        }
    } else {
        handleException("Unable to serve from " + "the cache : Unable to get the out message context");
    }
}

From source file:org.wso2.carbon.identity.provisioning.connector.InweboUserManager.java

private static SOAPMessage createUserSOAPMessage(Properties inweboProperties, InweboUser user)
        throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = inweboProperties.getProperty(InweboConnectorConstants.INWEBO_URI);
    SOAPEnvelope envelope = soapPart.getEnvelope();
    String namespacePrefix = InweboConnectorConstants.SOAPMessage.SOAP_NAMESPACE_PREFIX;
    envelope.addNamespaceDeclaration(namespacePrefix, serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACTION_LOGIN_CREATE, namespacePrefix);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_USER_ID,
            namespacePrefix);/*w  ww .j av  a 2s.c  o m*/
    soapBodyElem1.addTextNode(user.getUserId());
    SOAPElement soapBodyElem2 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_SERVICE_ID, namespacePrefix);
    soapBodyElem2.addTextNode(user.getServiceId());
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LOGIN,
            namespacePrefix);
    soapBodyElem3.addTextNode(user.getLogin());
    SOAPElement soapBodyElem4 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_FIRST_NAME, namespacePrefix);
    soapBodyElem4.addTextNode(user.getFirstName());
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_NAME,
            namespacePrefix);
    soapBodyElem5.addTextNode(user.getLastName());
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_MAIL,
            namespacePrefix);
    soapBodyElem6.addTextNode(user.getMail());
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_PHONE,
            namespacePrefix);
    soapBodyElem7.addTextNode(user.getPhone());
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_STATUS,
            namespacePrefix);
    soapBodyElem8.addTextNode(user.getStatus());
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ROLE,
            namespacePrefix);
    soapBodyElem9.addTextNode(user.getRole());
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_ACCESS,
            namespacePrefix);
    soapBodyElem10.addTextNode(user.getAccess());
    SOAPElement soapBodyElem11 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_CONTENT_TYPE, namespacePrefix);
    soapBodyElem11.addTextNode(user.getCodeType());
    SOAPElement soapBodyElem12 = soapBodyElem.addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_LANG,
            namespacePrefix);
    soapBodyElem12.addTextNode(user.getLanguage());
    SOAPElement soapBodyElem13 = soapBodyElem
            .addChildElement(InweboConnectorConstants.SOAPMessage.SOAP_EXTRA_FIELDS, namespacePrefix);
    soapBodyElem13.addTextNode(user.getExtraFields());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader(InweboConnectorConstants.SOAPMessage.SOAP_ACTION,
            serverURI + InweboConnectorConstants.SOAPMessage.SOAP_ACTION_HEADER);
    soapMessage.saveChanges();
    return soapMessage;
}