Search in sources :

Example 26 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.

the class ClientWorker method run.

public void run() {
    CustomLogSetter.getInstance().clearThreadLocalContent();
    TenantInfoInitiator tenantInfoInitiator = TenantInfoInitiatorProvider.getTenantInfoInitiator();
    if (tenantInfoInitiator != null) {
        tenantInfoInitiator.initTenantInfo();
    }
    if (responseMsgCtx == null) {
        cleanup();
        return;
    }
    if (responseMsgCtx.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION) != null) {
        ((NHttpServerConnection) responseMsgCtx.getProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION)).getContext().setAttribute(PassThroughConstants.CLIENT_WORKER_START_TIME, System.currentTimeMillis());
    }
    try {
        if (expectEntityBody) {
            String cType = response.getHeader(HTTP.CONTENT_TYPE);
            if (cType == null) {
                cType = response.getHeader(HTTP.CONTENT_TYPE.toLowerCase());
            }
            String contentType;
            if (cType != null) {
                // This is the most common case - Most of the time servers send the Content-Type
                contentType = cType;
            } else {
                // Server hasn't sent the header - Try to infer the content type
                contentType = inferContentType();
            }
            responseMsgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
            String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
            if (charSetEnc == null) {
                charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
            }
            if (contentType != null) {
                responseMsgCtx.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, contentType.indexOf("charset") > 0 ? charSetEnc : MessageContext.DEFAULT_CHAR_SET_ENCODING);
                responseMsgCtx.removeProperty(PassThroughConstants.NO_ENTITY_BODY);
            }
            responseMsgCtx.setServerSide(false);
            SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope envelope = fac.getDefaultEnvelope();
            try {
                responseMsgCtx.setEnvelope(envelope);
            } catch (AxisFault axisFault) {
                log.error("Error setting SOAP envelope", axisFault);
            }
            responseMsgCtx.setServerSide(true);
        } else {
            // there is no response entity-body
            responseMsgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, Boolean.TRUE);
            responseMsgCtx.setEnvelope(new SOAP11Factory().getDefaultEnvelope());
        }
        // copy the HTTP status code as a message context property with the key HTTP_SC to be
        // used at the sender to set the proper status code when passing the message
        int statusCode = this.response.getStatus();
        responseMsgCtx.setProperty(PassThroughConstants.HTTP_SC, statusCode);
        responseMsgCtx.setProperty(PassThroughConstants.HTTP_SC_DESC, response.getStatusLine());
        if (statusCode >= 400) {
            responseMsgCtx.setProperty(PassThroughConstants.FAULT_MESSAGE, PassThroughConstants.TRUE);
        }
        /*else if (statusCode == 202 && responseMsgCtx.getOperationContext().isComplete()) {
                // Handle out-only invocation scenario
                responseMsgCtx.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
            }*/
        responseMsgCtx.setProperty(PassThroughConstants.NON_BLOCKING_TRANSPORT, true);
        // process response received
        try {
            AxisEngine.receive(responseMsgCtx);
        } catch (AxisFault af) {
            log.error("Fault processing response message through Axis2", af);
        }
    } catch (AxisFault af) {
        log.error("Fault creating response SOAP envelope", af);
    } finally {
        cleanup();
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) TenantInfoInitiator(org.apache.synapse.commons.util.ext.TenantInfoInitiator) SOAP11Factory(org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 27 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project wso2-synapse by wso2.

the class Axis2Sender method sendBack.

/**
 * Send a response back to a client of Synapse
 *
 * @param smc the Synapse message context sent as the response
 */
public static void sendBack(org.apache.synapse.MessageContext smc) {
    if (preventMultipleResponses(smc)) {
        return;
    }
    MessageContext messageContext = ((Axis2MessageContext) smc).getAxis2MessageContext();
    // prevent it from going into any other transport sender
    if (messageContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED) && messageContext.getTransportOut() != null && !messageContext.getTransportOut().getName().startsWith(Constants.TRANSPORT_HTTP)) {
        return;
    }
    // fault processing code
    if (messageContext.isDoingREST() && messageContext.isFault() && isMessagePayloadHasASOAPFault(messageContext)) {
        POXUtils.convertSOAPFaultToPOX(messageContext);
    }
    try {
        messageContext.setProperty(SynapseConstants.ISRESPONSE_PROPERTY, Boolean.TRUE);
        if (AddressingHelper.isReplyRedirected(messageContext) && !messageContext.getReplyTo().hasNoneAddress()) {
            messageContext.setTo(messageContext.getReplyTo());
            messageContext.setReplyTo(null);
            messageContext.setWSAAction("");
            messageContext.setSoapAction("");
            messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
            messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
        }
        if (messageContext.getEnvelope().hasFault() && AddressingHelper.isFaultRedirected(messageContext) && (messageContext.getFaultTo() == null || !messageContext.getFaultTo().hasNoneAddress())) {
            messageContext.setTo(messageContext.getFaultTo());
            messageContext.setFaultTo(null);
            messageContext.setWSAAction("");
            messageContext.setSoapAction("");
            messageContext.setProperty(NhttpConstants.IGNORE_SC_ACCEPTED, Constants.VALUE_TRUE);
            messageContext.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES, Boolean.FALSE);
        }
        String preserveAddressingProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_WS_ADDRESSING);
        if (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)) {
            /*Avoiding duplicate addressing headers*/
            messageContext.setProperty(AddressingConstants.REPLACE_ADDRESSING_HEADERS, "true");
            messageContext.setMessageID(smc.getMessageID());
        } else {
            MessageHelper.removeAddressingHeaders(messageContext);
            messageContext.setMessageID(UIDGenerator.generateURNString());
        }
        // determine weather we need to preserve the processed headers
        String preserveHeaderProperty = (String) smc.getProperty(SynapseConstants.PRESERVE_PROCESSED_HEADERS);
        if (preserveHeaderProperty == null || !Boolean.parseBoolean(preserveHeaderProperty)) {
            // remove the processed headers
            MessageHelper.removeProcessedHeaders(messageContext, (preserveAddressingProperty != null && Boolean.parseBoolean(preserveAddressingProperty)));
        }
        // temporary workaround for https://issues.apache.org/jira/browse/WSCOMMONS-197
        if (messageContext.isEngaged(SynapseConstants.SECURITY_MODULE_NAME) && messageContext.getEnvelope().getHeader() == null) {
            SOAPFactory fac = messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
            fac.createSOAPHeader(messageContext.getEnvelope());
        }
        Axis2FlexibleMEPClient.clearSecurtityProperties(messageContext.getOptions());
        // Invoke Synapse Handlers
        Iterator<SynapseHandler> iterator = smc.getEnvironment().getSynapseHandlers().iterator();
        while (iterator.hasNext()) {
            SynapseHandler handler = iterator.next();
            if (!handler.handleResponseOutFlow(smc)) {
                return;
            }
        }
        doSOAPFormatConversion(smc);
        // handles concurrent throttling based on the messagecontext.
        handleConcurrentThrottleCount(smc);
        // If the request arrives through an inbound endpoint
        if (smc.getProperty(SynapseConstants.IS_INBOUND) != null && (Boolean) smc.getProperty(SynapseConstants.IS_INBOUND)) {
            if (smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER) != null) {
                InboundResponseSender inboundResponseSender = (InboundResponseSender) smc.getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER);
                inboundResponseSender.sendBack(smc);
            } else {
                String msg = "Inbound Response Sender not found -" + " Inbound Endpoint may not support sending a response back";
                log.error(msg);
                throw new SynapseException(msg);
            }
        } else {
            // If the request arrives through a conventional transport listener
            AxisEngine.send(messageContext);
        }
    } catch (AxisFault e) {
        handleException(getResponseMessage(messageContext), e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) SynapseException(org.apache.synapse.SynapseException) MessageContext(org.apache.axis2.context.MessageContext) SynapseHandler(org.apache.synapse.SynapseHandler) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InboundResponseSender(org.apache.synapse.inbound.InboundResponseSender)

Example 28 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project carbon-business-process by wso2.

the class SOAPUtils method buildSoapDetail.

private static OMElement buildSoapDetail(final BPELMessageContext bpelMessageContext, final MessageExchange odeMessageContext) throws AxisFault {
    Element message = odeMessageContext.getResponse().getMessage();
    QName faultName = odeMessageContext.getFault();
    Operation operation = odeMessageContext.getOperation();
    SOAPFactory soapFactory = bpelMessageContext.getSoapFactoryForCurrentMessageFlow();
    if (faultName.getNamespaceURI() == null) {
        return toFaultDetail(message, soapFactory);
    }
    Fault f = operation.getFault(faultName.getLocalPart());
    if (f == null) {
        return toFaultDetail(message, soapFactory);
    }
    // For faults, there will be exactly one part.
    Part p = (Part) f.getMessage().getParts().values().iterator().next();
    if (p == null) {
        return toFaultDetail(message, soapFactory);
    }
    Element partEl = DOMUtils.findChildByName(message, new QName(null, p.getName()));
    if (partEl == null) {
        return toFaultDetail(message, soapFactory);
    }
    Element detail = DOMUtils.findChildByName(partEl, p.getElementName());
    if (detail == null) {
        return toFaultDetail(message, soapFactory);
    }
    return OMUtils.toOM(detail, soapFactory);
}
Also used : QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) SOAPFault(org.apache.axiom.soap.SOAPFault) Fault(javax.wsdl.Fault) AxisFault(org.apache.axis2.AxisFault) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 29 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project carbon-business-process by wso2.

