You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/11/16 09:07:21 UTC
svn commit: r344946 - in /beehive/trunk/wsm:
src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java
test/build.xml
Author: ekoneil
Date: Wed Nov 16 00:07:14 2005
New Revision: 344946
URL: http://svn.apache.org/viewcvs?rev=344946&view=rev
Log:
Cleanup in the deployment handler for an annotated web service.
- removed lots of defensive null checks and replaced with asserts
- removed checked exceptions and replaced with runtime exceptions. Not sure if these need to be AxisFault instances -- probably so.
- enable asserts in the WSM server tests
BB: self
Test: WSM pass
Modified:
beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java
beehive/trunk/wsm/test/build.xml
Modified: beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java?rev=344946&r1=344945&r2=344946&view=diff
==============================================================================
--- beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java (original)
+++ beehive/trunk/wsm/src/axis/org/apache/beehive/wsm/axis/handlers/AnnotatedWebServiceDeploymentHandler.java Wed Nov 16 00:07:14 2005
@@ -23,6 +23,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.io.IOException;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.HandlerInfo;
@@ -42,20 +43,12 @@
import org.apache.beehive.wsm.model.BeehiveWsSOAPMessageHandlerInfo;
import org.apache.beehive.wsm.model.BeehiveWsTypeMetadata;
import org.apache.beehive.wsm.model.jsr181.Jsr181ObjectModelStore;
+import org.apache.beehive.wsm.exception.InvalidTypeMappingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * ****************************************************************************
- * A few annotation specific things added and lots of code copied from the
- * JWSHandler class by
*
- * @author Jonathan Colwell (jcolwell@bea.com) but most of the original code was
- * written by:
- * @author Glen Daniels (gdaniels@allaire.com)
- * @author Doug Davis (dug@us.ibm.com)
- * @author Sam Ruby (rubys@us.ibm.com) todo: fix directory
- * structure/classloaders for output files
*/
public class AnnotatedWebServiceDeploymentHandler
extends BasicHandler {
@@ -63,30 +56,35 @@
private static final String JWS_EXTENSION = ".jws";
private static Log LOGGER = LogFactory.getLog(AnnotatedWebServiceDeploymentHandler.class);
- private Map<String, SOAPService> soapServices = new HashMap<String, SOAPService>();
+ private Map<String, SOAPService> _soapServices = new HashMap<String, SOAPService>();
+
+ /**
+ */
+ public void generateWSDL(MessageContext mc)
+ throws AxisFault {
+ invoke(mc);
+ }
/**
- * @param mc
- * @throws AxisFault
*/
public void invoke(MessageContext mc)
throws AxisFault {
try {
- SOAPService ss = getSOAPService(getWebServiceClass(mc));
- if(null != ss) {
- ss.setEngine(mc.getAxisEngine());
- mc.setService(ss);
- /*
- * NOTE jcolwell@bea.com 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(Use.ENCODED.equals(ss.getUse())));
+ Class clazz = getWebServiceClass(mc);
+ SOAPService ss = getSOAPService(clazz);
+ assert ss != null : "Unable to create SOAP service from \"" + clazz + "\"";
- // blow away the real path to bypass the regular JWSHandler
- mc.removeProperty(Constants.MC_REALPATH);
- }
+ ss.setEngine(mc.getAxisEngine());
+ mc.setService(ss);
+
+ /*
+ * NOTE jcolwell@bea.com 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(Use.ENCODED.equals(ss.getUse())));
+ mc.removeProperty(Constants.MC_REALPATH);
}
catch(Exception e) {
throw AxisFault.makeFault(e);
@@ -94,29 +92,29 @@
}
/**
- * @param mc
- * @throws AxisFault
*/
- public void generateWSDL(MessageContext mc)
- throws AxisFault {
- invoke(mc);
- }
+ protected SOAPService getSOAPService(Class clazz) {
+ assert clazz != null : "Can't create a SOAPService from a null class!";
- /**
- * @param clazz
- * @return SOAPService
- * @throws Exception
- */
- protected SOAPService getSOAPService(Class clazz)
- throws Exception {
- SOAPService ss = null;
- if(null != clazz) {
- ss = soapServices.get(clazz.getName());
- if(null == ss) {
- BeehiveWsTypeMetadata typeMetadata = Jsr181ObjectModelStore.load(clazz);
- ss = createSOAPService(typeMetadata, clazz);
+ SOAPService ss = _soapServices.get(clazz.getName());
+ if(ss == null) {
+ BeehiveWsTypeMetadata typeMetadata = null;
+ try {
+ typeMetadata = Jsr181ObjectModelStore.load(clazz);
}
+ catch (IOException e) {
+ throw new IllegalStateException("Unable to load metadata for service \"" +
+ clazz.getName() + "\". Cause: " + e, e);
+ }
+ catch (ClassNotFoundException e) {
+ throw new IllegalStateException("Unable to load metadata for service \"" +
+ clazz.getName() + "\". Cause: " + e, e);
+ }
+
+ ss = createSOAPService(typeMetadata, clazz);
}
+
+ assert ss != null;
return ss;
}
@@ -124,78 +122,89 @@
* @param wsm
* @param cls
* @return SOAPService
- * @throws Exception
*/
- private SOAPService createSOAPService(BeehiveWsTypeMetadata wsm, Class cls)
- throws Exception {
+ private SOAPService createSOAPService(BeehiveWsTypeMetadata wsm, Class cls) {
- SOAPService ss = null;
- if(null != wsm) {
+ assert wsm != null : "Unable to create SOAPService since the WSM object model is null";
- // // NOTE jcolwell@bea.com 2004-Nov-01 --
- // // not calling ss.init() since ControlProvider won't do anything
- // // with it and I don't want the HandlerHandler initialized twice.
- // ss = new SOAPService(hh, new ControlProvider(), hh);
-
- /* todo: can the ControlProvider be used statically? */
- ss = new SOAPService(null, new ControlProvider(), null);
-
- // Add jaxrpc handlers if there are any.
- HandlerInfoChainFactory jaxrpcChain = getJaxRPCHandlerChainFactory(wsm);
- if(jaxrpcChain != null)
- ss.setOption(Constants.ATTR_HANDLERINFOCHAIN, jaxrpcChain);
- ss.setName(wsm.getName());
- ss.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";
-
- ss.setOption(RPCProvider.OPTION_SCOPE, scope);
- ServiceDesc sd = ServiceDescriptionFactory.getInstance().createServiceDescription(wsm, cls.getClassLoader());
- ss.setServiceDescription(sd);
+ /* todo: wire-up the ControlProvider as a handler. is that possible? */
+ SOAPService ss = new SOAPService(null, new ControlProvider(), null);
- List allowedMethodNames = sd.getAllowedMethods();
- Iterator allowedMethods = allowedMethodNames.iterator();
+ /* add jaxrpc handlers if there are any. */
+ HandlerInfoChainFactory jaxrpcChain = getJaxRPCHandlerChainFactory(wsm);
+ if(jaxrpcChain != null)
+ ss.setOption(Constants.ATTR_HANDLERINFOCHAIN, jaxrpcChain);
+ ss.setName(wsm.getName());
+ ss.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";
- /*
- todo: can StringBuilder be used here since there's no need for synchronization?
- todo: can the output String be cached? Presumably, the list of methods doesn't change for a single deploymentx
- */
- StringBuffer sb = new StringBuffer();
- boolean first = true;
- while(allowedMethods.hasNext()) {
- if(!first)
- sb.append(' ');
- sb.append(allowedMethods.next());
- first = false;
- }
+ ss.setOption(RPCProvider.OPTION_SCOPE, scope);
+ ServiceDesc sd = null;
+ try {
+ sd = ServiceDescriptionFactory.getInstance().createServiceDescription(wsm, cls.getClassLoader());
+ }
+ catch(ClassNotFoundException e) {
+ throw new IllegalStateException("Unable to create service description for web service in class \""
+ + wsm.getServiceClassName() + "\". Cause: " + e, e);
+ }
+ catch(InvalidTypeMappingException e) {
+ throw new IllegalStateException("Unable to create service description for web service in class \""
+ + wsm.getServiceClassName() + "\". Cause: " + e, e);
+ }
- ss.setOption(RPCProvider.OPTION_ALLOWEDMETHODS, sb.toString());
- ss.setOption(RPCProvider.OPTION_WSDL_PORTTYPE, wsm.getName());
- ss.setOption(RPCProvider.OPTION_WSDL_SERVICEPORT, wsm.getName());
- ss.setOption(RPCProvider.OPTION_WSDL_SERVICEELEMENT, wsm.getServiceName());
- ss.setOption(RPCProvider.OPTION_WSDL_TARGETNAMESPACE, wsm.getTargetNamespace());
- ss.setStyle(sd.getStyle());
- ss.setUse(sd.getUse());
- soapServices.put(cls.getName(), ss);
+ ss.setServiceDescription(sd);
+
+ List allowedMethodNames = sd.getAllowedMethods();
+ Iterator allowedMethods = allowedMethodNames.iterator();
+
+ StringBuffer sb = new StringBuffer();
+ boolean first = true;
+ while(allowedMethods.hasNext()) {
+ if(!first)
+ sb.append(' ');
+ sb.append(allowedMethods.next());
+ first = false;
}
+
+ ss.setOption(RPCProvider.OPTION_ALLOWEDMETHODS, sb.toString());
+ ss.setOption(RPCProvider.OPTION_WSDL_PORTTYPE, wsm.getName());
+ ss.setOption(RPCProvider.OPTION_WSDL_SERVICEPORT, wsm.getName());
+ ss.setOption(RPCProvider.OPTION_WSDL_SERVICEELEMENT, wsm.getServiceName());
+ ss.setOption(RPCProvider.OPTION_WSDL_TARGETNAMESPACE, wsm.getTargetNamespace());
+ ss.setStyle(sd.getStyle());
+ ss.setUse(sd.getUse());
+ _soapServices.put(cls.getName(), ss);
+
return ss;
}
- private HandlerInfoChainFactory getJaxRPCHandlerChainFactory(BeehiveWsTypeMetadata wsm)
- throws ClassNotFoundException {
+ private HandlerInfoChainFactory getJaxRPCHandlerChainFactory(BeehiveWsTypeMetadata wsm) {
HandlerInfoChainFactory res = null;
- List<? extends BeehiveWsSOAPMessageHandlerInfo> handlers = wsm.getSoapHandlers();
+ List handlers = wsm.getSoapHandlers();
if(handlers.size() > 0) {
ArrayList<HandlerInfo> infoList = new ArrayList<HandlerInfo>();
HashSet<String> roles = new HashSet<String>();
- for(BeehiveWsSOAPMessageHandlerInfo handler : handlers) {
- Class handlerClass = ClassUtils.forName(handler.getClassName());
+ Iterator iterator = handlers.iterator();
+ while(iterator.hasNext()) {
+ BeehiveWsSOAPMessageHandlerInfo handler = (BeehiveWsSOAPMessageHandlerInfo)iterator.next();
+
+ Class handlerClass = null;
+ try {
+ ClassUtils.forName(handler.getClassName());
+ }
+ catch(ClassNotFoundException e) {
+ throw new IllegalStateException("Could not locate handler class \""
+ + handler.getClassName()
+ + "\". Cause: " + e, e);
+ }
+
QName[] handlerHeaders = handler.getHeaders().toArray(new QName[0]);
infoList.add(new HandlerInfo(handlerClass, handler.getParameterMap(), handlerHeaders));
roles.addAll(handler.getRoles());
@@ -211,36 +220,32 @@
/**
* @param mc
* @return web service Class
- * @throws Exception
*/
- private Class getWebServiceClass(MessageContext mc)
- throws Exception {
+ private Class getWebServiceClass(MessageContext mc) {
- // check message context
- if(null == mc)
- throw new IllegalArgumentException("message context not set");
+ assert mc != null;
- // retrieve & check relative path
+ /* retrieve and check relative path */
String relativePath = mc.getStrProp(Constants.MC_RELATIVE_PATH);
- if(null == relativePath)
- throw new Exception("relative path not set properly in message context");
+ if(relativePath == null)
+ throw new IllegalStateException("Relative path not set properly in message context");
- // turn relative path into fq class name
+ /* turn relative path into a fully qualified class name */
if(!relativePath.startsWith("/"))
- throw new Exception("invalid relative path: " + relativePath);
+ throw new IllegalStateException("Invalid relative path: " + relativePath);
String className = null;
if(relativePath.endsWith(JWS_EXTENSION))
className = relativePath.substring(1, relativePath.length() - JWS_EXTENSION.length()).replaceAll("/", ".");
- else
- className = relativePath.substring(1, relativePath.length()).replaceAll("/", ".");
+ else className = relativePath.substring(1, relativePath.length()).replaceAll("/", ".");
LOGGER.debug("attempt to load web service class: " + className);
- Class clazz = Jsr181ObjectModelStore.loadWebServiceClass(className);
- if(null == clazz)
- LOGGER.debug("failed to load web service class: " + className);
-
- return clazz;
+ try {
+ return Jsr181ObjectModelStore.loadWebServiceClass(className);
+ }
+ catch(ClassNotFoundException e) {
+ throw new IllegalStateException("Could not locate web service class \"" + className + "\". Cause: " + e, e);
+ }
}
}
Modified: beehive/trunk/wsm/test/build.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/wsm/test/build.xml?rev=344946&r1=344945&r2=344946&view=diff
==============================================================================
--- beehive/trunk/wsm/test/build.xml (original)
+++ beehive/trunk/wsm/test/build.xml Wed Nov 16 00:07:14 2005
@@ -188,7 +188,7 @@
<target name="drt.server" description="Run the server tests">
<parallel>
- <start-server shmem="false" javaOptions=""/>
+ <start-server shmem="false" javaOptions="-ea:org.apache.beehive.wsm..."/>
<sequential>
<antcall target="ensure.deployed"/>
<echo message="JUnit logs in: ${drt.logs}"/>