org.apache.axiom.soap.SOAPEnvelope Java Examples

The following examples show how to use org.apache.axiom.soap.SOAPEnvelope. 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: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #2
Source File: JMSTestsUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Create a empty message context.
 *
 * @return A context with empty message
 * @throws AxisFault on an error creating a context
 */
public static org.apache.synapse.MessageContext createMessageContext() throws AxisFault {

    Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
    org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
    axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));

    ServiceContext svcCtx = new ServiceContext();
    OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
    axis2MC.setServiceContext(svcCtx);
    axis2MC.setOperationContext(opCtx);
    org.apache.synapse.MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(),
                                                                   synapseEnvironment);
    mc.setMessageID(UIDGenerator.generateURNString());
    SOAPEnvelope env = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
    OMNamespace namespace = OMAbstractFactory.getSOAP11Factory()
            .createOMNamespace("http://ws.apache.org/commons/ns/payload", "text");
    env.declareNamespace(namespace);
    mc.setEnvelope(env);
    SOAPBody body = OMAbstractFactory.getSOAP11Factory().createSOAPBody();
    OMElement element = OMAbstractFactory.getSOAP11Factory().createOMElement("TestElement", namespace);
    element.setText("This is a test!!");
    body.addChild(element);
    mc.getEnvelope().addChild(body);
    return mc;
}
 
Example #3
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static SOAPEnvelope createErrorEnvelope(MessageContext synCtx, String rawMsg, String erroMsg,
                                                InboundProcessorParams params) {
    SOAPEnvelope envelope = fac.getDefaultEnvelope();
    OMElement messageEl;
    boolean rawMessage = false;
    if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE) != null && params
            .getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equals("true")) {
        rawMessage = true;
    }

    if (rawMessage) {
        messageEl = generateHL7RawMessaegElement(rawMsg);
        envelope.getBody().addChild(messageEl);
    }

    return envelope;

}
 
Example #4
Source File: WSXACMLMessageReceiver.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope createDefaultSOAPEnvelope(MessageContext inMsgCtx) {

        String soapNamespace = inMsgCtx.getEnvelope().getNamespace()
                .getNamespaceURI();
        SOAPFactory soapFactory = null;
        if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP11Factory();
        } else if (soapNamespace
                .equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP12Factory();
        } else {
            log.error("Unknown SOAP Envelope");
        }
        if (soapFactory != null) {
            return soapFactory.getDefaultEnvelope();
        }

        return null;
    }
 
Example #5
Source File: InboundHttpServerWorker.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void doPreInjectTasks(MessageContext axis2MsgContext, Axis2MessageContext synCtx, String method) {

        if (!isRESTRequest(axis2MsgContext, method)) {
            if (request.isEntityEnclosing()) {
                processEntityEnclosingRequest(axis2MsgContext, false);
            } else {
                processNonEntityEnclosingRESTHandler(null, axis2MsgContext, false);
            }
        } else {
            AxisOperation axisOperation = synCtx.getAxis2MessageContext().getAxisOperation();
            synCtx.getAxis2MessageContext().setAxisOperation(null);
            String contentTypeHeader = request.getHeaders().get(HTTP.CONTENT_TYPE);
            SOAPEnvelope soapEnvelope = handleRESTUrlPost(contentTypeHeader);
            processNonEntityEnclosingRESTHandler(soapEnvelope, axis2MsgContext, false);
            synCtx.getAxis2MessageContext().setAxisOperation(axisOperation);

        }
    }
 
Example #6
Source File: AppendixV.java    From openxds with Apache License 2.0 6 votes vote down vote up
protected void checkSOAP12() throws XdsWSException {
	
	if (MessageContext.getCurrentMessageContext().isSOAP11()) {
		throwFault("SOAP 1.1 not supported");
	}
	SOAPEnvelope env = MessageContext.getCurrentMessageContext().getEnvelope();
	if (env == null)
		throwFault("No SOAP envelope found");
	SOAPHeader hdr = env.getHeader();
	if (hdr == null)
		throwFault("No SOAP header found");
	if ( !hdr.getChildrenWithName(new QName("http://www.w3.org/2005/08/addressing","Action")).hasNext()) {
		throwFault("WS-Action required in header");
	}

}
 
