You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by gd...@apache.org on 2007/06/20 14:30:44 UTC
svn commit: r549086 - in /webservices/axis2/trunk/java/modules/kernel:
src/org/apache/axis2/context/ src/org/apache/axis2/description/
src/org/apache/axis2/engine/ src/org/apache/axis2/receivers/
src/org/apache/axis2/service/ test/org/apache/axis2/ tes...
Author: gdaniels
Date: Wed Jun 20 05:30:42 2007
New Revision: 549086
URL: http://svn.apache.org/viewvc?view=rev&rev=549086
Log:
* Resolve https://issues.apache.org/jira/browse/AXIS2-2785 by introducing axis2.service.Lifecycle interface as per discussion and VOTE on axis-dev
* Leave introspection code for right now, but we'll note that this is changing in the release notes and remove it later on
* Add test for above, which made it necessary to add ConfigurationContext.addService().
* Add a copy of LocalTestCase (without RPC stuff) to kernel module. Maybe we should have the version in integration extend this one... probably!
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/Lifecycle.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/LocalTestCase.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/LifecycleTest.java
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java?view=diff&rev=549086&r1=549085&r2=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java Wed Jun 20 05:30:42 2007
@@ -248,12 +248,27 @@
cleanupServiceGroupContexts();
}
- public void addServiceGroupContextIntoApplicationScopeTable(ServiceGroupContext serviceGroupContext) {
+ public void addServiceGroupContextIntoApplicationScopeTable
+ (ServiceGroupContext serviceGroupContext) {
if (applicationSessionServiceGroupContexts == null) {
applicationSessionServiceGroupContexts = new Hashtable();
}
applicationSessionServiceGroupContexts.put(
serviceGroupContext.getDescription().getServiceGroupName(), serviceGroupContext);
+ }
+
+ /**
+ * Deploy a service to the embedded AxisConfiguration, and initialize it.
+ *
+ * @param service service to deploy
+ * @throws AxisFault if there's a problem
+ */
+ public void deployService(AxisService service) throws AxisFault {
+ axisConfiguration.addService(service);
+ if (Constants.SCOPE_APPLICATION.equals(service.getScope())) {
+ ServiceGroupContext sgc = createServiceGroupContext(service.getAxisServiceGroup());
+ DependencyManager.initService(sgc);
+ }
}
public AxisConfiguration getAxisConfiguration() {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?view=diff&rev=549086&r1=549085&r2=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Wed Jun 20 05:30:42 2007
@@ -2265,4 +2265,8 @@
public void setOperationsNameList(List operationsNameList) {
this.operationsNameList = operationsNameList;
}
+
+ public AxisServiceGroup getAxisServiceGroup() {
+ return (AxisServiceGroup)getParent();
+ }
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java?view=diff&rev=549086&r1=549085&r2=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/DependencyManager.java Wed Jun 20 05:30:42 2007
@@ -19,6 +19,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.service.Lifecycle;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.context.ServiceGroupContext;
import org.apache.axis2.description.AxisService;
@@ -39,11 +40,42 @@
public class DependencyManager {
private static final Log log = LogFactory.getLog(DependencyManager.class);
public final static String SERVICE_INIT_METHOD = "init";
- public final static String SERVICE_START_METHOD = "startUp";
public final static String SERVICE_DESTROY_METHOD = "destroy";
- public static void initServiceClass(Object obj,
- ServiceContext serviceContext) {
+ /**
+ * Initialize a new service object. Essentially, check to see if the object wants to receive
+ * an init() call - if so, call it.
+ *
+ * @param obj the service object
+ * @param serviceContext the active ServiceContext
+ * @throws AxisFault if there's a problem initializing
+ *
+ * @deprecated please use initServiceObject()
+ */
+ public static void initServiceClass(Object obj, ServiceContext serviceContext)
+ throws AxisFault {
+ initServiceObject(obj, serviceContext);
+ }
+
+ /**
+ * Initialize a new service object. Essentially, check to see if the object wants to receive
+ * an init() call - if so, call it.
+ *
+ * @param obj the service object
+ * @param serviceContext the active ServiceContext
+ * @throws AxisFault if there's a problem initializing
+ */
+ public static void initServiceObject(Object obj, ServiceContext serviceContext)
+ throws AxisFault {
+ // This is the way to do things into the future.
+ if (obj instanceof Lifecycle) {
+ ((Lifecycle)obj).init(serviceContext);
+ return;
+ }
+
+ // ...however, we also still support the old way for now. Note that introspecting for
+ // a method like this is something like 10 times slower than the above instanceof check.
+
Class classToLoad = obj.getClass();
// We can not call classToLoad.getDeclaredMethed() , since there
// can be insatnce where mutiple services extends using one class
@@ -73,8 +105,8 @@
/**
* To init all the services in application scope
*
- * @param serviceGroupContext
- * @throws AxisFault
+ * @param serviceGroupContext the ServiceGroupContext from which to extract all the services
+ * @throws AxisFault if there's a problem initializing
*/
public static void initService(ServiceGroupContext serviceGroupContext) throws AxisFault {
AxisServiceGroup serviceGroup = serviceGroupContext.getDescription();
@@ -92,7 +124,7 @@
((String) implInfoParam.getValue()).trim());
Object serviceImpl = implClass.newInstance();
serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceImpl);
- initServiceClass(serviceImpl, serviceContext);
+ initServiceObject(serviceImpl, serviceContext);
} catch (Exception e) {
AxisFault.makeFault(e);
}
@@ -101,13 +133,20 @@
}
/**
- * To startup service when user puts load-on-startup parameter
+ * Notify a service object that it's on death row.
+ * @param serviceContext the active ServiceContext
*/
-
-
public static void destroyServiceObject(ServiceContext serviceContext) {
Object obj = serviceContext.getProperty(ServiceContext.SERVICE_OBJECT);
if (obj != null) {
+ // If this is a Lifecycle object, just call it.
+ if (obj instanceof Lifecycle) {
+ ((Lifecycle)obj).destroy(serviceContext);
+ return;
+ }
+
+ // For now, we also use "raw" introspection to try and find the destroy method.
+
Class classToLoad = obj.getClass();
Method method =
null;
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java?view=diff&rev=549086&r1=549085&r2=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/receivers/AbstractMessageReceiver.java Wed Jun 20 05:30:42 2007
@@ -218,8 +218,7 @@
// create a new service impl class for that service
serviceimpl = makeNewServiceObject(msgContext);
//Service initialization
- DependencyManager.initServiceClass(serviceimpl,
- msgContext.getServiceContext());
+ DependencyManager.initServiceObject(serviceimpl, msgContext.getServiceContext());
serviceContext.setProperty(ServiceContext.SERVICE_OBJECT, serviceimpl);
return serviceimpl;
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/Lifecycle.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/Lifecycle.java?view=auto&rev=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/Lifecycle.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/service/Lifecycle.java Wed Jun 20 05:30:42 2007
@@ -0,0 +1,47 @@
+package org.apache.axis2.service;
+
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.AxisFault;
+
+/*
+* Copyright 2007 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.
+*/
+
+/**
+ * The Lifecycle interface should be implemented by your back-end service
+ * class if you wish to be notified of creation and cleanup by the Axis2
+ * framework.
+ */
+public interface Lifecycle {
+
+ /**
+ * init() is called when a new instance of the implementing class has been created.
+ * This occurs in sync with session/ServiceContext creation. This method gives classes
+ * a chance to do any setup work (grab resources, establish connections, etc) before
+ * they are invoked by a service request.
+ *
+ * @param context the active ServiceContext
+ * @throws AxisFault if something goes wrong. Throwing a fault here will result in either
+ * failed deployment (for application-scoped services) or failed requests.
+ */
+ void init(ServiceContext context) throws AxisFault;
+
+ /**
+ * destroy() is called when Axis2 decides that it is finished with a particular instance
+ * of the back-end service class. It allows classes to clean up resources.
+ * @param context the active ServiceContext
+ */
+ void destroy(ServiceContext context);
+}
Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/LocalTestCase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/LocalTestCase.java?view=auto&rev=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/LocalTestCase.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/LocalTestCase.java Wed Jun 20 05:30:42 2007
@@ -0,0 +1,193 @@
+/*
+ * Copyright 2007 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.
+ */
+package org.apache.axis2;
+
+import junit.framework.TestCase;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Phase;
+import org.apache.axis2.engine.DispatchPhase;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.transport.local.LocalTransportSender;
+import org.apache.axis2.transport.local.LocalTransportReceiver;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver;
+import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
+import org.apache.axis2.deployment.util.Utils;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axiom.soap.SOAP12Constants;
+
+import java.util.ArrayList;
+
+/**
+ * LocalTestCase is an extendable base class which provides common functionality
+ * for building JUnit tests which exercise Axis2 using the (fast, in-process)
+ * "local" transport.
+ */
+public class LocalTestCase extends TestCase {
+ /** Our server AxisConfiguration */
+ protected ConfigurationContext serverCtx;
+ protected AxisConfiguration serverConfig;
+
+ /** Our client ConfigurationContext */
+ protected ConfigurationContext clientCtx;
+
+ LocalTransportSender sender = new LocalTransportSender();
+
+ protected void setUp() throws Exception {
+ // Configuration - server side
+ serverCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null);
+ serverConfig = serverCtx.getAxisConfiguration();
+ LocalTransportReceiver.CONFIG_CONTEXT = new ConfigurationContext(serverConfig);
+ LocalTransportReceiver.CONFIG_CONTEXT.setServicePath("services");
+ LocalTransportReceiver.CONFIG_CONTEXT.setContextRoot("local:/");
+ TransportOutDescription tOut = new TransportOutDescription(Constants.TRANSPORT_LOCAL);
+ tOut.setSender(new LocalTransportSender());
+ serverConfig.addTransportOut(tOut);
+
+// addInPhases(serverConfig.getInFlowPhases());
+// DispatchPhase dp = (DispatchPhase)serverConfig.getInFlowPhases().get(1);
+// dp.addHandler(new AddressingBasedDispatcher());
+//
+// addInPhases(serverConfig.getInFaultFlowPhases());
+//
+// addOutPhases(serverConfig.getOutFlowPhases());
+// addOutPhases(serverConfig.getOutFaultFlowPhases());
+
+ ///////////////////////////////////////////////////////////////////////
+ // Set up raw message receivers for OMElement based tests
+
+ serverConfig.addMessageReceiver(WSDL2Constants.MEP_URI_IN_ONLY,
+ new RawXMLINOnlyMessageReceiver());
+ serverConfig.addMessageReceiver(WSDL2Constants.MEP_URI_IN_OUT,
+ new RawXMLINOutMessageReceiver());
+ serverConfig.addMessageReceiver(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
+ new RawXMLINOutMessageReceiver());
+
+ ///////////////////////////////////////////////////////////////////////
+ // And client side
+ clientCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null);
+ }
+
+ /**
+ * Add well-known Phases on the in side
+ *
+ * @param flow the Flow in which to add these Phases
+ */
+ private void addInPhases(ArrayList flow) {
+ flow.add(new Phase("PreDispatch"));
+ Phase dispatchPhase = new DispatchPhase("Dispatch");
+ flow.add(dispatchPhase);
+ }
+
+ /**
+ * Add well-known Phases on the out side
+ *
+ * @param flow the Flow in which to add these Phases
+ */
+ private void addOutPhases(ArrayList flow) {
+ flow.add(new Phase("MessageOut"));
+ }
+
+ /**
+ * Deploy a class as a service.
+ *
+ * @param name the service name
+ * @param myClass the Java class to deploy (all methods exposed by default)
+ * @return a fully configured AxisService, already deployed into the server
+ * @throws Exception in case of problems
+ */
+ protected AxisService deployClassAsService(String name, Class myClass) throws Exception {
+ return deployClassAsService(name, myClass, null);
+ }
+
+ /**
+ * Deploy a class as a service.
+ *
+ * @param name the service name
+ * @param myClass the Java class to deploy (all methods exposed by default)
+ * @param scope the service scope
+ * @return a fully configured AxisService, already deployed into the server
+ * @throws Exception in case of problems
+ */
+ protected AxisService deployClassAsService(String name, Class myClass, String scope)
+ throws Exception {
+ AxisService service = new AxisService(name);
+ if (scope != null) service.setScope(scope);
+
+ service.addParameter(Constants.SERVICE_CLASS,
+ myClass.getName());
+
+ Utils.fillAxisService(service, serverConfig, null, null);
+
+ serverCtx.deployService(service);
+ return service;
+ }
+
+ /**
+ * Get a pre-initialized ServiceClient set up to talk to our local
+ * server. If you want to set options, call this and then use getOptions()
+ * on the return.
+ *
+ * @return a ServiceClient, pre-initialized to talk using our local sender
+ * @throws org.apache.axis2.AxisFault if there's a problem
+ */
+ protected ServiceClient getClient() throws AxisFault {
+ Options opts = getOptions();
+ ServiceClient client = new ServiceClient(clientCtx, null);
+ client.setOptions(opts);
+ return client;
+ }
+
+ /**
+ * Get a pre-initialized ServiceClient set up to talk to our local
+ * server. If you want to set options, call this and then use getOptions()
+ * on the return. Clients created using this method have their To EPR
+ * preset to include the address for the service+operation.
+ *
+ * @return a ServiceClient, pre-initialized to talk using our local sender
+ * @throws org.apache.axis2.AxisFault if there's a problem
+ */
+ protected ServiceClient getClient(String serviceName, String operationName) throws AxisFault {
+ String url = LocalTransportReceiver.CONFIG_CONTEXT.getServiceContextPath()+"/"+serviceName;
+
+ Options opts = getOptions();
+ opts.setTo(new EndpointReference(url));
+ opts.setAction(operationName);
+ ServiceClient client = new ServiceClient(clientCtx, null);
+ client.setOptions(opts);
+ return client;
+ }
+
+ /**
+ * Get an Options object initialized with the right transport info, defaulting to SOAP 1.2
+ *
+ * @return pre-initialized Options object
+ */
+ protected Options getOptions() {
+ TransportOutDescription td = new TransportOutDescription("local");
+ td.setSender(sender);
+
+ Options opts = new Options();
+ opts.setTransportOut(td);
+ opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ return opts;
+ }
+}
Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/LifecycleTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/LifecycleTest.java?view=auto&rev=549086
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/LifecycleTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/deployment/LifecycleTest.java Wed Jun 20 05:30:42 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2007 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.
+ */
+package org.apache.axis2.deployment;
+
+import org.apache.axis2.LocalTestCase;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.service.Lifecycle;
+
+public class LifecycleTest extends LocalTestCase {
+ static public class Service implements Lifecycle {
+ static boolean initCalled, destroyCalled;
+
+ public void init(ServiceContext context) throws AxisFault {
+ initCalled = true;
+ }
+
+ public void destroy(ServiceContext context) {
+ destroyCalled = true;
+ }
+ }
+
+ public void testServiceObjectLifecycle() throws Exception {
+ deployClassAsService("lifecycle", Service.class, Constants.SCOPE_APPLICATION);
+ assertTrue("init() not called!", Service.initCalled);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org