View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.presentation;
23  
24  import java.io.IOException;
25  import java.net.URL;
26  import java.util.Properties;
27  import javax.servlet.ServletContext;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  import org.miloss.fgsms.common.Constants.AuthMode;
31  import org.miloss.fgsms.services.interfaces.agentcallbackservice.RemoteAgentCallbackPort;
32  import org.miloss.fgsms.services.interfaces.automatedreportingservice.AutomatedReportingService;
33  import org.miloss.fgsms.services.interfaces.dataaccessservice.DataAccessService;
34  import org.miloss.fgsms.services.interfaces.policyconfiguration.PCS;
35  import org.miloss.fgsms.services.interfaces.reportingservice.ReportingService;
36  import org.miloss.fgsms.services.interfaces.status.OpStatusService;
37  import org.miloss.fgsms.services.interfaces.status.StatusService;
38  
39  /**
40   * Loads client proxy objects for the fgsms Web services using the
41   * configuration file settings. This class will use the current thread's context
42   * class loader to attempt to determine if we are running in a CXF or
43   * JbossWS-Native environment. If it cannot be determined, an exception is
44   * thrown. This class is similar to the factory pattern, however it is not
45   * explicitly configurable
46   *
47   * @since 6.2
48   * @author AO
49   */
50  public class ProxyLoader implements IProxyLoader {
51  
52      public static final String PROXY_LOADER_SESSION_KEY = "org.miloss.fgsms.proxyloader";
53  
54      public static ProxyLoader getInstance(ServletContext application) throws Exception {
55          Object attribute = application.getAttribute(PROXY_LOADER_SESSION_KEY);
56          if (attribute != null && attribute instanceof ProxyLoader) {
57              return (ProxyLoader) attribute;
58          }
59          ProxyLoader pl = new ProxyLoader(application);
60          application.setAttribute(PROXY_LOADER_SESSION_KEY, pl);
61          return pl;
62      }
63  
64      private ProxyLoader(ServletContext application) throws Exception {
65  
66          //     this.application = application;
67  //determine if we are in jbossws-native or cxf
68          //hooks for JbossWS Native
69          /*try {
70              Class c = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.ws.core.StubExt");
71              Class c2 = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.ws.extensions.security.jaxws.WSSecurityHandlerClient");
72              if (c != null && c2 != null) {
73                  object = new ProxyLoaderJbossWSNative(application);
74                  return;
75              }
76          } catch (ClassNotFoundException cnf) {
77          }*/
78  
79  
80          //hooks for JbossWS CXF
81          try {
82              Class<?> c = Thread.currentThread().getContextClassLoader().loadClass("org.apache.cxf.transport.http.HTTPConduit");
83              if (c != null) {
84                  object = new ProxyLoaderCXF(application);
85                  return;
86              }
87          } catch (ClassNotFoundException cnf) {
88          }
89          throw new ClassNotFoundException("Could not accurately determine if we are operating in the CXF of JbossWS-Native environment");
90  
91      }
92      IProxyLoader object;
93  
94      @Override
95      public AuthMode getAuthmode() {
96          return object.getAuthmode();
97      }
98  
99      @Override
100     public boolean uddiConfigured() {
101         return object.uddiConfigured();
102     }
103 
104 	
105     /**
106      * only used from the login page, returns a PCS client proxy that should
107      * only be used for authenticated the user
108      *
109      * @param application
110      * @param username
111      * @param password
112      * @return
113      */
114     @Override
115     public PCS GetPCSForUsernamePasswordLogin(ServletContext application, String username, String password) {
116         return object.GetPCSForUsernamePasswordLogin(application, username, password);
117     }
118 
119     @Override
120     public PCS GetPCS(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
121         return object.GetPCS(application, request, response);
122     }
123 
124     @Override
125     public DataAccessService GetDAS(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
126         return object.GetDAS(application, request, response);
127     }
128 
129     @Override
130     public ReportingService GetRS(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
131         return object.GetRS(application, request, response);
132     }
133 
134     @Override
135     public AutomatedReportingService GetARS(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
136         return object.GetARS(application, request, response);
137     }
138 
139     @Override
140     public StatusService GetSS(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
141         return object.GetSS(application, request, response);
142     }
143 
144     @Override
145     public UDDIConfig GetUDDIInquiryConfig(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
146         return object.GetUDDIInquiryConfig(application, request, response);
147     }
148 
149     @Override
150     public String getKeyStoreTrustStoreDirectory() {
151         return object.getKeyStoreTrustStoreDirectory();
152     }
153 
154     @Override
155     public Properties getRawConfiguration() {
156         return object.getRawConfiguration();
157     }
158 
159     @Override
160     public URL getRawConfigurationURL() {
161         return object.getRawConfigurationURL();
162     }
163 
164     @Override
165     public OpStatusService GetOpStat(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
166         return object.GetOpStat(application, request, response);
167     }
168 
169     @Override
170     public RemoteAgentCallbackPort GetAgentCallBack(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
171         return object.GetAgentCallBack(application, request, response);
172     }
173     
174         @Override
175     public OpStatusService GetAgentCallBackOpStat(ServletContext application, HttpServletRequest request, HttpServletResponse response) throws IOException {
176         return object.GetAgentCallBackOpStat(application, request, response);
177     }
178 
179     @Override
180     public boolean isSecure() {
181         return object.isSecure();
182     }
183 }