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 org.kuali.workflow.config;
018:
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.Map;
022: import java.util.Properties;
023:
024: import javax.xml.namespace.QName;
025:
026: import org.apache.commons.httpclient.HostConfiguration;
027: import org.apache.commons.httpclient.HttpClient;
028: import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
029: import org.apache.commons.httpclient.cookie.CookiePolicy;
030: import org.apache.commons.httpclient.params.HttpClientParams;
031: import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
032: import org.apache.commons.httpclient.params.HttpMethodParams;
033: import org.apache.commons.httpclient.params.HttpParams;
034: import org.kuali.rice.core.Core;
035: import org.kuali.rice.lifecycle.Lifecycle;
036: import org.kuali.rice.resourceloader.BaseResourceLoader;
037: import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
038:
039: import edu.iu.uis.eden.KEWServiceLocator;
040: import edu.iu.uis.eden.SpringLoader;
041: import edu.iu.uis.eden.core.dependencylifecycles.SpringLifeCycle;
042: import edu.iu.uis.eden.messaging.HttpClientHelper;
043: import edu.iu.uis.eden.messaging.KEWHttpInvokerRequestExecutor;
044: import edu.iu.uis.eden.server.WorkflowDocumentActions;
045: import edu.iu.uis.eden.server.WorkflowUtility;
046:
047: /**
048: * Initializes and loads webservice resources for the Embedded plugin.
049: * Currently, the only 2 services which are exposed are the utility service and
050: * the document actions service.
051: *
052: * @author Eric Westfall
053: * @author rkirkend
054: */
055: public class ThinClientResourceLoader extends BaseResourceLoader {
056:
057: private Lifecycle springLifecycle = new SpringLifeCycle(
058: "org/kuali/workflow/resources/KewWebClientBeans.xml");
059:
060: public ThinClientResourceLoader() {
061: super (new QName(Core.getCurrentContextConfig()
062: .getMessageEntity(), "ThinClientResourceLoader"));
063: }
064:
065: @Override
066: public void start() throws Exception {
067: super .start();
068: springLifecycle.start();
069: }
070:
071: @Override
072: public void stop() throws Exception {
073: super .stop();
074: springLifecycle.stop();
075: }
076:
077: public Object getService(QName serviceName) {
078: if (serviceName.getLocalPart().equals(
079: KEWServiceLocator.WORKFLOW_UTILITY_SERVICE)) {
080: return getWorkflowUtility();
081: } else if (serviceName.getLocalPart().equals(
082: KEWServiceLocator.WORKFLOW_DOCUMENT_ACTIONS_SERVICE)) {
083: return getWorkflowDoucment();
084: }
085: return SpringLoader.getInstance().getService(serviceName);
086: }
087:
088: public WorkflowUtility getWorkflowUtility() {
089: HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
090: proxyFactory.setServiceUrl(Core.getCurrentContextConfig()
091: .getProperty("workflowutility.javaservice.endpoint"));
092:
093: proxyFactory.setServiceInterface(WorkflowUtility.class);
094: String secureProp = Core.getCurrentContextConfig().getProperty(
095: "secure.workflowutility.javaservice.endpoint");
096: Boolean secureIt = null;
097: if (secureProp == null) {
098: secureIt = true;
099: } else {
100: secureIt = new Boolean(secureProp);
101: }
102:
103: KEWHttpInvokerRequestExecutor executor = new KEWHttpInvokerRequestExecutor(
104: secureIt);
105:
106: proxyFactory.setHttpInvokerRequestExecutor(executor);
107: proxyFactory.afterPropertiesSet();
108: return (WorkflowUtility) proxyFactory.getObject();
109: }
110:
111: public WorkflowDocumentActions getWorkflowDoucment() {
112: HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
113: proxyFactory.setServiceUrl(Core.getCurrentContextConfig()
114: .getProperty("workflowdocument.javaservice.endpoint"));
115: proxyFactory.setServiceInterface(WorkflowDocumentActions.class);
116: String secureProp = Core.getCurrentContextConfig().getProperty(
117: "secure.workflowdocument.javaservice.endpoint");
118: Boolean secureIt = null;
119: if (secureProp == null) {
120: secureIt = true;
121: } else {
122: secureIt = new Boolean(secureProp);
123: }
124:
125: KEWHttpInvokerRequestExecutor executor = new KEWHttpInvokerRequestExecutor(
126: secureIt);
127: proxyFactory.setHttpInvokerRequestExecutor(executor);
128: proxyFactory.afterPropertiesSet();
129: return (WorkflowDocumentActions) proxyFactory.getObject();
130: }
131:
132: /*
133: * the below code copied from RemoteResourceServiceLocator
134: */
135:
136: private HttpClientParams httpClientParams;
137:
138: /**
139: * Creates a commons HttpClient for service invocation. Config parameters
140: * that start with http.* are used to configure the client.
141: *
142: * TODO we need to add support for other invocation protocols and
143: * implementations, but for now...
144: */
145: protected HttpClient getHttpClient() {
146: return new HttpClient(httpClientParams);
147: }
148:
149: protected void initializeHttpClientParams() {
150: httpClientParams = new HttpClientParams();
151: configureDefaultHttpClientParams(httpClientParams);
152: Properties configProps = Core.getCurrentContextConfig()
153: .getProperties();
154: for (Iterator iterator = configProps.keySet().iterator(); iterator
155: .hasNext();) {
156: String paramName = (String) iterator.next();
157: if (paramName.startsWith("http.")) {
158: HttpClientHelper.setParameter(httpClientParams,
159: paramName, (String) configProps.get(paramName));
160: }
161: }
162: }
163:
164: protected void configureDefaultHttpClientParams(HttpParams params) {
165: params.setParameter(HttpClientParams.CONNECTION_MANAGER_CLASS,
166: MultiThreadedHttpConnectionManager.class);
167: params.setParameter(HttpMethodParams.COOKIE_POLICY,
168: CookiePolicy.RFC_2109);
169: params.setLongParameter(
170: HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 10000);
171: Map<HostConfiguration, Integer> maxHostConnectionsMap = new HashMap<HostConfiguration, Integer>();
172: maxHostConnectionsMap.put(
173: HostConfiguration.ANY_HOST_CONFIGURATION, new Integer(
174: 20));
175: params.setParameter(
176: HttpConnectionManagerParams.MAX_HOST_CONNECTIONS,
177: maxHostConnectionsMap);
178: params.setIntParameter(
179: HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 20);
180: params.setIntParameter(
181: HttpConnectionManagerParams.CONNECTION_TIMEOUT, 10000);
182: }
183:
184: }
|