You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2005/09/21 11:30:17 UTC
svn commit: r290664 - in /webservices/axis2/trunk/java/modules/core:
src/org/apache/axis2/context/ src/org/apache/axis2/deployment/
src/org/apache/axis2/engine/ test-resources/deployment/serviceGroupRepo/
test/org/apache/axis2/context/
Author: deepal
Date: Wed Sep 21 02:29:53 2005
New Revision: 290664
URL: http://svn.apache.org/viewcvs?rev=290664&view=rev
Log:
integrate Context serialization into axis2
Added:
webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/context/ContextSerailzationWithEngine.java
Modified:
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/axis2.xml
webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java
webservices/axis2/trunk/java/modules/core/test-resources/deployment/serviceGroupRepo/axis2.xml
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java?rev=290664&r1=290663&r2=290664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/ConfigurationContextFactory.java Wed Sep 21 02:29:53 2005
@@ -3,10 +3,7 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.deployment.DeploymentException;
-import org.apache.axis2.description.ModuleDescription;
-import org.apache.axis2.description.ServiceDescription;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.*;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.AxisConfigurationImpl;
import org.apache.axis2.modules.Module;
@@ -14,15 +11,20 @@
import org.apache.axis2.phaseresolver.PhaseResolver;
import org.apache.axis2.transport.TransportListener;
import org.apache.axis2.transport.TransportSender;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.io.*;
public class ConfigurationContextFactory {
+ private Log log = LogFactory.getLog(getClass());
+
/**
* Build the configuration for the Server
* @param repositoryName
@@ -38,7 +40,32 @@
new DeploymentEngine(repositoryName);
AxisConfiguration configuration = deploymentEngine.load();
PhaseResolver phaseResolver = new PhaseResolver(configuration);
- configurationContext = new ConfigurationContext(configuration);
+
+ Parameter parameter = configuration.getParameter("seralizeLocation");
+ String serailzeLocaion = ".";
+ if (parameter !=null) {
+ serailzeLocaion = ((String)parameter.getValue()).trim();
+ }
+ File objFile = new File(serailzeLocaion,"Axis2.obj");
+ if(objFile.exists()){
+ try {
+ FileInputStream filein = new FileInputStream(objFile);
+ ObjectInputStream in = new ObjectInputStream(filein);
+ Object obj = in.readObject();
+ if(obj instanceof ConfigurationContext){
+ configurationContext = (ConfigurationContext)obj;
+ configurationContext.init(configuration);
+ }
+ } catch (IOException e) {
+ log.info(e.getMessage());
+ } catch (ClassNotFoundException e) {
+ log.info(e.getMessage());
+ }
+ }
+ if(configurationContext == null){
+ configurationContext = new ConfigurationContext(configuration);
+ }
+// configurationContext = new ConfigurationContext(configuration);
phaseResolver.buildTranspotsChains();
initModules(configurationContext);
initTransports(configurationContext);
@@ -63,7 +90,28 @@
AxisConfiguration configuration =
new DeploymentEngine().loadClient(axis2home);
PhaseResolver phaseResolver = new PhaseResolver(configuration);
- engineContext = new ConfigurationContext(configuration);
+
+ File objFile = new File("./Axis2.obj");
+ if(objFile.exists()){
+ try {
+ FileInputStream filein = new FileInputStream(objFile);
+ ObjectInputStream in = new ObjectInputStream(filein);
+ Object obj = in.readObject();
+ if(obj instanceof ConfigurationContext){
+ engineContext = (ConfigurationContext)obj;
+ engineContext.init(configuration);
+ }
+ } catch (IOException e) {
+ log.info(e.getMessage());
+ } catch (ClassNotFoundException e) {
+ log.info(e.getMessage());
+ }
+ }
+ if(engineContext == null){
+ engineContext = new ConfigurationContext(configuration);
+ }
+
+// engineContext = new ConfigurationContext(configuration);
phaseResolver.buildTranspotsChains();
initModules(engineContext);
initTransports(engineContext);
@@ -86,7 +134,7 @@
try {
HashMap modules =
((AxisConfigurationImpl) context.getAxisConfiguration())
- .getModules();
+ .getModules();
Collection col = modules.values();
for (Iterator iterator = col.iterator(); iterator.hasNext();) {
ModuleDescription axismodule =
@@ -128,7 +176,7 @@
throw new PhaseException(axisFault);
}
}
-
+
/**
* This method initilize the transports, passing the information taken from the
* deployment to the real instance, for and example here the <code>TransportSender</code>
@@ -139,7 +187,7 @@
public void initTransports(ConfigurationContext configContext)
throws AxisFault {
AxisConfiguration axisConf = configContext.getAxisConfiguration();
-
+
//Initzialize Transport Ins
HashMap transportIns = axisConf.getTransportsIn();
Iterator values = transportIns.values().iterator();
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java?rev=290664&r1=290663&r2=290664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/OperationContext.java Wed Sep 21 02:29:53 2005
@@ -73,7 +73,8 @@
public void init(AxisConfiguration axisConfiguration) throws AxisFault {
if (operationDescName!=null && serviceDescName!=null){
- axisOperation = axisConfiguration.getService(serviceDescName.getLocalPart()).
+ //todo this lead to NPE : Chamikara
+ axisOperation = axisConfiguration.getService(serviceDescName.getLocalPart()).
getOperation(operationDescName);
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/axis2.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/axis2.xml?rev=290664&r1=290663&r2=290664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/deployment/axis2.xml Wed Sep 21 02:29:53 2005
@@ -12,6 +12,9 @@
<parameter name="userName" locked="false">admin</parameter>
<parameter name="password" locked="false">axis2</parameter>
+ <parameter name="seralizeLocation" locked="false">.</parameter>
+
+
<!--if you want to extract the service archive file and work with that please uncomment this-->
<!--else , it wont extract archive file or does not take into consideration if someone drop-->
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java?rev=290664&r1=290663&r2=290664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/engine/AxisEngine.java Wed Sep 21 02:29:53 2005
@@ -23,6 +23,7 @@
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.OperationDescription;
import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.Parameter;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.om.OMAbstractFactory;
import org.apache.axis2.soap.SOAP11Constants;
@@ -39,6 +40,7 @@
import org.apache.commons.logging.LogFactory;
import java.util.ArrayList;
+import java.io.*;
/**
* There is one engine for the Server and the Client. the send() and receive()
@@ -140,7 +142,7 @@
operationDescription.getRemainingPhasesInFlow();
invokePhases(operationSpecificPhases, msgContext);
}
-
+
if (msgContext.isServerSide() && !msgContext.isPaused()) {
// invoke the Message Receivers
MessageReceiver receiver =
@@ -403,7 +405,7 @@
}else{
fault.setException(new Exception(e));
}
-
+
}
}
@@ -497,7 +499,7 @@
public boolean clearStorage(ConfigurationContext context) {
return context.getStorage().clean();
}
-
+
private String getSenderFaultCode(String soapNamespace) {
@@ -512,6 +514,28 @@
soapNamespace)
? SOAP12Constants.FAULT_CODE_RECEIVER
: SOAP11Constants.FAULT_CODE_RECEIVER;
+ }
+
+ /**
+ * To serilze the entier context heirarachy to a given location from top to bottom
+ * @throws AxisFault
+ */
+ public synchronized void serialize() throws AxisFault{
+ try {
+ String serailzeLocaion =".";
+ //output location
+ Parameter parameter = engineContext.getAxisConfiguration().getParameter("seralizeLocation");
+ if (parameter !=null) {
+ serailzeLocaion = ((String)parameter.getValue()).trim();
+ }
+ FileOutputStream fileOut = new FileOutputStream(new File(serailzeLocaion,"Axis2.obj"));
+ ObjectOutputStream out = new ObjectOutputStream(fileOut);
+ out.writeObject(engineContext);
+ } catch (FileNotFoundException e) {
+ throw new AxisFault(e);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/core/test-resources/deployment/serviceGroupRepo/axis2.xml
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/test-resources/deployment/serviceGroupRepo/axis2.xml?rev=290664&r1=290663&r2=290664&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/test-resources/deployment/serviceGroupRepo/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/core/test-resources/deployment/serviceGroupRepo/axis2.xml Wed Sep 21 02:29:53 2005
@@ -12,8 +12,7 @@
<parameter name="userName" locked="false">admin</parameter>
<parameter name="password" locked="false">axis2</parameter>
-
-
+ <parameter name="seralizeLocation" locked="false">./target</parameter>
<!-- ================================================= -->
Added: webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/context/ContextSerailzationWithEngine.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/context/ContextSerailzationWithEngine.java?rev=290664&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/context/ContextSerailzationWithEngine.java (added)
+++ webservices/axis2/trunk/java/modules/core/test/org/apache/axis2/context/ContextSerailzationWithEngine.java Wed Sep 21 02:29:53 2005
@@ -0,0 +1,142 @@
+package org.apache.axis2.context;
+
+import junit.framework.TestCase;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.addressing.miheaders.RelatesTo;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.description.ServiceGroupDescription;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.description.OperationDescription;
+import org.apache.axis2.AxisFault;
+import org.apache.wsdl.WSDLConstants;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+/*
+* Copyright 2004,2005 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.
+*
+*
+*/
+
+/**
+ * Author: Deepal Jayasinghe
+ * Date: Sep 21, 2005
+ * Time: 2:17:36 PM
+ */
+public class ContextSerailzationWithEngine extends TestCase {
+ String repo ="./test-resources/deployment/serviceGroupRepo";
+
+
+ final String SERVICE_NAME = "service1";
+ final String OPERATION_NAME = "op1";
+ final String SERVICE_GROUP_NAME = "serviceGroup";
+ final String SERVICE_GROUP_CONTEXT_ID = "serviceGroupCtxId";
+ final String MSG1_ID = "msgid1";
+ final String MSG2_ID = "msgid2";
+
+ AxisConfiguration axisConfiguration;
+ AxisConfiguration newaxisConfiguration;
+ ServiceGroupDescription serviceGroupDescription;
+ ServiceDescription serviceDescription;
+ OperationDescription operationDescription;
+
+ QName serviceDescQName = new QName (SERVICE_NAME);
+ QName operationDescName = new QName (OPERATION_NAME);
+
+ public void testSerialization(){
+ try {
+ ConfigurationContextFactory builder = new ConfigurationContextFactory();
+ ConfigurationContext configurationContext = builder.buildConfigurationContext(repo);
+ axisConfiguration =configurationContext.getAxisConfiguration();
+
+ serviceGroupDescription = axisConfiguration.getServiceGroup(SERVICE_GROUP_NAME);
+ serviceDescription = axisConfiguration.getService(SERVICE_NAME);
+ ServiceGroupContext serviceGroupContext = serviceDescription.getParent().getServiceGroupContext(configurationContext);
+ serviceGroupContext.setId(SERVICE_GROUP_CONTEXT_ID);
+ configurationContext.registerServiceGroupContext(serviceGroupContext);
+ ServiceContext serviceContext = serviceGroupContext.getServiceContext(serviceDescription.getName().getLocalPart());
+
+ operationDescription = serviceDescription.getOperation(operationDescName);
+ //setting message contexts
+ MessageContext inMessage = new MessageContext(configurationContext);
+ MessageContext outMessage = new MessageContext(configurationContext);
+ inMessage.setMessageID(MSG1_ID);
+ outMessage.setMessageID(MSG2_ID);
+ outMessage.setRelatesTo(new RelatesTo (MSG1_ID));
+ inMessage.setServiceGroupContextId(SERVICE_GROUP_CONTEXT_ID);
+ outMessage.setServiceGroupContextId(SERVICE_GROUP_CONTEXT_ID);
+ inMessage.setServiceGroupContext(serviceGroupContext);
+ outMessage.setServiceGroupContext(serviceGroupContext);
+ inMessage.setServiceContext(serviceContext);
+ outMessage.setServiceContext(serviceContext);
+ inMessage.setOperationDescription(operationDescription);
+ outMessage.setOperationDescription(operationDescription);
+
+ OperationContext operationContext = operationDescription.findOperationContext(inMessage,serviceContext);
+ operationContext.addMessageContext(outMessage);
+ outMessage.setOperationContext(operationContext);
+
+ configurationContext.registerOperationContext(inMessage.getMessageID(),operationContext);
+ configurationContext.registerOperationContext(outMessage.getMessageID(),operationContext);
+
+ AxisEngine engine = new AxisEngine(configurationContext);
+ engine.serialize();
+
+ configurationContext = null;
+
+ /////////////////////////////
+
+ ConfigurationContext newConfigContext = builder.buildConfigurationContext(repo);
+ newaxisConfiguration = newConfigContext.getAxisConfiguration();
+
+
+ assertFalse(newConfigContext.getOperationContextMap().isEmpty());
+
+ ServiceGroupContext serviceGroupcontext1 = newConfigContext.fillServiceContextAndServiceGroupContext(inMessage);
+ assertNotNull (serviceGroupcontext1);
+
+ serviceGroupcontext1 = newConfigContext.fillServiceContextAndServiceGroupContext(outMessage);
+ assertNotNull (serviceGroupcontext1);
+
+ ServiceContext serviceContext1 = serviceGroupContext.getServiceContext(SERVICE_NAME);
+ assertNotNull(serviceContext1);
+
+ OperationContext operationContext1 = newConfigContext.getOperationContext(MSG1_ID);
+ assertNotNull(operationContext1);
+
+ assertNotNull(operationContext1.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN));
+ assertNotNull(operationContext1.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT));
+
+
+ //Assertions to check weather description hierarchy is set correctly.
+ AxisConfiguration axisConfiguration1 = newConfigContext.getAxisConfiguration();
+ assertNotNull(axisConfiguration1);
+
+ assertNotNull(operationContext1.getAxisOperation());
+ assertNotNull(serviceGroupcontext1.getDescription());
+ assertNotNull(serviceContext1.getServiceConfig());
+
+
+
+
+ } catch (DeploymentException e) {
+ fail("This can not fail by DeploymentException");
+ } catch (AxisFault axisFault) {
+ axisFault.printStackTrace();
+ fail("This can not fail by AxisFault");
+ }
+ }
+}