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: HttpResponseImpl.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.IHttpResponse;
036:
037: public class HttpResponseImpl implements IHttpResponse {
038:
039: private int statusCode;
040: private String statusDescription;
041: private Source body;
042: private HashMap<String, IHttpHeader> headers;
043:
044: public HttpResponseImpl() {
045: headers = new HashMap<String, IHttpHeader>();
046: }
047:
048: /* (non-Javadoc)
049: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#setStatusCode(int)
050: */
051: public void setStatusCode(int statusCode) {
052: this .statusCode = statusCode;
053: }
054:
055: /* (non-Javadoc)
056: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#getStatusCode()
057: */
058: public int getStatusCode() {
059: return statusCode;
060: }
061:
062: /* (non-Javadoc)
063: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#setStatusDescription()
064: */
065: public void setStatusDescription(String statusDescription) {
066: this .statusDescription = statusDescription;
067: }
068:
069: /* (non-Javadoc)
070: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#getStatusDescription()
071: */
072: public String getStatusDescription() {
073: return statusDescription;
074: }
075:
076: /* (non-Javadoc)
077: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#setBody(javax.xml.transform.Source)
078: */
079: public void setBody(Source body) {
080: this .body = body;
081: }
082:
083: /* (non-Javadoc)
084: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpResponse#getBody()
085: */
086: public Source getBody() {
087: return body;
088: }
089:
090: public IHttpHeader createHeader(String name, String value) {
091: HttpHeaderImpl header = new HttpHeaderImpl();
092: header.setName(name);
093: header.setValue(value);
094: headers.put(name, header);
095: return header;
096: }
097:
098: /* (non-Javadoc)
099: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#addHeader(com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpHeader)
100: */
101: public void addHeader(IHttpHeader httpHeader) {
102: headers.put(httpHeader.getName(), httpHeader);
103: }
104:
105: /* (non-Javadoc)
106: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#clearHeaders()
107: */
108: public void clearHeaders() {
109: headers.clear();
110: }
111:
112: /* (non-Javadoc)
113: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#getHeaders()
114: */
115: public List<IHttpHeader> getHeaders() {
116: Vector<IHttpHeader> list = new Vector<IHttpHeader>();
117: for (Iterator iter = headers.entrySet().iterator(); iter
118: .hasNext();) {
119: Map.Entry entry = (Map.Entry) iter.next();
120: IHttpHeader header = (IHttpHeader) entry.getValue();
121: list.add(header);
122: }
123: return list;
124: }
125:
126: /* (non-Javadoc)
127: * @see com.bostechcorp.cbesb.runtime.ccsl.lib.IHttpRequest#setHeaders(java.util.List)
128: */
129: public void setHeaders(List<IHttpHeader> httpHeaders) {
130: headers.clear();
131: for (Iterator iter = httpHeaders.iterator(); iter.hasNext();) {
132: IHttpHeader header = (IHttpHeader) iter.next();
133: addHeader(header);
134: }
135: }
136:
137: }
|