001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.server.axis;
018:
019: import org.apache.axis.description.JavaServiceDesc;
020: import org.apache.axis.handlers.HandlerInfoChainFactory;
021: import org.apache.axis.handlers.soap.SOAPService;
022: import org.apache.axis.providers.java.RPCProvider;
023: import org.apache.openejb.DeploymentInfo;
024: import org.apache.openejb.OpenEJBException;
025: import org.apache.openejb.core.webservices.HandlerChainData;
026: import org.apache.openejb.core.webservices.HandlerData;
027: import org.apache.openejb.core.webservices.PortData;
028: import org.apache.openejb.jee.JavaWsdlMapping;
029: import org.apache.openejb.jee.PortComponent;
030: import org.apache.openejb.server.axis.assembler.CommonsSchemaInfoBuilder;
031: import org.apache.openejb.server.axis.assembler.JaxRpcServiceInfo;
032: import org.apache.openejb.server.axis.assembler.JaxRpcServiceInfoBuilder;
033: import org.apache.openejb.server.axis.assembler.XmlSchemaInfo;
034: import org.apache.openejb.server.httpd.HttpListener;
035: import org.apache.openejb.server.webservices.WsService;
036:
037: import javax.naming.Context;
038: import javax.wsdl.Port;
039: import javax.xml.namespace.QName;
040: import javax.xml.rpc.handler.HandlerInfo;
041: import java.net.URL;
042: import java.util.ArrayList;
043: import java.util.HashMap;
044: import java.util.List;
045: import java.util.Map;
046: import java.util.TreeMap;
047:
048: public class AxisService extends WsService {
049: private final Map<String, AxisWsContainer> wsContainers = new TreeMap<String, AxisWsContainer>();
050:
051: public String getName() {
052: return "axis";
053: }
054:
055: private JaxRpcServiceInfo getJaxRpcServiceInfo(
056: ClassLoader classLoader) throws OpenEJBException {
057: JavaWsdlMapping mapping = null; // the java to wsdl mapping file
058: CommonsSchemaInfoBuilder xmlBeansSchemaInfoBuilder = new CommonsSchemaInfoBuilder(
059: null, null); // the schema data from the wsdl file
060: PortComponent portComponent = null; // webservice.xml declaration of this service
061: Port port = null; // wsdl.xml declaration of this service
062: String wsdlFile = null;
063:
064: XmlSchemaInfo schemaInfo = xmlBeansSchemaInfoBuilder
065: .createSchemaInfo();
066:
067: JaxRpcServiceInfoBuilder serviceInfoBuilder = new JaxRpcServiceInfoBuilder(
068: mapping, schemaInfo, portComponent, port, wsdlFile,
069: classLoader);
070: JaxRpcServiceInfo serviceInfo = serviceInfoBuilder
071: .createServiceInfo();
072: return serviceInfo;
073: }
074:
075: protected HttpListener createEjbWsContainer(URL moduleBaseUrl,
076: PortData port, DeploymentInfo deploymentInfo)
077: throws Exception {
078: ClassLoader classLoader = deploymentInfo.getClassLoader();
079:
080: // todo build JaxRpcServiceInfo in assembler
081: JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
082:
083: // Build java service descriptor
084: JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(
085: serviceInfo, classLoader);
086: JavaServiceDesc serviceDesc = javaServiceDescBuilder
087: .createServiceDesc();
088:
089: // Create service
090: RPCProvider provider = new EjbContainerProvider(deploymentInfo,
091: createHandlerInfos(port.getHandlerChains()));
092: SOAPService service = new SOAPService(null, provider, null);
093: service.setServiceDescription(serviceDesc);
094:
095: // Set class name
096: service.setOption("className", deploymentInfo
097: .getServiceEndpointInterface().getName());
098: serviceDesc.setImplClass(deploymentInfo
099: .getServiceEndpointInterface());
100:
101: // Create container
102: AxisWsContainer container = new AxisWsContainer(port
103: .getWsdlUrl(), service, null, classLoader);
104: wsContainers.put(deploymentInfo.getDeploymentID().toString(),
105: container);
106: return container;
107: }
108:
109: protected void destroyEjbWsContainer(String deploymentId) {
110: AxisWsContainer container = wsContainers.remove(deploymentId);
111: if (container != null) {
112: container.destroy();
113: }
114: }
115:
116: protected HttpListener createPojoWsContainer(URL moduleBaseUrl,
117: PortData port, String serviceId, Class target,
118: Context context, String contextRoot) throws Exception {
119: ClassLoader classLoader = target.getClassLoader();
120:
121: // todo build JaxRpcServiceInfo in assembler
122: JaxRpcServiceInfo serviceInfo = getJaxRpcServiceInfo(classLoader);
123:
124: // Build java service descriptor
125: JavaServiceDescBuilder javaServiceDescBuilder = new JavaServiceDescBuilder(
126: serviceInfo, classLoader);
127: JavaServiceDesc serviceDesc = javaServiceDescBuilder
128: .createServiceDesc();
129:
130: // Create service
131: RPCProvider provider = new PojoProvider();
132: SOAPService service = new SOAPService(null, provider, null);
133: service.setServiceDescription(serviceDesc);
134:
135: // Set class name
136: service.setOption("className", target.getName());
137:
138: // Add Handler Chain
139: List<HandlerInfo> handlerInfos = createHandlerInfos(port
140: .getHandlerChains());
141: HandlerInfoChainFactory handlerInfoChainFactory = new HandlerInfoChainFactory(
142: handlerInfos);
143: service.setOption(
144: org.apache.axis.Constants.ATTR_HANDLERINFOCHAIN,
145: handlerInfoChainFactory);
146:
147: // Create container
148: AxisWsContainer container = new AxisWsContainer(port
149: .getWsdlUrl(), service, null, classLoader);
150: wsContainers.put(serviceId, container);
151: return container;
152: }
153:
154: protected void destroyPojoWsContainer(String serviceId) {
155: AxisWsContainer container = wsContainers.remove(serviceId);
156: if (container != null) {
157: container.destroy();
158: }
159: }
160:
161: @SuppressWarnings({"unchecked"})
162: private List<HandlerInfo> createHandlerInfos(
163: List<HandlerChainData> handlerChains)
164: throws ClassNotFoundException {
165: if (handlerChains == null || handlerChains.isEmpty())
166: return null;
167: List<HandlerData> handlers = handlerChains.get(0).getHandlers();
168:
169: List<HandlerInfo> handlerInfos = new ArrayList<HandlerInfo>(
170: handlers.size());
171: for (HandlerData handler : handlers) {
172: Class<?> handlerClass = handler.getHandlerClass();
173: Map initParams = new HashMap(handler.getInitParams());
174: QName[] headers = handler.getSoapHeaders().toArray(
175: new QName[handler.getSoapHeaders().size()]);
176: HandlerInfo handlerInfo = new HandlerInfo(handlerClass,
177: initParams, headers);
178: handlerInfos.add(handlerInfo);
179: }
180:
181: return handlerInfos;
182: }
183: }
|