Author: veithen
Date: Mon Jun 1 15:44:21 2009
New Revision: 780695
URL: http://svn.apache.org/viewvc?rev=780695&view=rev
Log:
Replaced the HeaderProcessor with something more flexible.
Added:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderParser.java
(with props)
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Header.java
(with props)
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HeaderHandler.java
- copied, changed from r780659,
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Headers.java
(with props)
Removed:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderProcessor.java
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpResponseHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpHeaderRewriter.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpRequestHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpResponseHandler.java
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/mime/MimePartFilter.java
Added:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderParser.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/HeaderParser.java?rev=780695&view=auto
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderParser.java
(added)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderParser.java
Mon Jun 1 15:44:21 2009
@@ -0,0 +1,156 @@
+/*
+ * 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;
+
+/**
+ * Utility class to parse a set of HTTP/MIME/RFC822 headers from a stream.
+ *
+ */
+public class HeaderParser {
+ private static final int STATE_UNKNOWN = 0;
+ private static final int STATE_AVAILABLE = 1;
+ private static final int STATE_NOT_AVAILABLE = 2;
+ private static final int STATE_NO_MORE_HEADERS = 3;
+
+ private final Stream stream;
+ private int state = STATE_UNKNOWN;
+ private int eol;
+ private int colon;
+ private int valueStart;
+
+ public HeaderParser(Stream stream) {
+ this.stream = stream;
+ }
+
+ private void updateState() {
+ if (state != STATE_UNKNOWN) {
+ return;
+ }
+ eol = StreamUtil.searchEndOfLine(stream);
+ if (eol == -1) {
+ state = STATE_NOT_AVAILABLE;
+ return;
+ }
+ if (eol == 0) {
+ state = STATE_NO_MORE_HEADERS;
+ return;
+ }
+ for (int i=0; i<eol; i++) {
+ if (stream.get(i) == ':') {
+ colon = i;
+ break;
+ }
+ }
+ valueStart = colon+1;
+ while (stream.get(valueStart) == ' ') {
+ valueStart++;
+ }
+ state = STATE_AVAILABLE;
+ }
+
+ /**
+ * Check whether a header is currently available from the underlying
stream.
+ *
+ * @return <code>true</code> if a header is available
+ */
+ public boolean available() {
+ updateState();
+ return state == STATE_AVAILABLE;
+ }
+
+ /**
+ * Get the name of the current header.
+ *
+ * @return the name of the header
+ */
+ public String getHeaderName() {
+ if (state != STATE_AVAILABLE) {
+ throw new IllegalStateException();
+ }
+ return StreamUtil.getAsciiString(stream, 0, colon);
+ }
+
+ /**
+ * Get the value of the current header.
+ *
+ * @return the value of the header
+ */
+ public String getHeaderValue() {
+ if (state != STATE_AVAILABLE) {
+ throw new IllegalStateException();
+ }
+ return StreamUtil.getAsciiString(stream, valueStart, eol);
+ }
+
+ /**
+ * Skip the current header. This will copy the current header
+ * to the next filter.
+ */
+ public void skip() {
+ if (state != STATE_AVAILABLE && state != STATE_NO_MORE_HEADERS) {
+ throw new IllegalStateException();
+ }
+ stream.skip(eol+2);
+ state = STATE_UNKNOWN;
+ }
+
+ /**
+ * Discard the current header.
+ */
+ public void discard() {
+ if (state != STATE_AVAILABLE && state != STATE_NO_MORE_HEADERS) {
+ throw new IllegalStateException();
+ }
+ stream.discard(eol+2);
+ state = STATE_UNKNOWN;
+ }
+
+ /**
+ * Insert a new header in the stream.
+ *
+ * @param name the name of the header
+ * @param value the value of the header
+ */
+ public void insert(String name, String value) {
+ StreamUtil.insertAsciiString(stream, name);
+ StreamUtil.insertAsciiString(stream, ": ");
+ StreamUtil.insertAsciiString(stream, value);
+ StreamUtil.insertAsciiString(stream, "\r\n");
+ }
+
+ /**
+ * Change the value of the current header. This will advance the position
+ * to the next header.
+ *
+ * @param newValue
+ */
+ public void change(String newValue) {
+ if (state != STATE_AVAILABLE) {
+ throw new IllegalStateException();
+ }
+ stream.skip(valueStart);
+ stream.discard(eol-valueStart);
+ StreamUtil.insertAsciiString(stream, newValue);
+ stream.skip(2);
+ state = STATE_UNKNOWN;
+ }
+
+ public boolean noMoreHeaders() {
+ updateState();
+ return state == STATE_NO_MORE_HEADERS;
+ }
+}
Propchange:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestHandler.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/AbstractHttpRequestHandler.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestHandler.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpRequestHandler.java
Mon Jun 1 15:44:21 2009
@@ -24,8 +24,7 @@
return requestLine;
}
- public String handleHeader(String name, String value) {
- return value;
+ public void handleHeaders(Headers headers) {
}
public void requestCompleted() {
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpResponseHandler.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/AbstractHttpResponseHandler.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpResponseHandler.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/AbstractHttpResponseHandler.java
Mon Jun 1 15:44:21 2009
@@ -24,8 +24,7 @@
return responseLine;
}
- public String handleHeader(String name, String value) {
- return value;
+ public void handleHeaders(Headers headers) {
}
public void responseCompleted() {
Added:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Header.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/Header.java?rev=780695&view=auto
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Header.java
(added)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Header.java
Mon Jun 1 15:44:21 2009
@@ -0,0 +1,35 @@
+/*
+ * 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 Header {
+ private final String name;
+ private final String value;
+
+ public Header(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
Propchange:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Header.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HeaderHandler.java
(from r780659,
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderHandler.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/HeaderHandler.java?p2=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HeaderHandler.java&p1=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderHandler.java&r1=780659&r2=780695&rev=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/HeaderHandler.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HeaderHandler.java
Mon Jun 1 15:44:21 2009
@@ -14,19 +14,16 @@
* limitations under the License.
*/
-package org.apache.ws.commons.tcpmon.core.filter;
+package org.apache.ws.commons.tcpmon.core.filter.http;
/**
- * Handle headers extracted by {...@link HeaderProcessor}.
+ * Handles a set of headers.
*/
public interface HeaderHandler {
/**
- * Handle a header.
+ * Handle a set of headers.
*
- * @param name the name of the header
- * @param value the value of the header
- * @return the new value of the header or <code>null</code> if
- * the {...@link HeaderProcessor} should remove the header
+ * @param headers the headers to process
*/
- String handleHeader(String name, String value);
+ void handleHeaders(Headers headers);
}
Added:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Headers.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/Headers.java?rev=780695&view=auto
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Headers.java
(added)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Headers.java
Mon Jun 1 15:44:21 2009
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+public class Headers {
+ private final List/*<Header>*/ headers = new LinkedList();
+
+ public void add(String name, String value) {
+ headers.add(new Header(name, value));
+ }
+
+ public Header getFirst(String name) {
+ for (Iterator it = headers.iterator(); it.hasNext(); ) {
+ Header header = (Header)it.next();
+ if (header.getName().equalsIgnoreCase(name)) {
+ return header;
+ }
+ }
+ return null;
+ }
+
+ public void set(String name, String value) {
+ boolean replaced = false;
+ Header newHeader = new Header(name, value);
+ for (ListIterator it = headers.listIterator(); it.hasNext(); ) {
+ Header header = (Header)it.next();
+ if (header.getName().equalsIgnoreCase(name)) {
+ if (replaced) {
+ it.remove();
+ } else {
+ it.set(newHeader);
+ replaced = true;
+ }
+ }
+ }
+ if (!replaced) {
+ headers.add(newHeader);
+ }
+ }
+
+ public Iterator iterator() {
+ return headers.iterator();
+ }
+}
Propchange:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/Headers.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.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/HttpFilter.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpFilter.java
Mon Jun 1 15:44:21 2009
@@ -21,8 +21,7 @@
import java.util.List;
import org.apache.ws.commons.tcpmon.core.filter.EntityProcessor;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderHandler;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderProcessor;
+import org.apache.ws.commons.tcpmon.core.filter.HeaderParser;
import org.apache.ws.commons.tcpmon.core.filter.ReadOnlyStream;
import org.apache.ws.commons.tcpmon.core.filter.Stream;
import org.apache.ws.commons.tcpmon.core.filter.StreamFilter;
@@ -38,21 +37,16 @@
private static final int STATE_CONTENT = 2;
private static final int STATE_COMPLETE = 3;
- private final HeaderProcessor headerProcessor = new HeaderProcessor();
private final boolean decodeTransferEncoding;
protected final List handlers = new LinkedList();
private int state = STATE_FIRST_LINE;
+ private final Headers headers = new Headers();
private ContentFilterFactory contentFilterFactory;
private EntityProcessor transferDecoder;
private StreamFilter[] contentFilterChain;
public HttpFilter(boolean decodeTransferEncoding) {
this.decodeTransferEncoding = decodeTransferEncoding;
- headerProcessor.addHandler(new HeaderHandler() {
- public String handleHeader(String name, String value) {
- return processHeader(name, value);
- }
- });
}
public void setContentFilterFactory(ContentFilterFactory
contentFilterFactory) {
@@ -89,7 +83,18 @@
break;
}
case STATE_HEADER: {
- if (headerProcessor.process(stream)) {
+ HeaderParser headerParser = new HeaderParser(stream);
+ while (headerParser.available()) {
+ headers.add(headerParser.getHeaderName(),
headerParser.getHeaderValue());
+ headerParser.discard();
+ }
+ if (headerParser.noMoreHeaders()) {
+ processHeaders();
+ for (Iterator it = headers.iterator(); it.hasNext(); )
{
+ Header header = (Header)it.next();
+ headerParser.insert(header.getName(),
header.getValue());
+ }
+ headerParser.skip();
state = STATE_CONTENT;
if (contentFilterChain != null) {
for (int i=contentFilterChain.length-1; i>=0; i--)
{
@@ -127,24 +132,25 @@
protected abstract String processFirstLine(String firstList);
protected abstract void completed();
- private String processHeader(String name, String value) {
- if (name.equalsIgnoreCase("Content-Length")) {
- transferDecoder = new IdentityDecoder(Integer.parseInt(value));
- } else if (name.equalsIgnoreCase("Transfer-Encoding")) {
- if (value.equals("chunked")) {
- transferDecoder = new ChunkedDecoder();
- }
- } else if (name.equalsIgnoreCase("Content-Type")) {
- if (contentFilterFactory != null) {
- contentFilterChain =
contentFilterFactory.getContentFilterChain(value);
+ private void processHeaders() {
+ for (Iterator it = headers.iterator(); it.hasNext(); ) {
+ Header header = (Header)it.next();
+ String name = header.getName();
+ String value = header.getValue();
+ if (name.equalsIgnoreCase("Content-Length")) {
+ transferDecoder = new IdentityDecoder(Integer.parseInt(value));
+ } else if (name.equalsIgnoreCase("Transfer-Encoding")) {
+ if (value.equals("chunked")) {
+ transferDecoder = new ChunkedDecoder();
+ }
+ } else if (name.equalsIgnoreCase("Content-Type")) {
+ if (contentFilterFactory != null) {
+ contentFilterChain =
contentFilterFactory.getContentFilterChain(value);
+ }
}
}
for (Iterator it = handlers.iterator(); it.hasNext(); ) {
- value = ((HeaderHandler)it.next()).handleHeader(name, value);
- if (value == null) {
- break;
- }
+ ((HeaderHandler)it.next()).handleHeaders(headers);
}
- return value;
}
}
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpHeaderRewriter.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/HttpHeaderRewriter.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpHeaderRewriter.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpHeaderRewriter.java
Mon Jun 1 15:44:21 2009
@@ -28,7 +28,7 @@
this.newValue = newValue;
}
- public String handleHeader(String name, String value) {
- return headerName.equals(name) ? newValue : value;
+ public void handleHeaders(Headers headers) {
+ headers.set(headerName, newValue);
}
}
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpRequestHandler.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/HttpRequestHandler.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpRequestHandler.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpRequestHandler.java
Mon Jun 1 15:44:21 2009
@@ -16,7 +16,6 @@
package org.apache.ws.commons.tcpmon.core.filter.http;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderHandler;
/**
* Interface implemented by handlers invoked by {...@link HttpRequestFilter}.
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpResponseHandler.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/HttpResponseHandler.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpResponseHandler.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/http/HttpResponseHandler.java
Mon Jun 1 15:44:21 2009
@@ -16,7 +16,6 @@
package org.apache.ws.commons.tcpmon.core.filter.http;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderHandler;
/**
* Interface implemented by handlers invoked by {...@link HttpResponseFilter}.
Modified:
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/mime/MimePartFilter.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/mime/MimePartFilter.java?rev=780695&r1=780694&r2=780695&view=diff
==============================================================================
---
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/mime/MimePartFilter.java
(original)
+++
webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/filter/mime/MimePartFilter.java
Mon Jun 1 15:44:21 2009
@@ -16,8 +16,7 @@
package org.apache.ws.commons.tcpmon.core.filter.mime;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderHandler;
-import org.apache.ws.commons.tcpmon.core.filter.HeaderProcessor;
+import org.apache.ws.commons.tcpmon.core.filter.HeaderParser;
import org.apache.ws.commons.tcpmon.core.filter.Stream;
import org.apache.ws.commons.tcpmon.core.filter.StreamFilter;
@@ -25,28 +24,30 @@
* Filter that processes a MIME part.
*/
public class MimePartFilter implements StreamFilter {
- private HeaderProcessor headerProcessor;
- private StreamFilter[] contentFilterChain;
+ private static final int HEADERS = 0;
+ private static final int CONTENT = 1;
- public MimePartFilter(final ContentFilterFactory contentFilterFactory) {
- headerProcessor = new HeaderProcessor();
- headerProcessor.addHandler(new HeaderHandler() {
- public String handleHeader(String name, String value) {
- if (name.equalsIgnoreCase("Content-Type")) {
- contentFilterChain =
contentFilterFactory.getContentFilterChain(value);
- }
- return value;
- }
- });
+ private final ContentFilterFactory contentFilterFactory;
+ private int state = HEADERS;
+ private StreamFilter[] contentFilterChain;
+
+ public MimePartFilter(ContentFilterFactory contentFilterFactory) {
+ this.contentFilterFactory = contentFilterFactory;
}
public void invoke(Stream stream) {
while (stream.available() > 0) {
- if (headerProcessor == null) {
- stream.skipAll();
- } else {
- if (headerProcessor.process(stream)) {
- headerProcessor = null;
+ if (state == HEADERS) {
+ HeaderParser headers = new HeaderParser(stream);
+ while (headers.available()) {
+ if
(headers.getHeaderName().equalsIgnoreCase("Content-Type")) {
+ contentFilterChain =
contentFilterFactory.getContentFilterChain(headers.getHeaderValue());
+ }
+ headers.skip();
+ }
+ if (headers.noMoreHeaders()) {
+ headers.skip();
+ state = CONTENT;
if (contentFilterChain != null) {
for (int i=contentFilterChain.length-1; i>=0; i--) {
stream.pushFilter(contentFilterChain[i]);
@@ -56,6 +57,7 @@
return;
}
}
+ stream.skipAll();
}
}
}