inital plugin from webtools project
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.core / src / net / sourceforge / phpdt / monitor / core / internal / http / HTTPRequest.java
1 /**********************************************************************
2  * Copyright (c) 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *    IBM - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.core.internal.http;
12
13 import net.sourceforge.phpdt.monitor.core.MonitorCore;
14 import net.sourceforge.phpdt.monitor.core.internal.Request;
15
16 /**
17  * 
18  */
19 public class HTTPRequest extends Request {
20         protected static final String HTTP_REQUEST_HEADER = "request-header";
21         protected static final String HTTP_RESPONSE_HEADER = "response-header";
22
23         protected static final String HTTP_REQUEST_BODY = "request-body";
24         protected static final String HTTP_RESPONSE_BODY = "response-body";
25         
26         protected static final byte[] EMPTY = new byte[0];
27
28         /**
29          * HTTPRequestResponse constructor comment.
30          */
31         public HTTPRequest(int localPort, String remoteHost, int remotePort) {
32                 super(MonitorCore.getProtocolAdapter(MonitorCore.HTTP_PROTOCOL_ID), localPort, remoteHost, remotePort);
33         }
34         
35         public byte[] getRequest(byte type2) {
36                 if (type2 == ALL)
37                         return request;
38                 else if (type2 == TRANSPORT)
39                         return getRequestHeader();
40                 else
41                         return getRequestContent();
42         }
43         
44         public byte[] getResponse(byte type2) {
45                 if (type2 == ALL)
46                         return response;
47                 else if (type2 == TRANSPORT)
48                         return getResponseHeader();
49                 else
50                         return getResponseContent();
51         }
52         
53         protected byte[] getRequestHeader() {
54                 Object obj = getObjectProperty(HTTP_REQUEST_HEADER);
55                 if (obj == null || !(obj instanceof byte[]))
56                         return null;
57                 else
58                         return (byte[]) obj;
59         }
60         
61         protected byte[] getRequestContent() {
62                 Object obj = getObjectProperty(HTTP_REQUEST_BODY);
63                 if (obj == null || !(obj instanceof byte[]))
64                         return null;
65                 else
66                         return (byte[]) obj;
67         }
68         
69         protected byte[] getResponseHeader() {
70                 Object obj = getObjectProperty(HTTP_RESPONSE_HEADER);
71                 if (obj == null || !(obj instanceof byte[]))
72                         return null;
73                 else
74                         return (byte[]) obj;
75         }
76         
77         protected byte[] getResponseContent() {
78                 Object obj = getObjectProperty(HTTP_RESPONSE_BODY);
79                 if (obj == null || !(obj instanceof byte[]))
80                         return null;
81                 else
82                         return (byte[]) obj;
83         }
84 }