/*
* Copyright (c) 2005-2010, 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.esb.integration.nhttp;
import org.wso2.esb.integration.ESBIntegrationTest;
import org.wso2.esb.integration.http.SimpleHttpServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.rmi.RemoteException;
public class QueryParameterManipulationTest extends ESBIntegrationTest {
@Override
public void init() {
super.init();
log.info("Verifying functionality against the bug: ESBJAVA-626");
}
@Override
public void successfulScenario() throws RemoteException {
updateESBConfiguration("/query_param.xml");
SimpleHttpServer httpServer = new SimpleHttpServer();
try {
httpServer.start();
makeGET(new URL(getProxyServiceURL("ParamManipulationProxy", false) + "?MyParam=TestValue"));
} catch (IOException e) {
handleError("Error while running the GET request test", e);
} finally {
try {
httpServer.stop();
} catch (IOException e) {
log.warn("Error while shutting down the HTTP server", e);
}
}
}
private void makeGET(URL url) throws IOException {
URLConnection conn = url.openConnection ();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
String response = sb.toString();
log.info("Response received: " + response);
assertTrue(response != null && response.length() > 0);
}
}