Search in sources :

Example 76 with Header

use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.

the class SOAPUtils method handleSoapHeaderPartDef.

private static void handleSoapHeaderPartDef(org.apache.ode.bpel.iapi.Message odeMessage, Definition wsdl, SOAPHeader header, javax.wsdl.extensions.soap.SOAPHeader headerdef, Message msgType) throws BPELFault {
    // Is this header part of the "payload" messsage?
    boolean payloadMessageHeader = headerdef.getMessage() == null || headerdef.getMessage().equals(msgType.getQName());
    boolean requiredHeader = payloadMessageHeader || (headerdef.getRequired() != null && headerdef.getRequired());
    if (requiredHeader && header == null) {
        throw new BPELFault("SOAP Header missing required element.");
    }
    if (header == null) {
        return;
    }
    Message hdrMsg = wsdl.getMessage(headerdef.getMessage());
    if (hdrMsg == null) {
        return;
    }
    Part p = hdrMsg.getPart(headerdef.getPart());
    if (p == null || p.getElementName() == null) {
        return;
    }
    OMElement headerEl = header.getFirstChildWithName(p.getElementName());
    if (requiredHeader && headerEl == null) {
        throw new BPELFault("SOAP Header missing required element: " + p.getElementName());
    }
    if (headerEl == null) {
        return;
    }
    odeMessage.setHeaderPart(p.getName(), OMUtils.toDOM(headerEl));
}
Also used : BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) Message(javax.wsdl.Message) Part(javax.wsdl.Part) OMElement(org.apache.axiom.om.OMElement)

Example 77 with Header

use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.

the class SOAPUtils method handleSOAPHeaderElementsInBindingOperation.

@SuppressWarnings("unchecked")
private static void handleSOAPHeaderElementsInBindingOperation(SOAPEnvelope soapEnvelope, SOAPFactory soapFactory, org.apache.ode.bpel.iapi.Message messageFromOde, Operation wsdlOperation, final javax.wsdl.extensions.soap.SOAPHeader soapHeaderElementDefinition) throws BPELFault {
    Map<String, Node> headerParts = messageFromOde.getHeaderParts();
    Message responseMessageDefinition = wsdlOperation.getOutput() != null ? wsdlOperation.getOutput().getMessage() : null;
    // If there isn't a message attribute in header element definition or if the
    // message attribute value is equal to the response message QName, then this
    // header element is part of the actual payload.
    // Refer SOAP Binding specification at http://www.w3.org/TR/wsdl#_soap-b.
    final boolean isHeaderElementAPartOfPayload = soapHeaderElementDefinition.getMessage() == null || ((wsdlOperation.getStyle() != OperationType.ONE_WAY) && soapHeaderElementDefinition.getMessage().equals(responseMessageDefinition.getQName()));
    if (soapHeaderElementDefinition.getPart() == null) {
        // Part information not found. Ignoring this header definition.
        return;
    }
    if (isHeaderElementAPartOfPayload && (responseMessageDefinition != null && responseMessageDefinition.getPart(soapHeaderElementDefinition.getPart()) == null)) {
        // we should throw a exception.
        throw new BPELFault("SOAP Header Element Definition refer unknown part.");
    }
    Element partElement = null;
    if (headerParts.size() > 0 && isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) headerParts.get(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("SOAP Header must be a DOM Element.", e);
        }
    }
    // message payload. This is because, some headers will provided by SOAP engine.
    if (partElement == null && isHeaderElementAPartOfPayload) {
        if (messageFromOde.getPart(soapHeaderElementDefinition.getPart()) != null) {
            partElement = messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } else {
            throw new BPELFault("Missing Required part in response message.");
        }
    }
    // and can be found and extracted from the odeMessage object
    if (partElement == null && messageFromOde.getParts().size() > 0 && !isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("Soap header must be an element" + messageFromOde.getPart(soapHeaderElementDefinition.getPart()));
        }
    }
    // just ignore this case.
    if (partElement == null) {
        return;
    }
    org.apache.axiom.soap.SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (soapHeader == null) {
        soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    }
    OMElement omPart = OMUtils.toOM(partElement, soapFactory);
    for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
        soapHeader.addChild(i.next());
    }
}
Also used : Message(javax.wsdl.Message) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader) OMNode(org.apache.axiom.om.OMNode)

Example 78 with Header

use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.

the class CallBackServiceImpl method sendProtocolMessage.

