diff options
Diffstat (limited to 'plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http')
6 files changed, 0 insertions, 1145 deletions
diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPConnection.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPConnection.java deleted file mode 100644 index 02cb85d42..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPConnection.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import org.eclipse.wst.internet.monitor.core.internal.Monitor; -import org.eclipse.wst.internet.monitor.core.internal.Trace; -import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor; -import org.eclipse.wst.internet.monitor.core.internal.provisional.Request; - -import java.util.List; -import java.util.ArrayList; -/** - * Manages a monitor server connection between two hosts. This - * connection may spawn one or more TCP/IP requests to be displayed - * in the monitor server view. - */ -public class HTTPConnection { - protected IMonitor monitor; - - protected int req = -1; - protected int resp = -1; - - protected List<Request> requests = new ArrayList<Request>(); - - /** - * HTTPConnection constructor comment. - * - * @param monitor a monitor - */ - public HTTPConnection(IMonitor monitor) { - super(); - this.monitor = monitor; - Trace.trace(Trace.PARSING, "TCP/IP monitor connection opened " + monitor); - } - - /** - * Add a request. - * - * @param b the request data - * @param isNew true if new - */ - public void addRequest(byte[] b, boolean isNew) { - if (isNew) - req ++; - HTTPRequest request = (HTTPRequest) getRequestResponse(req); - request.addToRequest(b); - } - - /** - * Add a response. - * - * @param b the response data - * @param isNew true if new - */ - public void addResponse(byte[] b, boolean isNew) { - if (isNew) - resp ++; - HTTPRequest request = (HTTPRequest) getRequestResponse(resp); - request.addToResponse(b); - } - - /** - * Add a property. - * - * @param key - * @param value - */ - public void addProperty(String key, Object value) { - Request request = getRequestResponse(req); - request.setProperty(key, value); - } - - /** - * Get the request. - * - * @param isRequest - * @return the request - */ - public Request getRequestResponse(boolean isRequest) { - if (isRequest) - return getRequestResponse(req); - - return getRequestResponse(resp); - } - - /** - * - */ - protected Request getRequestResponse(int i) { - synchronized (this) { - while (i >= requests.size()) { - Request request = new HTTPRequest((Monitor) monitor, monitor.getLocalPort(), monitor.getRemoteHost(), monitor.getRemotePort()); - requests.add(request); - return request; - } - return requests.get(i); - } - } - - /** - * Set the title. - * - * @param title the title - * @param isNew boolean - */ - public void setLabel(String title, boolean isNew) { - if (isNew) - req ++; - HTTPRequest request = (HTTPRequest) getRequestResponse(req); - request.setName(title); - } -} diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPProtocolAdapter.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPProtocolAdapter.java deleted file mode 100644 index 7c24cfedb..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPProtocolAdapter.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import java.io.IOException; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.wst.internet.monitor.core.internal.Connection; -import org.eclipse.wst.internet.monitor.core.internal.ProtocolAdapterDelegate; -import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor; -/** - * - */ -public class HTTPProtocolAdapter extends ProtocolAdapterDelegate { - protected Map<IMonitor, Connection> map = new HashMap<IMonitor, Connection>(); - - /** - * @see ProtocolAdapterDelegate#connect(IMonitor, Socket, Socket) - */ - public void connect(IMonitor monitor, Socket in, Socket out) throws IOException { - Connection conn2 = new Connection(in, out); - map.put(monitor, conn2); - HTTPConnection conn = new HTTPConnection(monitor); - HTTPThread request = new HTTPThread(conn2, in.getInputStream(), out.getOutputStream(), conn, true, monitor.getRemoteHost(), monitor.getRemotePort()); - HTTPThread response = new HTTPThread(conn2, out.getInputStream(), in.getOutputStream(), conn, false, "localhost", monitor.getLocalPort(), request); - request.start(); - response.start(); - } - - /** - * @see ProtocolAdapterDelegate#disconnect(IMonitor) - */ - public void disconnect(IMonitor monitor) throws IOException { - try { - Connection conn = map.get(monitor); - if (conn != null) - conn.close(); - } catch (Exception e) { - // ignore - } - } -} diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPRequest.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPRequest.java deleted file mode 100644 index 83e1655b2..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPRequest.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import org.eclipse.wst.internet.monitor.core.internal.IProtocolAdapter; -import org.eclipse.wst.internet.monitor.core.internal.Monitor; -import org.eclipse.wst.internet.monitor.core.internal.provisional.Request; -/** - * - */ -public class HTTPRequest extends Request { - protected static final String HTTP_REQUEST_HEADER = "request-header"; - protected static final String HTTP_RESPONSE_HEADER = "response-header"; - - protected static final String HTTP_REQUEST_BODY = "request-body"; - protected static final String HTTP_RESPONSE_BODY = "response-body"; - - protected static final byte[] EMPTY = new byte[0]; - - /** - * Create an HTTPRequest. - * - * @param monitor - * @param localPort - * @param remoteHost - * @param remotePort - */ - public HTTPRequest(Monitor monitor, int localPort, String remoteHost, int remotePort) { - super(monitor, IProtocolAdapter.HTTP_PROTOCOL_ID, localPort, remoteHost, remotePort); - } - - /** - * @see Request#getRequest(int) - */ - public byte[] getRequest(int type2) { - if (type2 == ALL) - return request; - else if (type2 == TRANSPORT) - return getRequestHeader(); - else - return getRequestContent(); - } - - /** - * @see Request#getResponse(int) - */ - public byte[] getResponse(int type2) { - if (type2 == ALL) - return response; - else if (type2 == TRANSPORT) - return getResponseHeader(); - else - return getResponseContent(); - } - - protected byte[] getRequestHeader() { - Object obj = getProperty(HTTP_REQUEST_HEADER); - if (obj == null || !(obj instanceof byte[])) - return null; - return (byte[]) obj; - } - - protected byte[] getRequestContent() { - Object obj = getProperty(HTTP_REQUEST_BODY); - if (obj == null || !(obj instanceof byte[])) - return null; - return (byte[]) obj; - } - - protected byte[] getResponseHeader() { - Object obj = getProperty(HTTP_RESPONSE_HEADER); - if (obj == null || !(obj instanceof byte[])) - return null; - return (byte[]) obj; - } - - protected byte[] getResponseContent() { - Object obj = getProperty(HTTP_RESPONSE_BODY); - if (obj == null || !(obj instanceof byte[])) - return null; - return (byte[]) obj; - } - - protected void setName(String n) { - super.setName(n); - } -} diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPThread.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPThread.java deleted file mode 100644 index f9d6b92d2..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/HTTPThread.java +++ /dev/null @@ -1,694 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import java.io.*; -import org.eclipse.wst.internet.monitor.core.internal.Connection; -import org.eclipse.wst.internet.monitor.core.internal.Messages; -import org.eclipse.wst.internet.monitor.core.internal.Trace; -import org.eclipse.wst.internet.monitor.core.internal.provisional.Request; -/** - * Monitor server I/O thread. - */ -public class HTTPThread extends Thread { - private static final int BUFFER = 2048; - private static final byte CR = (byte) '\r'; - private static final byte LF = (byte) '\n'; - protected static int threadCount = 0; - - private byte[] readBuffer = new byte[BUFFER]; - - // buffer and index - protected byte[] buffer = new byte[0]; - protected int bufferIndex = 0; - - protected InputStream in; - protected OutputStream out; - protected HTTPConnection conn; - protected boolean isRequest; - protected Connection conn2; - - protected HTTPThread request; - protected boolean isWaiting; - - // user to translate the Host: header - protected String host; - protected int port; - - protected int contentLength = -1; - protected byte transferEncoding = -1; - protected String responseType = null; - protected boolean connectionKeepAlive = false; - protected boolean connectionClose = false; - - protected static final String[] ENCODING_STRING = new String[] { - "chunked", "identity", "gzip", "compressed", "deflate"}; - - protected static final byte ENCODING_CHUNKED = 0; - protected static final byte ENCODING_IDENTITY = 1; - protected static final byte ENCODING_GZIP = 2; - protected static final byte ENCODING_COMPRESSED = 3; - protected static final byte ENCODING_DEFLATE = 4; - -/* change: -Referer: http://localhost:8081/index.html -Host: localhost:8081 -*/ -/* The Connection header has the following grammar: - - Connection = "Connection" ":" 1#(connection-token) - connection-token = token - - HTTP/1.1 proxies MUST parse the Connection header field before a - message is forwarded and, for each connection-token in this field, - remove any header field(s) from the message with the same name as the - connection-token. */ - - /** - * Create a new HTTP thread. - * - * @param conn2 - * @param in - * @param out - * @param conn - * @param isRequest - * @param host - * @param port - */ - public HTTPThread(Connection conn2, InputStream in, OutputStream out, HTTPConnection conn, boolean isRequest, String host, int port) { - super("TCP/IP Monitor HTTP Connection"); - this.conn2 = conn2; - this.in = in; - this.out = out; - this.conn = conn; - this.isRequest = isRequest; - this.host = host; - this.port = port; - - setName("HTTP (" + host + ":" + port + ") " + (isRequest ? "REQUEST" : "RESPONSE") + " " + (threadCount++)); - setPriority(Thread.NORM_PRIORITY + 1); - setDaemon(true); - - Trace.trace(Trace.PARSING, "Started: " + this); - } - - /** - * Create a new HTTP thread. - * - * @param conn2 - * @param in - * @param out - * @param conn - * @param isRequest - * @param host - * @param port - * @param request - */ - public HTTPThread(Connection conn2, InputStream in, OutputStream out, HTTPConnection conn, boolean isRequest, String host, int port, HTTPThread request) { - this(conn2, in, out, conn, isRequest, host, port); - - this.request = request; - } - - /** - * Add a line feed to the end of the byte array. - * @return byte[] - * @param b byte[] - */ - protected static byte[] convert(byte[] b) { - if (b == null || b.length == 0) - return b; - - int size = b.length; - byte[] x = new byte[size + 2]; - System.arraycopy(b, 0, x, 0, size); - x[size] = (byte) '\r'; // CR - x[size + 1] = (byte) '\n'; // LF - return x; - } - - /** - * Read more data into the buffer. - */ - protected void fillBuffer() throws IOException { - int n = in.read(readBuffer); - - if (n <= 0) - throw new IOException("End of input"); - - // add to full buffer - int len = buffer.length - bufferIndex; - if (len < 0) - len = 0; - byte[] x = new byte[n + len]; - System.arraycopy(buffer, bufferIndex, x, 0, len); - System.arraycopy(readBuffer, 0, x, len, n); - bufferIndex = 0; - buffer = x; - } - - /** - * Returns the first location of a CRLF. - * - * @return int - */ - protected int getFirstCRLF() { - int size = buffer.length; - int i = bufferIndex + 1; - while (i < size) { - if (buffer[i - 1] == CR && buffer[i] == LF) - return i; - i++; - } - return -1; - } - - /** - * Output the given bytes. - * @param b byte[] - */ - protected void outputBytes(byte[] b, boolean isNew) throws IOException { - out.write(b); - if (isRequest) - conn.addRequest(b, isNew); - else - conn.addResponse(b, isNew); - } - - /** - * Parse the HTTP body. - * - * @throws IOException - */ - public void parseBody() throws IOException { - Trace.trace(Trace.PARSING, "Parsing body for: " + this); - - if (responseType != null && ("204".equals(responseType) || "304".equals(responseType))) { - setHTTPBody(new byte[0]); - return; - } - - if (isRequest) { - if (contentLength != -1) { - if (contentLength < 1024 * 1024) { // 1Mb - byte[] b = readBytes(contentLength); - out.write(b); - conn.addRequest(b, false); - setHTTPBody(b); - } else { - byte[] b = removeFromBuffer(Math.min(bufferIndex, contentLength)); - int bytesLeft = contentLength - b.length; - out.write(b); - - int n = 0; - while (bytesLeft > 0) { - n = in.read(readBuffer); - bytesLeft -= n; - out.write(readBuffer, 0, n); - } - - b = Messages.errorContentSize.getBytes(); - conn.addRequest(b, false); - setHTTPBody(b); - } - } else if (transferEncoding != -1 && transferEncoding != ENCODING_IDENTITY) { - parseChunk(); - } - - Trace.trace(Trace.PARSING, "Done parsing request body for: " + this); - return; - } - - // just return body for HTTP 1.0 responses - if (!isRequest && !connectionKeepAlive && contentLength == -1 && transferEncoding == -1) { - Trace.trace(Trace.PARSING, "Assuming HTTP 1.0 for: " + this); - int n = buffer.length - bufferIndex; - byte[] b = readBytes(n); - byte[] body = new byte[0]; - while (n >= 0) { - Trace.trace(Trace.PARSING, "Bytes read: " + n + " " + this); - if (b != null && n > 0) { - byte[] x = null; - if (n == b.length) - x = b; - else { - x = new byte[n]; - System.arraycopy(b, 0, x, 0, n); - } - outputBytes(x, false); - - // copy to HTTP body - byte[] temp = new byte[body.length + x.length]; - System.arraycopy(body, 0, temp, 0, body.length); - System.arraycopy(x, 0, temp, body.length, x.length); - body = temp; - } - if (b == null || b.length < BUFFER) - b = new byte[BUFFER]; - n = in.read(b); - Thread.yield(); - } - out.flush(); - setHTTPBody(body); - return; - } - - // spec 4.4.1 - if (responseType != null && responseType.startsWith("1")) { - setHTTPBody(new byte[0]); - return; - } - - // spec 4.4.2 - if (transferEncoding != -1 && transferEncoding != ENCODING_IDENTITY) { - parseChunk(); - return; - } - - // spec 4.4.3 - if (contentLength != -1) { - if (contentLength < 1024 * 1024) { // 1Mb - byte[] b = readBytes(contentLength); - out.write(b); - if (isRequest) - conn.addRequest(b, false); - else - conn.addResponse(b, false); - setHTTPBody(b); - } else { - byte[] b = removeFromBuffer(Math.min(bufferIndex, contentLength)); - int bytesLeft = contentLength - b.length; - out.write(b); - - int n = 0; - while (bytesLeft > 0) { - n = in.read(readBuffer); - bytesLeft -= n; - out.write(readBuffer, 0, n); - } - - b = Messages.errorContentSize.getBytes(); - if (isRequest) - conn.addRequest(b, false); - else - conn.addResponse(b, false); - setHTTPBody(b); - } - return; - } - - // spec 4.4.4 (?) - - Trace.trace(Trace.PARSING, "Unknown body for: " + this); - } - - /** - * Parse an HTTP chunk. - * - * @throws IOException - */ - public void parseChunk() throws IOException { - Trace.trace(Trace.PARSING, "Parsing chunk for: " + this); - boolean done = false; - byte[] body = new byte[0]; - - while (!done) { - // read chunk size - byte[] b = readLine(); - - String s = new String(b); - int index = s.indexOf(" "); - int length = -1; - try { - if (index > 0) - s = s.substring(0, index); - length = Integer.parseInt(s.trim(), 16); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error chunk for: " + this, e); - } - - // output bytes - outputBytes(b, false); - - if (length <= 0) - done = true; - else { - // read and output chunk data plus CRLF - b = readBytes(length + 2); - outputBytes(b, false); - - // copy to HTTP body - byte[] temp = new byte[body.length + b.length - 2]; - System.arraycopy(body, 0, temp, 0, body.length); - System.arraycopy(b, 0, temp, body.length, b.length - 2); - body = temp; - } - } - - // read trailer - byte[] b = readLine(); - while (b.length > 2) { - outputBytes(b, false); - b = readLine(); - } - - outputBytes(b, false); - setHTTPBody(body); - } - - /** - * Parse an HTTP header. - * - * @throws IOException - */ - public void parseHeader() throws IOException { - Trace.trace(Trace.PARSING, "Parsing header for: " + this); - - // read until first blank line - boolean isFirstLine = true; - boolean isNew = true; - - byte[] b = readLine(); - while (b.length > 5) { - Trace.trace(Trace.PARSING, "Parsing header line: '" + new String(b) + "'"); - - if (isFirstLine) { - String s = new String(b); - if (isRequest) { - setLabel(s); - isNew = false; - } - - if (!isRequest) { - int index1 = s.indexOf(' '); - int index2 = s.indexOf(' ', index1 + 1); - - try { - responseType = s.substring(index1 + 1, index2).trim(); - Trace.trace(Trace.PARSING, "Response Type: " + this + " " + responseType); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error parsing response type for: " + this, e); - } - if (responseType != null && responseType.equals("100")) { - outputBytes(b, isNew); - isNew = false; - - b = readLine(); - outputBytes(b, false); - - b = readLine(); - - index1 = s.indexOf(' '); - index2 = s.indexOf(' ', index1 + 1); - - try { - responseType = s.substring(index1 + 1, index2).trim(); - Trace.trace(Trace.PARSING, "Response Type: " + this + " " + responseType); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error parsing response type for: " + this, e); - } - } - } - isFirstLine = false; - } - - // translate - b = translateHeaderLine(b); - - outputBytes(b, isNew); - isNew = false; - - b = readLine(); - } - - Trace.trace(Trace.PARSING, "Parsing final header line: '" + new String(b) + "'"); - - outputBytes(b, false); - - Request rr = conn.getRequestResponse(isRequest); - Trace.trace(Trace.PARSING, "Setting header length: " + rr.getRequest(Request.ALL).length); - - setHTTPHeader(rr); - } - - /** - * Read bytes from the stream. - * @return byte[] - */ - protected byte[] readBytes(int n) throws IOException { - Trace.trace(Trace.PARSING, "readBytes() " + n + " for: " + this); - while (buffer.length - bufferIndex < n) - fillBuffer(); - - return removeFromBuffer(bufferIndex + n); - } - - /** - * Read and return the next full line. - * - * @return byte[] - */ - protected byte[] readLine() throws IOException { - Trace.trace(Trace.PARSING, "readLine() for: " + this); - - int n = getFirstCRLF(); - while (n < 0) { - fillBuffer(); - n = getFirstCRLF(); - } - return removeFromBuffer(n + 1); - } - - /** - * Remove data from the buffer up to the absolute index n. - * Return the data from between bufferIndex and n. - * - * @param n the bytes to remove - * @return a byte array - */ - protected byte[] removeFromBuffer(int n) { - // copy line out of buffer - byte[] b = new byte[n - bufferIndex]; - System.arraycopy(buffer, bufferIndex, b, 0, n - bufferIndex); - - if (buffer.length > BUFFER * 2 || bufferIndex > BUFFER) { - // remove line from buffer - int size = buffer.length; - byte[] x = new byte[size - n]; - System.arraycopy(buffer, n, x, 0, size - n); - buffer = x; - bufferIndex = 0; - } else - bufferIndex = n; - - return b; - } - - /** - * Listen for input, save it, and pass to the output stream. - * Philosophy: Read a single line separately and translate. - * When blank line is reached, just pass all other data through. - */ - public void run() { - try { - try { - while (true) { - contentLength = -1; - transferEncoding = -1; - connectionKeepAlive = false; - connectionClose = false; - - parseHeader(); - parseBody(); - - if (isRequest && connectionKeepAlive) - waitForResponse(); - - //Request r = conn.getRequestResponse(true); - //r.fireChangedEvent(); - - Trace.trace(Trace.PARSING, "Done HTTP request for " + this + " " + connectionKeepAlive); - if (!isRequest && (!request.connectionKeepAlive || connectionClose)) { - conn2.close(); - if (request.connectionKeepAlive && connectionClose) - request.connectionKeepAlive = false; - notifyRequest(); - break; - } - - if (!isRequest) - notifyRequest(); - - Thread.yield(); - } - } catch (IOException e) { - // reached end of input - Trace.trace(Trace.PARSING, "End of buffer for: " + this, e); - if (!isRequest) { - try { - request.connectionKeepAlive = false; - request.conn2.close(); - notifyRequest(); - } catch (Exception ex) { - Trace.trace(Trace.PARSING, "Error closing request in response to error: " + this, e); - } - } - } - - // send rest of buffer - out.write(buffer, bufferIndex, buffer.length - bufferIndex); - out.flush(); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error in: " + this, e); - } - //if (!isRequest) - // conn2.close(); - - Trace.trace(Trace.PARSING, "Closing thread " + this); - } - - /** - * Sets the title of the call. - * - * @param s java.lang.String - */ - protected void setLabel(String s) { - try { - int index1 = s.indexOf(' '); - if (index1 < 0 || index1 > 15) - return; - int index2 = s.indexOf(' ', index1 + 1); - if (index2 < 0) - return; - - conn.setLabel(s.substring(index1 + 1, index2), true); - } catch (Exception e) { - // ignore - } - } - - /** - * Translate the header line. - * - * @return byte[] - * @param b byte[] - */ - protected byte[] translateHeaderLine(byte[] b) { - String s = new String(b); - - if (isRequest && s.startsWith("Host: ")) { - String t = "Host: " + host; - if (port != 80) - t += ":" + port; - return convert(t.getBytes()); - } else if (s.startsWith("Content-Length: ")) { - try { - contentLength = Integer.parseInt(s.substring(16).trim()); - Trace.trace(Trace.PARSING, "Content length: " + this + " " + contentLength); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Content length error", e); - } - } else if (s.startsWith("Connection: ")) { - try { - String t = s.substring(11).trim(); - if (t.equalsIgnoreCase("Keep-Alive")) - connectionKeepAlive = true; - // response contains "Connection: close" header - // close connection to the client even if "keepalive" had been requested - // we can't just reset request.keepAlive - it's used as indicator whether - // the request thread is (going to) wait for the response thread - // (and must be notified (only then)), - // so we have to let it alone - if (t.equalsIgnoreCase("close")) - connectionClose = true; - Trace.trace(Trace.PARSING, "Keep alive: " + connectionKeepAlive); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error getting Connection: from header", e); - } - } else if (s.startsWith("Transfer-Encoding: ")) { - String t = s.substring(19).trim(); - int size = ENCODING_STRING.length; - for (int i = 0; i < size; i++) { - if (ENCODING_STRING[i].equalsIgnoreCase(t)) { - transferEncoding = (byte) i; - Trace.trace(Trace.PARSING, "Transfer encoding: " + ENCODING_STRING[i]); - } - } - } - - return b; - } - - protected void close() { - try { - Trace.trace(Trace.PARSING, "Closing: " + this); - out.close(); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error closing connection " + this, e); - } - } - - protected void waitForResponse() { - Trace.trace(Trace.PARSING, "Waiting for response " + this); - synchronized (this) { - try { - isWaiting = true; - wait(); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error in waitForResponse() " + this, e); - } - isWaiting = false; - } - Trace.trace(Trace.PARSING, "Done waiting for response " + this); - } - - protected void notifyRequest() { - Trace.trace(Trace.PARSING, "Notifying request " + this); - while (request.connectionKeepAlive && !request.isWaiting) { - Trace.trace(Trace.PARSING, "Waiting for request " + this); - try { - Thread.sleep(100); - } catch (Exception e) { - // ignore - } - } - synchronized (request) { - try { - request.notify(); - } catch (Exception e) { - Trace.trace(Trace.PARSING, "Error in notifyRequest() " + this, e); - } - } - Trace.trace(Trace.PARSING, "Done notifying request " + this); - } - - protected void setHTTPHeader(Request rr) { - if (isRequest) { - byte[] b = rr.getRequest(Request.ALL); - byte[] h = new byte[b.length]; - System.arraycopy(b, 0, h, 0, b.length); - rr.setProperty(HTTPRequest.HTTP_REQUEST_HEADER, h); - } else { - byte[] b = rr.getResponse(Request.ALL); - byte[] h = new byte[b.length]; - System.arraycopy(b, 0, h, 0, b.length); - rr.setProperty(HTTPRequest.HTTP_RESPONSE_HEADER, h); - } - } - - protected void setHTTPBody(byte[] b) { - Request rr = conn.getRequestResponse(isRequest); - if (isRequest) - rr.setProperty(HTTPRequest.HTTP_REQUEST_BODY, b); - else - rr.setProperty(HTTPRequest.HTTP_RESPONSE_BODY, b); - } -} diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPConnection.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPConnection.java deleted file mode 100644 index c9e344117..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPConnection.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import org.eclipse.wst.internet.monitor.core.internal.provisional.Request; -/** - * A resend HTTP connection wraps an HTTP connection to send an existing request. - */ -public class ResendHTTPConnection extends HTTPConnection { - protected Request existingRequest; - - /** - * Create a new resend connection. - * - * @param request - */ - public ResendHTTPConnection(Request request) { - super(null); - this.existingRequest = request; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.internet.monitor.core.internal.http.HTTPConnection#getRequestResponse(int) - */ - protected Request getRequestResponse(int i) { - return existingRequest; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPRequest.java b/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPRequest.java deleted file mode 100644 index 2a48859dd..000000000 --- a/plugins/org.eclipse.wst.internet.monitor.core/monitorcore/org/eclipse/wst/internet/monitor/core/internal/http/ResendHTTPRequest.java +++ /dev/null @@ -1,148 +0,0 @@ -/********************************************************************** - * Copyright (c) 2004, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - Initial API and implementation - **********************************************************************/ -package org.eclipse.wst.internet.monitor.core.internal.http; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.Socket; - -import org.eclipse.wst.internet.monitor.core.internal.Connection; -import org.eclipse.wst.internet.monitor.core.internal.Monitor; -import org.eclipse.wst.internet.monitor.core.internal.SocketWrapper; -import org.eclipse.wst.internet.monitor.core.internal.provisional.Request; -/** - * Wraps an existing request to create an HTTP request that can be sent. The - * response is ignored. Only the request is important in this case. - */ -public class ResendHTTPRequest extends HTTPRequest { - private boolean sent = false; - - private byte[] header; - - private byte[] content; - - private Request originalRequest = null; - - /** - * Constructor. - * - * @param monitor - * @param req the request that is to be resent. - */ - public ResendHTTPRequest(Monitor monitor, Request req) { - super(monitor, req.getLocalPort(), req.getRemoteHost(), req.getRemotePort()); - setProperty(HTTP_REQUEST_HEADER, req.getProperty(HTTP_REQUEST_HEADER)); - setProperty(HTTP_REQUEST_BODY, req.getProperty(HTTP_REQUEST_BODY)); - header = req.getRequest(TRANSPORT); - content = req.getRequest(CONTENT); - request = req.getRequest(ALL); - name = req.getName(); - this.originalRequest = req; - } - - /** - * Send the request. - */ - public void sendRequest() { - try { - Socket inSocket = new SocketWrapper(new ByteArrayInputStream(request)); - Socket outSocket = new Socket(remoteHost, remotePort); - //Connection conn = new Connection(inSocket, outSocket); - //TCPIPThread requestThread = new TCPIPThread(conn, this, in, - // outSocket.getOutputStream(), true); - //requestThread.start(); - //new TCPIPThread(conn, this, outSocket.getInputStream(), - // inSocket.getOutputStream(), false).start(); - Connection conn2 = new Connection(inSocket, outSocket); - ResendHTTPConnection conn = new ResendHTTPConnection(this); - - HTTPThread request2 = new HTTPThread(conn2, inSocket.getInputStream(), - outSocket.getOutputStream(), conn, true, remoteHost, remotePort); - HTTPThread response2 = new HTTPThread(conn2, outSocket.getInputStream(), - inSocket.getOutputStream(), conn, false, "localhost", localPort, request2); - request2.start(); - response2.start(); - } catch (IOException e) { - response = ("Unable to resend to server.\n" + e).getBytes(); - } - sent = true; - } - - /** (non-Javadoc) - * @see Request#addToRequest(byte[]) - */ - public void addToRequest(byte[] addRequest) { - // Don't want to add to the request as we already have the request. - } - - /** - * Returns <code>true</code> if the request has been sent. - * - * @return <code>true</code> if the request has been sent, and <code>false</code> - * otherwise - */ - public boolean hasBeenSent() { - return sent; - } - - /** - * Set the request. - * - * @param request - * @param type - */ - public void setRequest(byte[] request, int type) { - if (request == null) - request = new byte[0]; - if (type == TRANSPORT) - header = request; - else if (type == CONTENT) - content = request; - - int length = 0; - int headerLength = 0; - if (header != null) { - length += header.length; - headerLength = length; - } - if (content != null) - length += content.length; - byte[] newRequest = new byte[length]; - if (header != null) - System.arraycopy(header, 0, newRequest, 0, header.length); - if (content != null) - System.arraycopy(content, 0, newRequest, headerLength, content.length); - super.setRequest(newRequest); - } - - /** (non-Javadoc) - * @see HTTPRequest#getRequestContent() - */ - protected byte[] getRequestContent() { - return content; - } - - /** (non-Javadoc) - * @see HTTPRequest#getRequestHeader() - */ - protected byte[] getRequestHeader() { - return header; - } - - /** - * Returns the original request. - * - * @return the original request - */ - public Request getOriginalRequest() { - return originalRequest; - } -}
\ No newline at end of file |