001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.ws.server;
020:
021: import java.security.Principal;
022: import java.util.Enumeration;
023: import java.util.Locale;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpSession;
027:
028: import com.nabhinc.core.WebServiceRequest;
029: import com.nabhinc.core.WebServiceSession;
030:
031: /**
032: * Implementation of <code>WebServiceRequest</code> interface for
033: * servlet containers.
034: *
035: * @author Padmanabh Dabke
036: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
037: */
038: public class HTTPWebServiceRequest implements WebServiceRequest {
039:
040: private HttpServletRequest hwsrHttpRequest = null;
041: private WebServiceSession hwsrSession = null;
042:
043: /**
044: * Empty constructor
045: */
046: public HTTPWebServiceRequest() {
047: }
048:
049: /**
050: * Creates a HTTPWebService request object that delegates
051: * method invocations to supplied HTTP request.
052: * @param req Associated HTTP request
053: */
054: public HTTPWebServiceRequest(HttpServletRequest req) {
055: hwsrHttpRequest = req;
056: }
057:
058: /* (non-Javadoc)
059: * @see com.nabhinc.ws.server.WebServiceRequest#getAttribute(java.lang.String)
060: */
061: public Object getAttribute(String name) {
062: return hwsrHttpRequest.getAttribute(name);
063: }
064:
065: /* (non-Javadoc)
066: * @see com.nabhinc.ws.server.WebServiceRequest#getAttributeNames()
067: */
068: public Enumeration getAttributeNames() {
069: return hwsrHttpRequest.getAttributeNames();
070: }
071:
072: /* (non-Javadoc)
073: * @see com.nabhinc.ws.server.WebServiceRequest#getRemoteAddr()
074: */
075: public String getRemoteAddr() {
076: return hwsrHttpRequest.getRemoteAddr();
077: }
078:
079: /* (non-Javadoc)
080: * @see com.nabhinc.ws.server.WebServiceRequest#getRemoteHost()
081: */
082: public String getRemoteHost() {
083: return hwsrHttpRequest.getRemoteHost();
084: }
085:
086: /* (non-Javadoc)
087: * @see com.nabhinc.ws.server.WebServiceRequest#setAttribute(java.lang.String, java.lang.Object)
088: */
089: public void setAttribute(String name, Object o) {
090: hwsrHttpRequest.setAttribute(name, o);
091:
092: }
093:
094: /* (non-Javadoc)
095: * @see com.nabhinc.ws.server.WebServiceRequest#removeAttribute(java.lang.String)
096: */
097: public void removeAttribute(String name) {
098: hwsrHttpRequest.removeAttribute(name);
099:
100: }
101:
102: /* (non-Javadoc)
103: * @see com.nabhinc.ws.server.WebServiceRequest#getLocale()
104: */
105: public Locale getLocale() {
106: return hwsrHttpRequest.getLocale();
107: }
108:
109: /* (non-Javadoc)
110: * @see com.nabhinc.ws.server.WebServiceRequest#getLocales()
111: */
112: public Enumeration getLocales() {
113: return hwsrHttpRequest.getLocales();
114: }
115:
116: /* (non-Javadoc)
117: * @see com.nabhinc.ws.server.WebServiceRequest#isSecure()
118: */
119: public boolean isSecure() {
120: return hwsrHttpRequest.isSecure();
121: }
122:
123: /* (non-Javadoc)
124: * @see com.nabhinc.ws.server.WebServiceRequest#getAuthType()
125: */
126: public String getAuthType() {
127: return hwsrHttpRequest.getAuthType();
128: }
129:
130: /* (non-Javadoc)
131: * @see com.nabhinc.ws.server.WebServiceRequest#getRemoteUser()
132: */
133: public String getRemoteUser() {
134: return hwsrHttpRequest.getRemoteUser();
135: }
136:
137: /* (non-Javadoc)
138: * @see com.nabhinc.ws.server.WebServiceRequest#isUserInRole(java.lang.String)
139: */
140: public boolean isUserInRole(String role) {
141: return hwsrHttpRequest.isUserInRole(role);
142: }
143:
144: /* (non-Javadoc)
145: * @see com.nabhinc.ws.server.WebServiceRequest#getUserPrincipal()
146: */
147: public Principal getUserPrincipal() {
148: return hwsrHttpRequest.getUserPrincipal();
149: }
150:
151: /* (non-Javadoc)
152: * @see com.nabhinc.ws.server.WebServiceRequest#getSession(boolean)
153: */
154: public WebServiceSession getSession(boolean create) {
155: if (hwsrSession == null) {
156: HttpSession session = hwsrHttpRequest.getSession(create);
157: if (session != null) {
158: hwsrSession = new HTTPWebServiceSession(session);
159: }
160: }
161: return hwsrSession;
162: }
163:
164: /* (non-Javadoc)
165: * @see com.nabhinc.ws.server.WebServiceRequest#getSession()
166: */
167: public WebServiceSession getSession() {
168: if (hwsrSession == null) {
169: HttpSession session = hwsrHttpRequest.getSession();
170: if (session != null) {
171: hwsrSession = new HTTPWebServiceSession(session);
172: }
173: }
174: return hwsrSession;
175: }
176:
177: /* (non-Javadoc)
178: * @see com.nabhinc.ws.server.WebServiceRequest#getDateHeader(java.lang.String)
179: */
180: public long getDateHeader(String name) {
181: return hwsrHttpRequest.getDateHeader(name);
182: }
183:
184: /* (non-Javadoc)
185: * @see com.nabhinc.ws.server.WebServiceRequest#getHeader(java.lang.String)
186: */
187: public String getHeader(String name) {
188: return hwsrHttpRequest.getHeader(name);
189: }
190:
191: /* (non-Javadoc)
192: * @see com.nabhinc.ws.server.WebServiceRequest#getHeaders(java.lang.String)
193: */
194: public Enumeration getHeaders(String name) {
195: return hwsrHttpRequest.getHeaders(name);
196: }
197:
198: /* (non-Javadoc)
199: * @see com.nabhinc.ws.server.WebServiceRequest#getHeaderNames()
200: */
201: public Enumeration getHeaderNames() {
202: return hwsrHttpRequest.getHeaderNames();
203: }
204:
205: /* (non-Javadoc)
206: * @see com.nabhinc.ws.server.WebServiceRequest#getIntHeader(java.lang.String)
207: */
208: public int getIntHeader(String name) {
209: return hwsrHttpRequest.getIntHeader(name);
210: }
211:
212: }
|