Example #7
Source File: RegularExpressionProtectorTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This is the test case to validate the request body against sql injection attack.
 */
@Test
public void testSqlInjectionInBody() throws AxisFault {
    log.info(" Running the test case to validate the request body from sql injection attacks.");
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    env.getBody().addChild(fac.createOMElement("test", "Drop database", "testBody"));
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_BODY)).thenReturn
            (String.valueOf(enabledStatus));
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_HEADERS)).thenReturn
            (String.valueOf("false"));
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_PATHPARAM)).thenReturn
            (String.valueOf("false"));
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgContext);
    Mockito.doReturn(env).when(axis2MsgContext).getEnvelope();
    regularExpressionProtector = new RegularExpressionProtector();
    regularExpressionProtector.mediate(messageContext);
}
 
Example #8
Source File: RegularExpressionProtectorTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This is the test case to check the return value of the isContentAware method.
 */
@Test
public void testIsContentAware() {
    log.info("Running the test case to check the return status of the isContentAware method.");
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    env.getBody().addChild(fac.createOMElement("test", "Content aware", "MessageBody"));
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgContext);
    Mockito.doReturn(env).when(axis2MsgContext).getEnvelope();
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_BODY)).thenReturn
            (String.valueOf(enabledStatus));
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_HEADERS)).thenReturn
            (String.valueOf("false"));
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.ENABLED_CHECK_PATHPARAM)).thenReturn
            (String.valueOf("false"));
    regularExpressionProtector = new RegularExpressionProtector();
    regularExpressionProtector.mediate(messageContext);
    String enabledBuild = String.valueOf(regularExpressionProtector.isContentAware());
    Assert.assertEquals(enabledStatus, enabledBuild);
    log.info("Successfully completed testIsContentAware test case.");
}
 
Example #9
Source File: UtilsTestCase.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetFaultPayload() {
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS))
            .thenReturn(headers);
    Mockito.when(messageContext.getProperty("error_message_type"))
            .thenReturn("error_message_type");
    OMElement omElement = Mockito.mock(OMElement.class);
    SOAPEnvelope soapEnvelope = Mockito.mock(SOAPEnvelope.class);
    SOAPBody soapBody = Mockito.mock(SOAPBody.class);
    Mockito.when(messageContext.getEnvelope()).thenReturn(soapEnvelope);
    Mockito.when(soapEnvelope.getBody()).thenReturn(soapBody);
    Utils.setFaultPayload(messageContext, omElement);
    Assert.assertTrue(true);  // No error has occurred. hence test passes.

    //when acceptType != null
    Mockito.when(headers.get(HttpHeaders.ACCEPT)).thenReturn("text/html");
    Utils.setFaultPayload(messageContext, omElement);
    Assert.assertTrue(true);  // No error has occurred. hence test passes.

}
 
Example #10
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #11
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #12
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #13
Source File: CarbonEventingMessageReceiver.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public final void invokeBusinessLogic(MessageContext mc) throws AxisFault {
    try {
        processMessage(mc);
    } catch (WSEventException e) {
        log.error("An exception occured. Unable to Process Request", e);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        String details = sw.toString();
        pw.close();
        SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                EventingConstants.WSE_FAULT_CODE_RECEIVER, "EventSourceUnableToProcess",
                e.getMessage(), details, mc.isSOAP11());
        dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
    }
}
 
Example #14
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #15
Source File: LoadBalanceSessionFullClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #16
Source File: LoadBalanceSessionFullClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.createOMNamespace(
        "http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #17
Source File: WSXACMLMessageReceiver.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope createDefaultSOAPEnvelope(MessageContext inMsgCtx) {

        String soapNamespace = inMsgCtx.getEnvelope().getNamespace()
                .getNamespaceURI();
        SOAPFactory soapFactory = null;
        if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP11Factory();
        } else if (soapNamespace
                .equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP12Factory();
        } else {
            log.error("Unknown SOAP Envelope");
        }
        if (soapFactory != null) {
            return soapFactory.getDefaultEnvelope();
        }

        return null;
    }
 
