001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: HttpRequestImpl.java 9049 2007-09-13 18:53:25Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.component.http.client;
025:
026: import java.util.HashMap;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Map;
030: import java.util.Vector;
031:
032: import javax.xml.transform.Source;
033:
034: import com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpHeader;
035: import com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest;
036:
037: public class HttpRequestImpl implements IHttpRequest {
038:
039: private byte method;
040: private String url;
041: private Source body;
042: private HashMap<String, IHttpHeader> headers;
043:
044: public HttpRequestImpl() {
045: method = IHttpRequest.METHOD_POST;
046: body = null;
047: headers = new HashMap<String, IHttpHeader>();
048: }
049:
050: /* (non-Javadoc)
051: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#setMethod(byte)
052: */
053: public void setMethod(byte method) {
054: this .method = method;
055: }
056:
057: /* (non-Javadoc)
058: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#getMethod()
059: */
060: public byte getMethod() {
061: return method;
062: }
063:
064: /* (non-Javadoc)
065: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#getURL()
066: */
067: public String getURL() {
068: return url;
069: }
070:
071: /* (non-Javadoc)
072: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#setURL(java.lang.String)
073: */
074: public void setURL(String url) {
075: this .url = url;
076: }
077:
078: /* (non-Javadoc)
079: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#setBody(javax.xml.transform.Source)
080: */
081: public void setBody(Source body) {
082: this .body = body;
083: }
084:
085: /* (non-Javadoc)
086: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#getBody()
087: */
088: public Source getBody() {
089: return body;
090: }
091:
092: public IHttpHeader createHeader(String name, String value) {
093: HttpHeaderImpl header = new HttpHeaderImpl();
094: header.setName(name);
095: header.setValue(value);
096: headers.put(name, header);
097: return header;
098: }
099:
100: /* (non-Javadoc)
101: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#addHeader(com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpHeader)
102: */
103: public void addHeader(IHttpHeader httpHeader) {
104: headers.put(httpHeader.getName(), httpHeader);
105: }
106:
107: /* (non-Javadoc)
108: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#clearHeaders()
109: */
110: public void clearHeaders() {
111: headers.clear();
112: }
113:
114: /* (non-Javadoc)
115: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#getHeaders()
116: */
117: public List<IHttpHeader> getHeaders() {
118: Vector<IHttpHeader> list = new Vector<IHttpHeader>();
119: for (Iterator iter = headers.entrySet().iterator(); iter
120: .hasNext();) {
121: Map.Entry entry = (Map.Entry) iter.next();
122: IHttpHeader header = (IHttpHeader) entry.getValue();
123: list.add(header);
124: }
125: return list;
126: }
127:
128: /* (non-Javadoc)
129: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#setHeaders(java.util.List)
130: */
131: public void setHeaders(List<IHttpHeader> httpHeaders) {
132: headers.clear();
133: for (Iterator iter = httpHeaders.iterator(); iter.hasNext();) {
134: IHttpHeader header = (IHttpHeader) iter.next();
135: addHeader(header);
136: }
137: }
138:
139: }
|