001: /*
002: * Copyright (c) xsocket.org, 2006 - 2008. All rights reserved.
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
019: * The latest copy of this software may be found on http://www.xsocket.org/
020: */
021: package org.xsocket.connection.http;
022:
023: import java.io.IOException;
024: import java.net.URLEncoder;
025:
026: import org.junit.Assert;
027:
028: import org.junit.Test;
029:
030: import org.xsocket.connection.Server;
031: import org.xsocket.connection.ConnectionUtils;
032: import org.xsocket.connection.http.HttpRequest;
033: import org.xsocket.connection.http.HttpResponse;
034: import org.xsocket.connection.http.client.GetRequest;
035: import org.xsocket.connection.http.client.HttpClientConnection;
036: import org.xsocket.connection.http.client.IHttpResponseHandler;
037: import org.xsocket.connection.http.server.HttpServer;
038: import org.xsocket.connection.http.server.HttpServerConnection;
039: import org.xsocket.connection.http.server.IHttpResponseContext;
040: import org.xsocket.connection.http.server.IHttpRequestHandler;
041:
042: /**
043: *
044: * @author grro@xsocket.org
045: */
046: public final class ModifiedRequestHeaderTest {
047:
048: @Test
049: public void testModifiedRequestHeader() throws Exception {
050:
051: Handler hdl = new Handler();
052: Server server = new HttpServer(0, hdl);
053: ConnectionUtils.start(server);
054:
055: HttpClientConnection con = new HttpClientConnection(
056: "localhost", server.getLocalPort());
057: con.send(new GetRequest("/test?belong="
058: + URLEncoder.encode("geh\u00F6ren", "UTF-8")),
059: new ResponseHandler());
060:
061: QAUtil.sleep(300);
062:
063: Assert.assertNull("error occured " + hdl.error, hdl.error);
064: con.close();
065: server.close();
066: }
067:
068: private static final class ResponseHandler implements
069: IHttpResponseHandler {
070:
071: public void onResponse(HttpResponse response)
072: throws IOException {
073:
074: }
075: }
076:
077: private static final class Handler implements IHttpRequestHandler {
078:
079: private String error = null;
080:
081: public void onRequest(HttpRequest request,
082: IHttpResponseContext httpServerEndpoint)
083: throws IOException {
084: String value = request.getParameter("belong");
085: if (!value.equals("geh\u00F6ren")) {
086: error = "wrong encoding. got " + value
087: + " instead of geh\u00F6ren";
088: }
089:
090: request.setParameter("beautiful", "sch\u00F6n");
091:
092: if (request.toString().indexOf("geh%C3%B6ren") == -1) {
093: error = "wrong encoding for geh\u00F6ren "
094: + request.toString();
095: }
096:
097: if (request.toString().indexOf("sch%C3%B6n") == -1) {
098: error = "wrong encoding for sch\u00F6n "
099: + request.toString();
100: }
101: }
102: }
103: }
|