Java tutorial
/* * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.esb.mediators.callout; import org.apache.commons.lang.StringUtils; import org.testng.Assert; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import org.wso2.carbon.automation.core.utils.HttpRequestUtil; import org.wso2.carbon.esb.ESBIntegrationTest; import org.wso2.carbon.esb.util.WireMonitorServer; import java.net.URL; import java.util.HashMap; import java.util.Map; /** * Test Scenario: If there are headers different in case (uppercase and lowercase), Axis2 HTTPSender processes them as * separate headers. This causes problems when using blocking transport on ESB. This test case takes into account the * "SOAPAction" header and checks whether there are duplicates for the same. */ public class CARBON15119DuplicateSOAPActionHeader extends ESBIntegrationTest { WireMonitorServer wireMonitorServer; @BeforeTest(alwaysRun = true) public void init() throws Exception { super.init(); wireMonitorServer = new WireMonitorServer(6769); wireMonitorServer.start(); loadESBConfigurationFromClasspath("/artifacts/ESB/mediatorconfig/callout/DuplicateSOAPActionHeader.xml"); } @Test(groups = "wso2.esb", description = "Test to check whether there are duplicate SOAPAction headers in the request to the service from callout mediator") public void testCheckForDuplicateSOAPActionHeaders() throws Exception { String proxyServiceUrl = getProxyServiceURL("DuplicateSOAPActionHeader"); String requestPayload = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' >" + "<soapenv:Body xmlns:ser='http://services.samples' xmlns:xsd='http://services.samples/xsd'> " + "<ser:getQuote> <ser:request> <xsd:symbol>WSO2</xsd:symbol> </ser:request> </ser:getQuote> " + "</soapenv:Body></soapenv:Envelope> "; Map<String, String> headers = new HashMap<String, String>(); headers.put("Soapaction", "urn:getQuote"); HttpRequestUtil.doPost(new URL(proxyServiceUrl), requestPayload, headers); String capturedMsg = wireMonitorServer.getCapturedMessage(); int matchesCount = StringUtils.countMatches(capturedMsg.toLowerCase(), "soapaction"); Assert.assertTrue(matchesCount == 1); } @AfterTest(alwaysRun = true) public void destroy() throws Exception { super.cleanup(); } }