You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/06/01 21:44:02 UTC
svn commit: r780799 - in
/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core:
engine/ filter/http/
Author: veithen
Date: Mon Jun 1 19:44:01 2009
New Revision: 780799
URL: http://svn.apache.org/viewvc?rev=780799&view=rev
Log:
Rewrite 'Referer' and 'Location' headers when in non proxy mode.
Added:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java (with props)
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/Connection.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorConfiguration.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestResponseHandler.java
Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/Connection.java?rev=780799&r1=780798&r2=780799&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/Connection.java Mon Jun 1 19:44:01 2009
@@ -19,7 +19,7 @@
import org.apache.ws.commons.tcpmon.core.filter.Pipeline;
import org.apache.ws.commons.tcpmon.core.filter.StreamException;
import org.apache.ws.commons.tcpmon.core.filter.Tee;
-import org.apache.ws.commons.tcpmon.core.filter.http.HttpHeaderRewriter;
+import org.apache.ws.commons.tcpmon.core.filter.http.HostRewriter;
import org.apache.ws.commons.tcpmon.core.filter.http.HttpProxyClientHandler;
import org.apache.ws.commons.tcpmon.core.filter.http.HttpProxyServerHandler;
import org.apache.ws.commons.tcpmon.core.filter.http.HttpRequestFilter;
@@ -113,6 +113,7 @@
requestTee = new Tee();
HttpRequestFilter requestFilter = new HttpRequestFilter(false);
requestPipeline.addFilter(requestFilter);
+ HostRewriter hostRewriter;
if (config.isProxy()) {
requestFilter.addHandler(new HttpProxyServerHandler() {
protected void handleConnection(String host, int port) {
@@ -123,8 +124,10 @@
}
}
});
+ hostRewriter = null;
} else {
- requestFilter.addHandler(new HttpHeaderRewriter("Host", targetHost + ":" + targetPort));
+ hostRewriter = new HostRewriter(targetHost, targetPort, config.isSecureSocketFactory());
+ requestFilter.addHandler(hostRewriter);
connectToTarget(targetHost, targetPort);
}
// We log the request data at this stage. This means that the user will see the request
@@ -163,6 +166,9 @@
if (responseContentFilterFactory != null) {
responseFilter.setContentFilterFactory(responseContentFilterFactory);
}
+ if (hostRewriter != null) {
+ responseFilter.addHandler(hostRewriter);
+ }
responsePipeline.addFilter(responseFilter);
config.applyResponseFilters(responsePipeline);
if (tmpOut1 != null) {
Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorConfiguration.java?rev=780799&r1=780798&r2=780799&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorConfiguration.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/engine/InterceptorConfiguration.java Mon Jun 1 19:44:01 2009
@@ -18,6 +18,7 @@
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
+import javax.net.ssl.SSLSocketFactory;
import org.apache.ws.commons.tcpmon.core.filter.Pipeline;
import org.apache.ws.commons.tcpmon.core.filter.StreamFilterFactory;
@@ -73,6 +74,10 @@
return socketFactory;
}
+ public boolean isSecureSocketFactory() {
+ return socketFactory instanceof SSLSocketFactory;
+ }
+
public String getTargetHost() {
return targetHost;
}
Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestResponseHandler.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestResponseHandler.java?rev=780799&r1=780798&r2=780799&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestResponseHandler.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestResponseHandler.java Mon Jun 1 19:44:01 2009
@@ -20,7 +20,7 @@
* Abstract implementation of {@link HttpRequestHandler} and {@link HttpResponseHandler}
* with default behavior.
*/
-public abstract class AbstractHttpRequestResponseHandler implements HttpRequestHandler {
+public abstract class AbstractHttpRequestResponseHandler implements HttpRequestHandler, HttpResponseHandler {
public String processRequestLine(String requestLine) {
return requestLine;
}
Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java?rev=780799&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java Mon Jun 1 19:44:01 2009
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.ws.commons.tcpmon.core.filter.http;
+
+public class HostRewriter extends AbstractHttpRequestResponseHandler {
+ private static final String[] rewritableRequestHeaders = { "Referer" };
+ private static final String[] rewritableResponseHeaders = { "Location" };
+
+ private final String targetHost;
+ private final int targetPort;
+ private final String targetBaseUri;
+ private String orgBaseUri;
+
+ public HostRewriter(String targetHost, int targetPort, boolean isSecure) {
+ this.targetHost = targetHost;
+ this.targetPort = targetPort;
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(isSecure ? "https" : "http");
+ buffer.append("://");
+ buffer.append(targetHost);
+ if ((!isSecure && targetPort != 80) || (isSecure && targetPort != 443)) {
+ buffer.append(":");
+ buffer.append(targetPort);
+ }
+ buffer.append("/");
+ targetBaseUri = buffer.toString();
+ }
+
+ private void rewriteUriHeaders(Headers headers, String[] names, String fromBaseUri, String toBaseUri) {
+ for (int i=0; i<names.length; i++) {
+ String name = names[i];
+ Header header = headers.getFirst(name);
+ if (header != null) {
+ String value = header.getValue();
+ if (value.startsWith(fromBaseUri)) {
+ headers.set(name, toBaseUri + value.substring(fromBaseUri.length()));
+ }
+ }
+ }
+ }
+
+ public void processRequestHeaders(Headers headers) {
+ Header header = headers.getFirst("Host");
+ if (header != null) {
+ orgBaseUri = "http://" + header.getValue() + "/";
+ headers.set("Host", targetHost + ":" + targetPort);
+ rewriteUriHeaders(headers, rewritableRequestHeaders, orgBaseUri, targetBaseUri);
+ }
+ }
+
+ public void processResponseHeaders(Headers headers) {
+ if (orgBaseUri != null) {
+ rewriteUriHeaders(headers, rewritableResponseHeaders, targetBaseUri, orgBaseUri);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HostRewriter.java
------------------------------------------------------------------------------
svn:eol-style = native