Example #18
Source File: EventBrokerUtils.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static MessageContext createMessageContext(OMElement payload,
                                                  OMElement topic,
                                                  int tenantId) throws EventBrokerException {
    MessageContext mc = new MessageContext();
    mc.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
    SOAPFactory soapFactory = new SOAP12Factory();
    SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
    envelope.getBody().addChild(payload);
    if (topic != null) {
        envelope.getHeader().addChild(topic);
    }
    try {
        mc.setEnvelope(envelope);
    } catch (Exception e) {

        throw new EventBrokerException("Unable to generate event.", e);
    }
    return mc;
}
 
Example #19
Source File: PublishOnlyMessageReceiver.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch the message to the target endpoint
 *
 * @param soapEnvelope   Soap Enevlop with message
 * @param responseAction WSE action for the response
 * @param mc             Message Context
 * @param isFault        Whether a Fault message must be sent
 * @throws AxisFault Thrown by the axis2 engine.
 */
private void dispatchResponse(SOAPEnvelope soapEnvelope, String responseAction,
                              MessageContext mc, boolean isFault) throws AxisFault {
    MessageContext rmc = MessageContextBuilder.createOutMessageContext(mc);
    rmc.getOperationContext().addMessageContext(rmc);
    replicateState(mc);
    rmc.setEnvelope(soapEnvelope);
    rmc.setWSAAction(responseAction);
    rmc.setSoapAction(responseAction);
    if (isFault) {
        AxisEngine.sendFault(rmc);
    } else {
        AxisEngine.send(rmc);
    }
}
 
Example #20
Source File: CarbonEventingMessageReceiver.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch the message to the target endpoint
 *
 * @param soapEnvelope   Soap Enevlop with message
 * @param responseAction WSE action for the response
 * @param mc             Message Context
 * @param isFault        Whether a Fault message must be sent
 * @throws AxisFault Thrown by the axis2 engine.
 */
private void dispatchResponse(SOAPEnvelope soapEnvelope, String responseAction,
                              MessageContext mc, boolean isFault) throws AxisFault {
    MessageContext rmc = MessageContextBuilder.createOutMessageContext(mc);
    rmc.getOperationContext().addMessageContext(rmc);
    replicateState(mc);
    rmc.setEnvelope(soapEnvelope);
    rmc.setWSAAction(responseAction);
    rmc.setSoapAction(responseAction);
    if (isFault) {
        AxisEngine.sendFault(rmc);
    } else {
        AxisEngine.send(rmc);
    }
}
 
Example #21
Source File: ProxyMessageReceiver.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private SOAPEnvelope getResponseEnvelope(ServiceClient client) throws AxisFault {
    OperationContext operationContext = client.getLastOperationContext();
    MessageContext messageContext =
            operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    if (messageContext != null) {
        return messageContext.getEnvelope();
    }
    return null;
}
 
Example #22
Source File: PublishOnlyMessageReceiver.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public final void invokeBusinessLogic(MessageContext mc) throws AxisFault {
    try {
        handleEvent(mc);
    } catch (WSEventException e) {
        log.error("An exception occured. Unable to Process Request", e);
        SOAPEnvelope soapEnvelope = BuilderUtils.genFaultResponse(
                EventingConstants.WSE_FAULT_CODE_RECEIVER, "EventSourceUnableToProcess",
                "An exception occured. Unable to Process Request ", "", mc.isSOAP11());
        dispatchResponse(soapEnvelope, EventingConstants.WSA_FAULT, mc, true);
    }
}
 
Example #23
Source File: DataProcessAndPublishingAgentTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void testContentAwareTierPresentAndContentLengthNotPresent() throws Exception {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    throttleProperties.setEnabled(true);
    DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper
            (throttleProperties);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setIsContentAware(true);
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    env.getBody().addChild(fac.createOMElement("test", "http://t", "t"));
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext
            .class);
    Mockito.when(messageContext.getEnvelope()).thenReturn(env);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API)).thenReturn("admin--PizzaShackAPI");
    TreeMap headers = new TreeMap();
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS))
            .thenReturn(headers);
    VerbInfoDTO verbInfoDTO = new VerbInfoDTO();
    verbInfoDTO.setContentAware(false);
    ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>();
    list.add(verbInfoDTO);
    Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list);
    dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier,
            apiLevelThrottleKey, null, subscriptionLevelThrottleKey, subscriptionLevelTier,
            resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant,
            apiTenant, appId, messageContext, authenticationContext);
    dataProcessAndPublishingAgent.run();
}
 