the class BPELMessageReceiver method invokeBusinessLogic.

protected final void invokeBusinessLogic(final MessageContext inMessageContext) throws AxisFault {
    if (messageTraceLog.isDebugEnabled()) {
        messageTraceLog.debug("Message received: " + inMessageContext.getAxisService().getName() + "." + inMessageContext.getAxisOperation().getName());
        if (messageTraceLog.isTraceEnabled()) {
            messageTraceLog.trace("Request message: " + inMessageContext.getEnvelope());
        }
    }
    SOAPFactory soapFactory = getSOAPFactory(inMessageContext);
    final BPELMessageContext bpelMessageContext = BPELMessageContextFactory.createBPELMessageContext(inMessageContext, processProxy, soapFactory);
    // Initializing the attachments in the BPEL Message Context
    List<String> attachmentIDs = persistAttachments(inMessageContext.getAttachmentMap());
    if (attachmentIDs != null && !attachmentIDs.isEmpty()) {
        bpelMessageContext.setAttachmentIDList(attachmentIDs);
    }
    if (hasResponse(inMessageContext.getAxisOperation())) {
        handleInOutOperation(bpelMessageContext);
        if (messageTraceLog.isDebugEnabled()) {
            messageTraceLog.debug("Reply Sent: " + inMessageContext.getAxisService().getName() + "." + inMessageContext.getAxisOperation().getName());
            if (messageTraceLog.isTraceEnabled()) {
                messageTraceLog.trace("Response message: " + bpelMessageContext.getOutMessageContext().getEnvelope());
            }
        }
    } else {
        handleInOnlyOperation(bpelMessageContext);
    }
}
Also used : BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 30 with SOAPFactory

