001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.plugin;
018:
019: import java.net.MalformedURLException;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.Map;
023: import java.util.Properties;
024:
025: import javax.xml.namespace.QName;
026:
027: import org.apache.commons.httpclient.HostConfiguration;
028: import org.apache.commons.httpclient.HttpClient;
029: import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
030: import org.apache.commons.httpclient.cookie.CookiePolicy;
031: import org.apache.commons.httpclient.params.HttpClientParams;
032: import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
033: import org.apache.commons.httpclient.params.HttpMethodParams;
034: import org.apache.commons.httpclient.params.HttpParams;
035: import org.kuali.rice.core.Core;
036: import org.kuali.rice.lifecycle.Lifecycle;
037: import org.kuali.rice.resourceloader.BaseResourceLoader;
038: import org.kuali.rice.resourceloader.ContextClassLoaderProxy;
039: import org.kuali.rice.resourceloader.ResourceLoader;
040: import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
041:
042: import edu.iu.uis.eden.KEWServiceLocator;
043: import edu.iu.uis.eden.SpringLoader;
044: import edu.iu.uis.eden.core.dependencylifecycles.SpringLifeCycle;
045: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
046: import edu.iu.uis.eden.messaging.HttpClientHelper;
047: import edu.iu.uis.eden.messaging.KEWHttpInvokerRequestExecutor;
048: import edu.iu.uis.eden.server.WorkflowDocumentActions;
049: import edu.iu.uis.eden.server.WorkflowUtility;
050:
051: /**
052: * Initializes and loads webservice resources for the Embedded plugin.
053: * Currently, the only 2 services which are exposed are the utility service and
054: * the document actions service.
055: *
056: * @author Eric Westfall
057: * @author rkirkend
058: */
059: public class WebserviceResourceLoader extends BaseResourceLoader {
060:
061: private Lifecycle springLifecycle = new SpringLifeCycle(
062: "WebClientBeans.xml");
063:
064: public WebserviceResourceLoader() {
065: super (new QName(Core.getCurrentContextConfig()
066: .getMessageEntity(), ResourceLoader.WEB_SERVICE_PLUGIN));
067: }
068:
069: @Override
070: public void start() throws Exception {
071: super .start();
072: springLifecycle.start();
073: }
074:
075: @Override
076: public void stop() throws Exception {
077: super .stop();
078: springLifecycle.stop();
079: }
080:
081: public Object getService(QName serviceName) {
082: return ContextClassLoaderProxy
083: .wrap(getServiceInternal(serviceName));
084: }
085:
086: protected Object getServiceInternal(QName serviceName) {
087: if (serviceName.getLocalPart().equals(
088: KEWServiceLocator.WORKFLOW_UTILITY_SERVICE)) {
089: return getWorkflowUtility();
090: } else if (serviceName.getLocalPart().equals(
091: KEWServiceLocator.WORKFLOW_DOCUMENT_ACTIONS_SERVICE)) {
092: return getWorkflowDoucment();
093: }
094: return SpringLoader.getInstance().getService(serviceName);
095: }
096:
097: public WorkflowUtility getWorkflowUtility() {
098: HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
099: proxyFactory.setServiceUrl(Core.getCurrentContextConfig()
100: .getProperty("workflowutility.javaservice.endpoint"));
101:
102: proxyFactory.setServiceInterface(WorkflowUtility.class);
103: String secureProp = Core.getCurrentContextConfig().getProperty(
104: "secure.workflowutility.javaservice.endpoint");
105: Boolean secureIt = null;
106: if (secureProp == null) {
107: secureIt = true;
108: } else {
109: secureIt = new Boolean(secureProp);
110: }
111:
112: KEWHttpInvokerRequestExecutor executor = new KEWHttpInvokerRequestExecutor(
113: secureIt); // new
114: // KEWHttpInvokerRequestExecutor(getHttpClient());
115: proxyFactory.setHttpInvokerRequestExecutor(executor);
116: proxyFactory.afterPropertiesSet();
117: return (WorkflowUtility) proxyFactory.getObject();
118: }
119:
120: public WorkflowDocumentActions getWorkflowDoucment() {
121: HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
122: proxyFactory.setServiceUrl(Core.getCurrentContextConfig()
123: .getProperty("workflowdocument.javaservice.endpoint"));
124: proxyFactory.setServiceInterface(WorkflowDocumentActions.class);
125: String secureProp = Core.getCurrentContextConfig().getProperty(
126: "secure.workflowdocument.javaservice.endpoint");
127: Boolean secureIt = null;
128: if (secureProp == null) {
129: secureIt = true;
130: } else {
131: secureIt = new Boolean(secureProp);
132: }
133:
134: KEWHttpInvokerRequestExecutor executor = new KEWHttpInvokerRequestExecutor(
135: secureIt); // new
136: // KEWHttpInvokerRequestExecutor(getHttpClient());
137: proxyFactory.setHttpInvokerRequestExecutor(executor);
138: proxyFactory.afterPropertiesSet();
139: return (WorkflowDocumentActions) proxyFactory.getObject();
140: }
141:
142: /*
143: * the below code copied from RemoteResourceServiceLocator
144: */
145:
146: private HttpClientParams httpClientParams;
147:
148: /**
149: * Creates a commons HttpClient for service invocation. Config parameters
150: * that start with http.* are used to configure the client.
151: *
152: * TODO we need to add support for other invocation protocols and
153: * implementations, but for now...
154: */
155: protected HttpClient getHttpClient() {
156: return new HttpClient(httpClientParams);
157: }
158:
159: protected void initializeHttpClientParams() {
160: httpClientParams = new HttpClientParams();
161: configureDefaultHttpClientParams(httpClientParams);
162: Properties configProps = Core.getCurrentContextConfig()
163: .getProperties();
164: for (Iterator iterator = configProps.keySet().iterator(); iterator
165: .hasNext();) {
166: String paramName = (String) iterator.next();
167: if (paramName.startsWith("http.")) {
168: HttpClientHelper.setParameter(httpClientParams,
169: paramName, (String) configProps.get(paramName));
170: }
171: }
172: }
173:
174: protected void configureDefaultHttpClientParams(HttpParams params) {
175: params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS,
176: MultiThreadedHttpConnectionManager.class);
177: params.setParameter(HttpMethodParams.COOKIE_POLICY,
178: CookiePolicy.RFC_2109);
179: params.setLongParameter(
180: HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 10000);
181: Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
182: maxHostConnectionsMap.put(
183: HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(
184: 20));
185: params.setParameter(
186: HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
187: maxHostConnectionsMap);
188: params.setIntParameter(
189: HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 20);
190: params.setIntParameter(
191: HttpConnectionManagerParams.CONNECTION_TIMEOUT, 10000);
192: }
193:
194: }
|