Search in sources :

Example 46 with SOAPFactory

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

the class HTCoordinationContextHandler method invokeRegistrationService.

private OMElement invokeRegistrationService(String identifier, String taskProtocolHandlerServiceURL, String registrationService) throws AxisFault {
    OMElement payload = SOAPUtils.getRegistrationPayload(identifier, taskProtocolHandlerServiceURL);
    SOAPFactory soap11Factory = OMAbstractFactory.getSOAP11Factory();
    MessageContext mctx = new MessageContext();
    if (mctx.getEnvelope() == null) {
        mctx.setEnvelope(soap11Factory.createSOAPEnvelope());
    }
    if (mctx.getEnvelope().getBody() == null) {
        soap11Factory.createSOAPBody(mctx.getEnvelope());
    }
    if (mctx.getEnvelope().getHeader() == null) {
        soap11Factory.createSOAPHeader(mctx.getEnvelope());
    }
    mctx.getEnvelope().getBody().addChild(payload);
    // //Setting basic auth headers. Reading those information using HT server config.
    // HumanTaskServerConfiguration serverConfig = HTCoordinationModuleContentHolder.getInstance().getHtServer().getServerConfig();
    // String tenantDomain = MultitenantUtils.getTenantDomainFromUrl(registrationService);
    // if (registrationService.equals(tenantDomain)) {
    // //this is a Super tenant registration service
    // if (log.isDebugEnabled()) {
    // log.debug("Sending Username" + serverConfig.getRegistrationServiceAuthUsername() + " - " + serverConfig.getRegistrationServiceAuthPassword());  //TODO REMOVE this
    // }
    // CarbonUtils.setBasicAccessSecurityHeaders(serverConfig.getRegistrationServiceAuthUsername(), serverConfig.getRegistrationServiceAuthPassword(), true, mctx);
    // } else {
    // if (log.isDebugEnabled()) {
    // log.debug("Sending ws-coor Registration request to tenant domain: " + tenantDomain);
    // }
    // // Tenant's registration service
    // 
    // String username = serverConfig.getRegistrationServiceAuthUsername() + "@" + tenantDomain;
    // String pass = serverConfig.getRegistrationServiceAuthPassword();
    // if (log.isDebugEnabled()) {
    // log.debug("Sending Username" + username + " - " + pass);  //TODO REMOVE this
    // }
    // CarbonUtils.setBasicAccessSecurityHeaders(
    // username,
    // pass,
    // true,
    // mctx);
    // }
    MessageContext responseMsgContext = ServiceUtils.invokeRegistrationService(mctx, registrationService);
    if (responseMsgContext.getEnvelope() != null) {
        if (responseMsgContext.getEnvelope().getBody() != null) {
            return responseMsgContext.getEnvelope().getBody();
        }
    }
    return null;
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 47 with SOAPFactory

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

the class RegularExpressionProtectorTest method testSqlInjectionInBody.

/**
 * 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);
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 48 with SOAPFactory

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

the class PlainTextFormatterTest method createElementMessageContextElement.

private MessageContext createElementMessageContextElement(String textPayload) throws AxisFault {
    try {
        MessageContext messageContext = new MessageContext();
        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope envelope = factory.getDefaultEnvelope();
        OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
        OMElement payload = AXIOMUtil.stringToOM(textPayload);
        textWrapper.addChild(payload);
        envelope.getBody().addChild(textWrapper);
        messageContext.setEnvelope(envelope);
        return messageContext;
    } catch (XMLStreamException e) {
        // This is highly unlikely to happen
        return null;
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 49 with SOAPFactory

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

the class PlainTextFormatterTest method createMessageContext.

private MessageContext createMessageContext(String textPayload) throws AxisFault {
    MessageContext messageContext = new MessageContext();
    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope envelope = factory.getDefaultEnvelope();
    OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
    textWrapper.setText(textPayload);
    envelope.getBody().addChild(textWrapper);
    messageContext.setEnvelope(envelope);
    return messageContext;
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 50 with SOAPFactory

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

the class MinConcurrencyTest method runTest.

@Override
protected void runTest() throws Throwable {
    int endpointCount = channels.length;
    int expectedConcurrency = endpointCount * messages;
    final MessageReceiver messageReceiver = new MessageReceiver() {

        public void receive(MessageContext msgContext) throws AxisFault {
            synchronized (concurrencyReachedLock) {
                concurrencyReached++;
                concurrencyReachedLock.notifyAll();
            }
            try {
                synchronized (shutdownAwaitLock) {
                    shutdownAwaitLock.wait();
                }
            } catch (InterruptedException ex) {
            }
        }
    };
    TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
    TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
    try {
        for (int i = 0; i < endpointCount; i++) {
            TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
            AsyncChannel channel = channels[i];
            clientResourceSet.addResource(channel);
            AxisAsyncTestClient client = new AxisAsyncTestClient(false);
            clientResourceSet.addResource(client);
            clientResourceSet.setUp();
            clientResourceSets[i] = clientResourceSet;
            TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
            endpointResourceSet.addResource(new AxisTestEndpoint() {

                @Override
                protected AxisOperation createOperation() {
                    AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
                    operation.setMessageReceiver(messageReceiver);
                    return operation;
                }

                @Override
                protected void onTransportError(Throwable ex) {
                // TODO Auto-generated method stub
                }
            });
            if (!preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
            for (int j = 0; j < messages; j++) {
                ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
                AxisMessage message = new AxisMessage();
                message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
                SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
                SOAPEnvelope envelope = factory.getDefaultEnvelope();
                message.setEnvelope(envelope);
                client.sendMessage(options, new ContentType(message.getMessageType()), message);
            }
            if (preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
        }
        long startTime = System.currentTimeMillis();
        while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
            synchronized (concurrencyReachedLock) {
                concurrencyReachedLock.wait(5000);
            }
        }
        synchronized (shutdownAwaitLock) {
            shutdownAwaitLock.notifyAll();
        }
        if (concurrencyReached < expectedConcurrency) {
            fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
        }
    } finally {
        for (int i = 0; i < endpointCount; i++) {
            if (endpointResourceSets[i] != null) {
                endpointResourceSets[i].tearDown();
            }
            if (clientResourceSets[i] != null) {
                clientResourceSets[i].tearDown();
            }
        }
    }
}
Also used : ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) ContentType(javax.mail.internet.ContentType) QName(javax.xml.namespace.QName) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) MessageReceiver(org.apache.axis2.engine.MessageReceiver) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) MessageContext(org.apache.axis2.context.MessageContext) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage)

Aggregations

SOAPFactory (org.apache.axiom.soap.SOAPFactory)70 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)50 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 AxisFault (org.apache.axis2.AxisFault)11 MessageContext (org.apache.axis2.context.MessageContext)11 DataHandler (javax.activation.DataHandler)10 OMNamespace (org.apache.axiom.om.OMNamespace)9 SOAPHeader (org.apache.axiom.soap.SOAPHeader)9 SynapseException (org.apache.synapse.SynapseException)9 Iterator (java.util.Iterator)8 OMNode (org.apache.axiom.om.OMNode)7 SOAPFault (org.apache.axiom.soap.SOAPFault)7 IOException (java.io.IOException)6 EndpointReference (org.apache.axis2.addressing.EndpointReference)6 ArrayList (java.util.ArrayList)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 OMAttribute (org.apache.axiom.om.OMAttribute)4