Java Code Examples for org.apache.axiom.om.OMAbstractFactory#getSOAP12Factory()

The following examples show how to use org.apache.axiom.om.OMAbstractFactory#getSOAP12Factory() . 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: 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 3
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 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: 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 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: DataServiceCallMediator.java    From micro-integrator with Apache License 2.0 5 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");
        }
        return soapFactory.getDefaultEnvelope();
    }
 
Example 13
Source File: EntitlementMediator.java    From micro-integrator with Apache License 2.0 5 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");
        }
        return soapFactory.getDefaultEnvelope();
    }
 
Example 14
Source File: ServiceInvoker.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void setClientSessionID(String id) {

        SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

        OMNamespace synNamespace = soapFactory.
                createOMNamespace("http://ws.apache.org/namespaces/synapse", "syn");
        SOAPHeaderBlock header = soapFactory.createSOAPHeaderBlock("ClientID", synNamespace);
        header.setText(id);

        client.addHeader(header);
    }
 
Example 15
Source File: ServiceInvoker.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public void setClientSessionID(String id) {

        SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

        OMNamespace synNamespace = soapFactory.
                createOMNamespace("http://ws.apache.org/namespaces/synapse", "syn");
        SOAPHeaderBlock header = soapFactory.createSOAPHeaderBlock("ClientID", synNamespace);
        header.setText(id);

        client.addHeader(header);
    }
 
Example 16
Source File: ServiceInvoker.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void setClientSessionID(String id) {

        SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

        OMNamespace synNamespace = soapFactory.
                createOMNamespace("http://ws.apache.org/namespaces/synapse", "syn");
        SOAPHeaderBlock header = soapFactory.createSOAPHeaderBlock("ClientID", synNamespace);
        header.setText(id);

        client.addHeader(header);
    }
 
Example 17
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 18
Source File: TestSchemaValidator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private void setMockedRequest(String httpMethod, String resourcePath, String xmlMessage) throws XMLStreamException, IOException {
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    OMElement messageStore = AXIOMUtil.stringToOM(xmlMessage);
    env.getBody().addChild(messageStore);
    log.info(" Running the test case to validate the request content against the defined schemas.");
    String contentType = "application/json";
    String ApiId = "admin-SwaggerPetstore-1.0.0";
    File swaggerJsonFile = new File(Thread.currentThread().getContextClassLoader().
            getResource("swaggerEntry/swagger.json").getFile());
    String swaggerValue = FileUtils.readFileToString(swaggerJsonFile);

    Mockito.doReturn(env).when(messageContext).getEnvelope();
    // Mockito.when()

    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgContext);
    Mockito.when((String) axis2MsgContext.getProperty(APIMgtGatewayConstants.REST_CONTENT_TYPE))
            .thenReturn(contentType);
    Mockito.when((String) axis2MsgContext.getProperty(APIMgtGatewayConstants.HTTP_REQUEST_METHOD)).
            thenReturn(httpMethod);
    Mockito.when(messageContext.getConfiguration()).thenReturn(synapseConfiguration);
    Mockito.when(synapseConfiguration.getLocalRegistry()).thenReturn(map);
    Mockito.when(map.get(uuid)).thenReturn(entry);

    Mockito.when(messageContext.getConfiguration()).thenReturn(synapseConfiguration);
    Mockito.when((String) messageContext.getProperty((APIMgtGatewayConstants.API_ELECTED_RESOURCE))).
            thenReturn(resourcePath);
    Mockito.when(synapseConfiguration.getLocalRegistry()).thenReturn(map);
    Mockito.when(map.get(ApiId)).thenReturn(entry);
    Mockito.when((String) entry.getValue()).thenReturn(swaggerValue);
    Mockito.when((String) messageContext.getProperty(APIMgtGatewayConstants.ELECTED_REQUEST_METHOD)).
            thenReturn(httpMethod);
    Mockito.when((String) axis2MsgContext.getProperty(APIMgtGatewayConstants.HTTP_REQUEST_METHOD)).
            thenReturn(httpMethod);
    Mockito.when((String) messageContext.getProperty(APIMgtGatewayConstants.OPEN_API_STRING))
            .thenReturn(swaggerValue);
}
 
Example 19
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 20
Source File: APIMgtResponseHandlerTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test
public void mediateWithChunkEnable() throws Exception {
    APIMgtUsageDataPublisher apiMgtUsageDataPublisher = Mockito.mock(APIMgtUsageDataPublisher.class);
    APIManagerAnalyticsConfiguration apiManagerAnalyticsConfiguration = Mockito.mock
            (APIManagerAnalyticsConfiguration.class);
    Mockito.when(apiManagerAnalyticsConfiguration.isBuildMsg()).thenReturn(true);
    APIMgtResponseHandler apiMgtResponseHandler = new APIMgtResponseHandlerWrapper(apiMgtUsageDataPublisher,
            true, false, apiManagerAnalyticsConfiguration);
    MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
    org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext
            .class);
    Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
    Mockito.when(axis2MsgCntxt.getProperty(SynapseConstants.HTTP_SC)).thenReturn(200);
    Map headers = new HashMap();
    Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn
            (headers);
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    env.getBody().addChild(fac.createOMElement("test", "http://t", "t"));
    Mockito.when(messageContext.getEnvelope()).thenReturn(env);
    Mockito.when(messageContext.getProperty("REST_FULL_REQUEST_PATH")).thenReturn("/abc/1.0.0/a");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.REQUEST_START_TIME)).thenReturn("12345678");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.CONSUMER_KEY)).thenReturn("abc-def-ghi");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.CONTEXT)).thenReturn("/abc/1.0.0");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_VERSION)).thenReturn("1.0.0");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API)).thenReturn("api1");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.RESOURCE)).thenReturn("/a");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.HTTP_METHOD)).thenReturn("GET");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.VERSION)).thenReturn("1.0.0");
    Mockito.when((messageContext.getProperty(SynapseConstants.ERROR_CODE))).thenReturn("404");
    Mockito.when(messageContext.getProperty(SynapseConstants.ERROR_MESSAGE)).thenReturn("not found");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.USER_ID)).thenReturn("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.HOST_NAME)).thenReturn("127.0.0.1");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.API_PUBLISHER)).thenReturn("admin");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.APPLICATION_NAME)).thenReturn("App1");
    Mockito.when(messageContext.getProperty(APIMgtGatewayConstants.APPLICATION_ID)).thenReturn("1");
    Mockito.when(messageContext.getProperty(SynapseConstants.TRANSPORT_IN_NAME)).thenReturn("https");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API)).thenReturn("admin--api1-1.0.0");
    Mockito.when(messageContext.getProperty(RESTConstants.REST_URL_PREFIX)).thenReturn("https://localhost");
    apiMgtResponseHandler.mediate(messageContext);
}