Example #24
Source File: Utils.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public static void setSOAPFault(MessageContext messageContext, String code, 
                                String reason, String detail) {
    SOAPFactory factory = (messageContext.isSOAP11() ?
            OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory());

    OMDocument soapFaultDocument = factory.createOMDocument();
    SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
    soapFaultDocument.addChild(faultEnvelope);

    SOAPFault fault = faultEnvelope.getBody().getFault();
    if (fault == null) {
        fault = factory.createSOAPFault();
    }

    SOAPFaultCode faultCode = factory.createSOAPFaultCode();
    if (messageContext.isSOAP11()) {
        faultCode.setText(new QName(fault.getNamespace().getNamespaceURI(), code));
    } else {
        SOAPFaultValue value = factory.createSOAPFaultValue(faultCode);
        value.setText(new QName(fault.getNamespace().getNamespaceURI(), code));            
    }
    fault.setCode(faultCode);

    SOAPFaultReason faultReason = factory.createSOAPFaultReason();
    if (messageContext.isSOAP11()) {
        faultReason.setText(reason);
    } else {
        SOAPFaultText text = factory.createSOAPFaultText();
        text.setText(reason);
        text.setLang("en");
        faultReason.addSOAPText(text);            
    }
    fault.setReason(faultReason);

    SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
    soapFaultDetail.setText(detail);
    fault.setDetail(soapFaultDetail);
    
    // set the all headers of original SOAP Envelope to the Fault Envelope
    if (messageContext.getEnvelope() != null) {
        SOAPHeader soapHeader = messageContext.getEnvelope().getHeader();
        if (soapHeader != null) {
            for (Iterator iterator = soapHeader.examineAllHeaderBlocks(); iterator.hasNext();) {
                Object o = iterator.next();
                if (o instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock header = (SOAPHeaderBlock) o;
                    faultEnvelope.getHeader().addChild(header);
                } else if (o instanceof OMElement) {
                    faultEnvelope.getHeader().addChild((OMElement) o);
                }
            }
        }
    }

    try {
        messageContext.setEnvelope(faultEnvelope);
    } catch (AxisFault af) {
        log.error("Error while setting SOAP fault as payload", af);
        return;
    }

    if (messageContext.getFaultTo() != null) {
        messageContext.setTo(messageContext.getFaultTo());
    } else if (messageContext.getReplyTo() != null) {
        messageContext.setTo(messageContext.getReplyTo());
    } else {
        messageContext.setTo(null);
    }

    // set original messageID as relatesTo
    if (messageContext.getMessageID() != null) {
        RelatesTo relatesTo = new RelatesTo(messageContext.getMessageID());
        messageContext.setRelatesTo(new RelatesTo[] { relatesTo });
    }
}
 
Example #25
Source File: RegularExpressionProtector.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method returns true if the request payload size exceeds the system property
 * 'payloadSizeLimitForRegexThreatProtector' value (in KB) defined. If this system property is not defined, this
 * check won't be done.
 *
 * @param messageContext contains the message properties of the relevant API request which was
 *                       enabled the regexValidator message mediation in flow.
 * @return true if the payload size has exceeded the defined value in system property
 */
