Author: mmerz
Date: Wed Oct 27 17:51:18 2004
New Revision: 55754
Added:
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AnnotatedWebServiceDeploymentHandler.java
Log:
Added the AnnotatedWebSericeDeploymentHandler
Contributor: Daryoush Mehrtash
Added:
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AnnotatedWebServiceDeploymentHandler.java
==============================================================================
--- (empty file)
+++
incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/axis/AnnotatedWebServiceDeploymentHandler.java
Wed Oct 27 17:51:18 2004
@@ -0,0 +1,276 @@
+package org.apache.beehive.wsm.axis;
+
+/*
+ * DropInDeploymentHandler.java
+ *
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import org.apache.beehive.wsm.jsr181.model.WebServiceTYPEMetadata;
+import org.apache.beehive.wsm.jsr181.model.WebServiceMETHODMetadata;
+import org.apache.beehive.wsm.jsr181.model.WebServicePARAMETERMetadata;
+import
org.apache.beehive.wsm.jsr181.processor.reflection.WsmReflectionAnnotationProcessor;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLDecoder;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.AxisProperties;
+import org.apache.axis.Constants;
+import org.apache.axis.MessageContext;
+import org.apache.axis.client.Call;
+import org.apache.axis.components.compiler.Compiler;
+import org.apache.axis.components.compiler.CompilerError;
+import org.apache.axis.components.compiler.CompilerFactory;
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.description.ServiceDesc;
+import org.apache.axis.handlers.BasicHandler;
+import org.apache.axis.handlers.soap.SOAPService;
+import org.apache.axis.providers.java.RPCProvider;
+import org.apache.axis.transport.http.HTTPConstants;
+import org.apache.axis.utils.ClassUtils;
+import org.apache.axis.utils.JWSClassLoader;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.XMLUtils;
+import org.apache.beehive.wsm.axis.HandlerHandler;
+import org.apache.beehive.wsm.axis.badtiger.EnumWrapper;
+import org.apache.beehive.wsm.axis.util.ClasspathUtils;
+import org.apache.commons.logging.Log;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/*******************************************************************************
+ * A few annotation specific things added and lots of code copied from the
+ * JWSHandler class by
+ *
+ * @author Jonathan Colwell ([EMAIL PROTECTED])
+ *
+ * but most of the original code was written by:
+ * @author Glen Daniels ([EMAIL PROTECTED])
+ * @author Doug Davis ([EMAIL PROTECTED])
+ * @author Sam Ruby ([EMAIL PROTECTED])
+ *
+ * todo: fix directory structure/classloaders for output files
+ */
+public class AnnotatedWebServiceDeploymentHandler extends BasicHandler
+{
+ protected static Log log =
+
LogFactory.getLog(AnnotatedWebServiceDeploymentHandler.class.getName());
+
+ protected Map<String, SOAPService> soapServices = new HashMap<String,
+
SOAPService>();
+
+ /**
+ * @param mc
+ * @throws AxisFault
+ */
+ public void invoke(MessageContext mc)
+ throws AxisFault
+ {
+ try {
+
+ SOAPService ss =
+ createSOAPServiceFromAnnotatedClass(findWebServiceClass(mc));
+ if (null != ss)
+ {
+ ss.setEngine(mc.getAxisEngine());
+ ss.init();
+ mc.setService(ss);
+ /*
+ * NOTE [EMAIL PROTECTED] 2004-Oct-22 -- not
sure why, but xsi
+ * types were still being sent even with
literal Use. Forcing it
+ * to not send the types unless encoded.
+ */
+ mc.setProperty(Call.SEND_TYPE_ATTR,
+ new Boolean(EnumWrapper.ENCODED
+ .equals(ss.getUse())));
+
+ // blow away the real path to bypass the regular JWSHandler
+ mc.removeProperty(Constants.MC_REALPATH);
+ }
+ }
+ catch (Exception e)
+ {
+ throw AxisFault.makeFault(e);
+ }
+ }
+
+ /**
+ * @param mc
+ * throws AxisFault
+ */
+ public void generateWSDL(MessageContext mc)
+ throws AxisFault
+ {
+ invoke(mc);
+ }
+
+ /**
+ * @param
+ * @return
+ * @throws Exception
+ */
+ protected SOAPService createSOAPServiceFromAnnotatedClass(Class clazz)
+ throws Exception
+ {
+ SOAPService rpc = null;
+
+ if (null != clazz)
+ {
+ rpc = soapServices.get(clazz.getName());
+ if (null == rpc)
+ {
+ WebServiceTYPEMetadata wsm =
+ (WebServiceTYPEMetadata)
WsmReflectionAnnotationProcessor.getInstance().getObjectModel(clazz);
+
+ rpc = createSOAPServiceUsingAnnotations(wsm, clazz);
+ }
+ }
+
+ return rpc;
+ }
+
+ /**
+ * @param wsm
+ * @param cls
+ * @return
+ * @throws Exception
+ */
+ protected SOAPService
createSOAPServiceUsingAnnotations(WebServiceTYPEMetadata wsm, Class cls)
+ throws Exception
+ {
+ SOAPService rpc = null;
+
+ if (null != wsm)
+ {
+ HandlerHandler hh = new HandlerHandler();
+ hh.init(wsm);
+ rpc = new SOAPService(hh, new ControlProvider(), hh);
+ rpc.setName(wsm.getWsName());
+ rpc.setOption(RPCProvider.OPTION_CLASSNAME, cls.getName() );
+
+ // Take the setting for the scope option from the handler
+ // parameter named "scope"
+ String scope = (String)getOption(RPCProvider.OPTION_SCOPE);
+ if (null == scope)
+ {
+ scope = "Request";
+ }
+ rpc.setOption(RPCProvider.OPTION_SCOPE, scope);
+
+ ServiceDesc sd = AxisHook.createServiceDesc(wsm,
cls.getClassLoader());
+ rpc.setServiceDescription(sd);
+
+ List allowedMethodNames = sd.getAllowedMethods();
+ Iterator allowIt = allowedMethodNames.iterator();
+ StringBuffer sb = new StringBuffer();
+ boolean firstPass = true;
+ while (allowIt.hasNext())
+ {
+ if (firstPass)
+ {
+ sb.append(' ');
+ firstPass = false;
+ }
+ sb.append(((String)allowIt.next()));
+ }
+ rpc.setOption(RPCProvider.OPTION_ALLOWEDMETHODS,
+ sb.toString());
+ rpc.setOption(RPCProvider.OPTION_WSDL_PORTTYPE,
+ wsm.getWsName());
+ rpc.setOption(RPCProvider.OPTION_WSDL_SERVICEPORT,
+ wsm.getWsName());
+ rpc.setOption(RPCProvider.OPTION_WSDL_SERVICEELEMENT,
+ wsm.getWsServiceName());
+ rpc.setOption(RPCProvider.OPTION_WSDL_TARGETNAMESPACE,
+ wsm.getWsTargetNamespace());
+
+ rpc.setStyle(sd.getStyle());
+ rpc.setUse(sd.getUse());
+
+ soapServices.put(cls.getName(), rpc);
+ }
+ return rpc;
+ }
+
+ /**
+ * Mostly taken from Axis code base.
+ *
+ * @param mc
+ * @return
+ * @throws
+ */
+ protected Class findWebServiceClass(MessageContext mc)
+ throws Exception
+ {
+
+ if (null != mc) {
+
+ String relPath = mc.getStrProp(Constants.MC_RELATIVE_PATH);
+ if(null != relPath ) {
+ // check to see if this is annotated class
+ // clean up the relative path to use as the class destination
+ // dir
+ if ('/' == relPath.charAt(0))
+ {
+ relPath = relPath.substring(1);
+ }
+ int indexOfDot = relPath.indexOf(".");
+ if(-1 != indexOfDot) relPath=relPath.substring(0, indexOfDot);
+ String clsName=relPath.replaceAll("/", ".");
+ log.debug("look for webserivce in class: " + clsName);
+
+ try {
+ Class result =
getClass().getClassLoader().loadClass(clsName);
+ return result;
+ } catch (ClassNotFoundException e) {
+ log.debug("class: " + clsName + " was
not found by the AnnotatedWebServiceDeploymentHandler continue to the next
handler. ");
+ return null;
+ }
+
+ }
+
+ }
+ return null;
+ }
+
+
+}