private void sendProtocolMessage(long taskID, String headerValue, String value) throws AxisFault {
    final MessageContext mctx = new MessageContext();
    ServiceInvocationContext invocationContext = new ServiceInvocationContext();
    invocationContext.setInMessageContext(mctx);
    invocationContext.setUep(uep);
    invocationContext.setService(serviceName);
    invocationContext.setPort(portName);
    invocationContext.setCaller(taskName.getLocalPart());
    invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
    invocationContext.setOperationName(operation);
    if (mctx.getEnvelope() == null) {
        mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
    }
    if (mctx.getEnvelope().getBody() == null) {
        getSoapFactory().createSOAPBody(mctx.getEnvelope());
    }
    if (mctx.getEnvelope().getHeader() == null) {
        getSoapFactory().createSOAPHeader(mctx.getEnvelope());
    }
    // Creating Dummy Element
    // Extracting MessageName
    List bindingOperations = binding.getBindingOperations();
    String messageName = "";
    OMNamespace serviceNS = null;
    BindingOperation oper;
    for (int i = 0; i < bindingOperations.size(); i++) {
        oper = (BindingOperation) bindingOperations.get(i);
        if (operation.equals(oper.getName())) {
            Message message = oper.getOperation().getInput().getMessage();
            messageName = message.getQName().getLocalPart();
            for (Object ob : message.getParts().keySet()) {
                // Here we don't support RPC messages.
                Part part = (Part) message.getParts().get(ob);
                serviceNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(part.getElementName().getNamespaceURI(), part.getElementName().getPrefix());
                break;
            }
            break;
        }
    }
    OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(messageName, serviceNS);
    mctx.getEnvelope().getBody().addChild(payload);
    OMNamespace htpNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.HT_PROTOCOL_NAMESPACE, HumanTaskConstants.HT_PROTOCOL_DEFAULT_PREFIX);
    SOAPHeaderBlock protocolHeader = mctx.getEnvelope().getHeader().addHeaderBlock(headerValue, htpNS);
    protocolHeader.setText(value);
    protocolHeader.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), htpNS);
    OMNamespace b4pNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
    SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, b4pNS);
    header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), b4pNS);
    AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)

Example 79 with Header

use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.

the class CallBackServiceImpl method invoke.

@Override
public void invoke(OMElement payload, long taskId) throws AxisFault {
    final MessageContext mctx = new MessageContext();
    ServiceInvocationContext invocationContext = new ServiceInvocationContext();
    invocationContext.setInMessageContext(mctx);
    invocationContext.setUep(uep);
    invocationContext.setService(serviceName);
    invocationContext.setPort(portName);
    invocationContext.setCaller(taskName.getLocalPart());
    invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
    invocationContext.setOperationName(operation);
    if (mctx.getEnvelope() == null) {
        mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
    }
    if (mctx.getEnvelope().getBody() == null) {
        getSoapFactory().createSOAPBody(mctx.getEnvelope());
    }
    if (mctx.getEnvelope().getHeader() == null) {
        getSoapFactory().createSOAPHeader(mctx.getEnvelope());
    }
    mctx.getEnvelope().getBody().addChild(payload);
    OMNamespace ns = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
    SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, ns);
    header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskId), ns);
    AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext)

Example 80 with Header

use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.

the class SOAPHelper method addCoordinationContext.

/**
 * Adding ws-Coordination context to soap request.
 *
 * @param msgCtx              MessageContext
 * @param messageID           UUID as a WS-Coordination identifier
 * @param registrationService URL of the ws-coordination registration service.
 */
public void addCoordinationContext(MessageContext msgCtx, String messageID, String registrationService) {
    SOAPHeader header = msgCtx.getEnvelope().getHeader();
    EndpointReference epr = new EndpointReference();
    epr.setAddress(registrationService);
    CoordinationContext context = new HumanTaskCoordinationContextImpl(messageID, epr);
    header.addChild(context.toOM());
}
Also used : HumanTaskCoordinationContextImpl(org.wso2.carbon.bpel.b4p.coordination.context.impl.HumanTaskCoordinationContextImpl) SOAPHeader(org.apache.axiom.soap.SOAPHeader) EndpointReference(org.apache.axis2.addressing.EndpointReference) CoordinationContext(org.wso2.carbon.bpel.b4p.coordination.context.CoordinationContext)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)103 HashMap (java.util.HashMap)95 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)95 Test (org.testng.annotations.Test)36 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)35 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)33 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)30 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)28 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)24 ArrayList (java.util.ArrayList)23 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)19 CharonException (org.wso2.charon3.core.exceptions.CharonException)19 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)19 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)18 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)18 Header (org.wso2.carbon.messaging.Header)17 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)16 IOException (java.io.IOException)15 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)15 Map (java.util.Map)14