01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.http;
15:
16: import org.itsnat.core.http.ItsNatHttpServletRequest;
17: import org.itsnat.core.http.ItsNatHttpServlet;
18: import org.itsnat.core.http.ItsNatHttpSession;
19: import org.itsnat.impl.core.ItsNatServletContextImpl;
20: import org.itsnat.impl.core.ItsNatServletImpl;
21: import org.itsnat.impl.core.ItsNatServletRequestImpl;
22: import org.itsnat.impl.core.ItsNatSessionImpl;
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25: import javax.servlet.http.HttpSession;
26:
27: /**
28: *
29: * @author jmarranz
30: */
31: public class ItsNatHttpServletRequestImpl extends
32: ItsNatServletRequestImpl implements ItsNatHttpServletRequest {
33:
34: /**
35: * Creates a new instance of ItsNatHttpServletRequestImpl
36: */
37: public ItsNatHttpServletRequestImpl(ItsNatServletImpl servlet,
38: HttpServletRequest request) {
39: super (servlet, request);
40: }
41:
42: public ItsNatHttpSession getItsNatHttpSession() {
43: return getItsNatHttpSessionImpl();
44: }
45:
46: public ItsNatHttpSessionImpl getItsNatHttpSessionImpl() {
47: return (ItsNatHttpSessionImpl) itsnatSession;
48: }
49:
50: protected ItsNatSessionImpl getOrBuildItsNatSession() {
51: HttpServletRequest request = getHttpServletRequest();
52: HttpSession session = request.getSession();
53: synchronized (session) {
54: String attrName = "itsnat_session";
55: ItsNatHttpSessionImpl itsnatSession = (ItsNatHttpSessionImpl) session
56: .getAttribute(attrName);
57: if (itsnatSession == null) {
58: ItsNatServletContextImpl context = getItsNatServletContext();
59: String agent = request.getHeader("User-Agent");
60: itsnatSession = new ItsNatHttpSessionImpl(session,
61: context, agent);
62: session.setAttribute(attrName, itsnatSession);
63:
64: context.addItsNatSessionWeakList(itsnatSession); // útil para el control remoto
65: }
66: return itsnatSession;
67: }
68: }
69:
70: public HttpServletRequest getHttpServletRequest() {
71: return (HttpServletRequest) request;
72: }
73:
74: public ItsNatHttpServlet getItsNatHttpServlet() {
75: return getItsNatHttpServletImpl();
76: }
77:
78: public ItsNatHttpServletImpl getItsNatHttpServletImpl() {
79: return (ItsNatHttpServletImpl) itsNatServlet;
80: }
81:
82: public ItsNatHttpServletResponseImpl newItsNatHttpServletResponse(
83: HttpServletResponse response) {
84: return new ItsNatHttpServletResponseImpl(this , response);
85: }
86:
87: public String getServletURLInternal() {
88: String contextPath = getHttpServletRequest().getContextPath();
89: return contextPath
90: + "/"
91: + getItsNatHttpServletImpl().getServlet()
92: .getServletConfig().getServletName();
93: }
94: }
|