01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.servlet;
18:
19: import java.io.UnsupportedEncodingException;
20: import java.net.URLDecoder;
21:
22: import javax.servlet.http.HttpServletRequest;
23: import javax.xml.namespace.QName;
24:
25: import org.apache.log4j.Logger;
26: import org.kuali.rice.core.Core;
27: import org.kuali.rice.resourceloader.GlobalResourceLoader;
28: import org.springframework.web.servlet.HandlerMapping;
29: import org.springframework.web.servlet.handler.AbstractHandlerMapping;
30: import org.springframework.web.util.UrlPathHelper;
31:
32: import edu.iu.uis.eden.messaging.RemotedServiceRegistry;
33:
34: /**
35: * A {@link HandlerMapping} which handles incoming HTTP requests from the bus.
36: *
37: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
38: */
39: public class KSBHttpInvokerHandler extends AbstractHandlerMapping {
40:
41: private static final Logger LOG = Logger
42: .getLogger(KSBHttpInvokerHandler.class);
43:
44: private UrlPathHelper urlPathHelper = new UrlPathHelper();
45:
46: protected Object getHandlerInternal(HttpServletRequest request)
47: throws Exception {
48: QName serviceName = getServiceNameFromRequest(request);
49: // load the servlet for handling JMX communication
50: if (serviceName.equals(new QName(Core.getCurrentContextConfig()
51: .getMessageEntity(), "jmx"))) {
52: return GlobalResourceLoader
53: .getService("jmxWrappingController");
54: }
55: return ((RemotedServiceRegistry) GlobalResourceLoader
56: .getService("enServiceInvoker"))
57: .getService(serviceName);
58: }
59:
60: public QName getServiceNameFromRequest(HttpServletRequest request) {
61: try {
62: String lookupPath = this .urlPathHelper
63: .getLookupPathForRequest(request);
64: String serviceName = URLDecoder.decode(lookupPath
65: .substring(1, lookupPath.length()), "UTF-8");
66: if (LOG.isDebugEnabled()) {
67: LOG
68: .debug("#############################################################");
69: LOG.debug("Entering Message Entity "
70: + Core.getCurrentContextConfig()
71: .getMessageEntity()
72: + ". Looking up handler for [" + serviceName
73: + "]");
74: LOG
75: .debug("#############################################################");
76: }
77: return QName.valueOf(serviceName);
78: } catch (UnsupportedEncodingException e) {
79: throw new RuntimeException(e);
80: }
81: }
82: }
|