use of org.apache.axiom.soap.SOAPFactory in project ofbiz-framework by apache.

the class SOAPEventHandler method createAndSendSOAPResponse.

private void createAndSendSOAPResponse(Map<String, Object> serviceResults, String serviceName, HttpServletResponse response) throws EventHandlerException {
    try {
        // setup the response
        if (Debug.verboseOn())
            Debug.logVerbose("[EventHandler] : Setting up response message", module);
        String xmlResults = SoapSerializer.serialize(serviceResults);
        // Debug.logInfo("xmlResults ==================" + xmlResults, module);
        XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
        StAXOMBuilder resultsBuilder = (StAXOMBuilder) OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader);
        OMElement resultSer = resultsBuilder.getDocumentElement();
        // create the response soap
        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope resEnv = factory.createSOAPEnvelope();
        SOAPBody resBody = factory.createSOAPBody();
        OMElement resService = factory.createOMElement(new QName(serviceName + "Response"));
        resService.addChild(resultSer.getFirstElement());
        resBody.addChild(resService);
        resEnv.addChild(resBody);
        // The declareDefaultNamespace method doesn't work see (https://issues.apache.org/jira/browse/AXIS2-3156)
        // so the following doesn't work:
        // resService.declareDefaultNamespace(ModelService.TNS);
        // instead, create the xmlns attribute directly:
        OMAttribute defaultNS = factory.createOMAttribute("xmlns", null, ModelService.TNS);
        resService.addAttribute(defaultNS);
        // log the response message
        if (Debug.verboseOn()) {
            try {
                Debug.logInfo("Response Message:\n" + resEnv + "\n", module);
            } catch (Throwable t) {
            }
        }
        resEnv.serialize(response.getOutputStream());
        response.getOutputStream().flush();
    } catch (Exception e) {
        Debug.logError(e, module);
        throw new EventHandlerException(e.getMessage(), e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) SOAPBody(org.apache.axiom.soap.SOAPBody) StringReader(java.io.StringReader) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

SOAPFactory (org.apache.axiom.soap.SOAPFactory)69 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)49 OMElement (org.apache.axiom.om.OMElement)38 QName (javax.xml.namespace.QName)16 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)14 SOAPBody (org.apache.axiom.soap.SOAPBody)12 MessageContext (org.apache.axis2.context.MessageContext)11 DataHandler (javax.activation.DataHandler)10 AxisFault (org.apache.axis2.AxisFault)10 OMNamespace (org.apache.axiom.om.OMNamespace)9 SOAPHeader (org.apache.axiom.soap.SOAPHeader)9 SynapseException (org.apache.synapse.SynapseException)8 Iterator (java.util.Iterator)7 OMNode (org.apache.axiom.om.OMNode)7 SOAPFault (org.apache.axiom.soap.SOAPFault)7 EndpointReference (org.apache.axis2.addressing.EndpointReference)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 OMAttribute (org.apache.axiom.om.OMAttribute)4