private boolean isPayloadSizeExceeded(MessageContext messageContext) {
    // payloadSizeLimit is in KB
    Integer payloadSizeLimit = Integer.getInteger(APIMgtGatewayConstants.PAYLOAD_SIZE_LIMIT_FOR_REGEX_TREAT_PROTECTOR);
    if (payloadSizeLimit == null) {
        return false;
    }
    long requestPayloadSize = 0;
    org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext)
            .getAxis2MessageContext();
    Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String contentLength = (String) headers.get(HttpHeaders.CONTENT_LENGTH);
    if (contentLength != null) {
        requestPayloadSize = Integer.parseInt(contentLength);
    } else {  //When chunking is enabled
        SOAPEnvelope env = messageContext.getEnvelope();
        if (env != null) {
            SOAPBody soapbody = env.getBody();
            if (soapbody != null) {
                byte[] size = soapbody.toString().getBytes(Charset.defaultCharset());
                requestPayloadSize = size.length;
            }
        }
    }
    if (requestPayloadSize > payloadSizeLimit * 1024) {
        GatewayUtils.handleThreat(messageContext, APIMgtGatewayConstants.HTTP_SC_CODE, "Exceeded Request Payload " +
                "size limit allowed to be used with the enabledCheckBody option of Regular Expression Threat " +
                "Protector mediator");
        return true;
    }
    return false;
}
 
Example #26
Source File: AppendixV.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void checkSOAP11() throws XdsWSException {

	if ( !MessageContext.getCurrentMessageContext().isSOAP11()) {
		throwFault("SOAP 1.2 not supported");
	}
	SOAPEnvelope env = MessageContext.getCurrentMessageContext().getEnvelope();
	if (env == null)
		throwFault("No SOAP envelope found");
}
 
Example #27
Source File: CommandBuilderTestUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static MessageContext getMCWithSOAP12Envelope() throws AxisFault {
    MessageContext messageContext = new MessageContext();
    SOAPFactory factory = new SOAP12Factory();
    SOAPEnvelope envelope = factory.createSOAPEnvelope();
    messageContext.setEnvelope(envelope);
    return messageContext;
}
 
Example #28
Source File: AMQPConsumer.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * @param payload XML message content came inside the JMS message
 * @throws XMLStreamException on error
 */
private void parseOrder(String payload) throws XMLStreamException {
    InputStream is = new ByteArrayInputStream(payload.getBytes());
    javax.xml.stream.XMLStreamReader parser = XMLInputFactory
            .newInstance().createXMLStreamReader(is);
    StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser,
            null);
    SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
    // retrieve SOAP body
    SOAPBody soapBody = envelope.getBody();
    OMElement messageNode = soapBody.getFirstChildWithName(new QName(
            FIX_MSG));
    Iterator<?> messageElements = (Iterator<?>) messageNode
            .getChildElements();
    while (messageElements.hasNext()) {
        OMElement node = (OMElement) messageElements.next();
        if (node.getQName().getLocalPart().equals(FIX_MSG_BODY)) {
            Iterator<?> bodyElements = (Iterator<?>) node.getChildElements();
            while (bodyElements.hasNext()) {
                OMElement bodyNode = (OMElement) bodyElements.next();
                String tag = bodyNode
                        .getAttributeValue(new QName(FIX_MSG_ID));
                String value = bodyNode.getText();
                if (tag.equals(FIX_MSG_SYMBOL)) {
                    inSymbol = value;
                } else if (tag.equals(FIX_MSG_CLORDID)) {
                    inClOrderID = value;
                } else if (tag.equals(FIX_MSG_ORDQTY)) {
                    inQty = value;
                }
            }
        }
    }
}
 
Example #29
Source File: LoadBalanceSessionFullClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private void buildSoapEnvelopesWithClientSession() {
    Date date = new Date();
    SOAPEnvelope env1 = buildSoapEnvelope("" + (date.getTime() + 10), "v1");
    SOAPEnvelope env2 = buildSoapEnvelope("" + (date.getTime() + 20), "v1");
    SOAPEnvelope env3 = buildSoapEnvelope("" + (date.getTime() + 30), "v1");

    envelopes = new SOAPEnvelope[] { env1, env2, env3 };
}
 
Example #30
Source File: AxisOperationClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * @param payload
 * @return
 */

private SOAPEnvelope createSOAPEnvelope(OMElement payload) {
    fac = OMAbstractFactory.getSOAP11Factory();
    envelope = fac.getDefaultEnvelope();
    envelope.getBody().addChild(payload);
    return envelope;
}