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 na...@apache.org on 2007/01/11 05:04:33 UTC
svn commit: r495106 [1/10] - in /webservices/axis2/trunk/java/modules:
integration/ integration/test/org/apache/axis2/engine/
integration/test/org/apache/axis2/mtom/
kernel/src/org/apache/axis2/addressing/ kernel/src/org/apache/axis2/client/
kernel/src...
Author: nagy
Date: Wed Jan 10 20:04:31 2007
New Revision: 495106
URL: http://svn.apache.org/viewvc?view=rev&rev=495106
Log:
AXIS2-1567
Contributor: Ann Robinson
Implemented serialization/deserialization routines for contexts
Added:
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/MessageSaveAndRestoreTest.java
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/MessageSaveAndRestoreWithMTOMTest.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/SelfManagedDataManager.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MetaDataEntry.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ObjectStateUtils.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/SelfManagedDataHolder.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextChangeTest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextSaveATest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextSaveBTest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextSaveCTest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/MessageContextSelfManagedDataTest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/OperationContextSaveTest.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/OptionsSaveTest.java
Modified:
webservices/axis2/trunk/java/modules/integration/maven.xml
webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/MessageContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/OperationContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ServiceGroupContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/SessionContext.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisServiceGroup.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/InOnlyAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/InOutAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutInAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/OutOnlyAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/Parameter.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/RobustOutOnlyAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/TwoChannelAxisOperation.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
Modified: webservices/axis2/trunk/java/modules/integration/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/maven.xml?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/integration/maven.xml Wed Jan 10 20:04:31 2007
@@ -602,6 +602,7 @@
<!-- MTOM enabled Repository -->
<mkdir dir="target/test-resources/MTOM-enabledRepository"/>
<mkdir dir="target/test-resources/MTOM-enabledRepository/conf"/>
+ <mkdir dir="target/test-resources/MTOM-enabledRepository/modules"/>
<copy file="test-resources/mtom/MTOM-enabled-axis2.xml"
tofile="target/test-resources/MTOM-enabledRepository/conf/axis2.xml"/>
<copy file="../addressing/target/addressing-${addressing_version}.mar"
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/MessageSaveAndRestoreTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/MessageSaveAndRestoreTest.java?view=auto&rev=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/MessageSaveAndRestoreTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/MessageSaveAndRestoreTest.java Wed Jan 10 20:04:31 2007
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2006 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.engine;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.integration.TestingUtils;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.phaseresolver.PhaseMetadata;
+import org.apache.axis2.util.Utils;
+
+import javax.xml.namespace.QName;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * This tests the saving and restoring of the Axis2 contexts from within a
+ * handler. This is a more thorough test of the serialization mechanisms
+ * than the other unit tests, as the contexts are populated from the beginning
+ * of the Axis2 execution path.
+ */
+public class MessageSaveAndRestoreTest extends UtilServerBasedTestCase implements TestConstants
+{
+ public MessageSaveAndRestoreTest()
+ {
+ super(MessageSaveAndRestoreTest.class.getName());
+ }
+
+ public MessageSaveAndRestoreTest(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ return getTestSetup(new TestSuite(MessageSaveAndRestoreTest.class));
+ }
+
+ protected void setUp() throws Exception
+ {
+ AxisService service = Utils.createSimpleService(TestConstants.serviceName,
+ Echo.class.getName(),
+ TestConstants.operationName);
+ UtilServer.deployService(service);
+
+ AxisOperation operation = service.getOperation(TestConstants.operationName);
+
+ ArrayList phases = new ArrayList();
+ phases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
+ operation.setRemainingPhasesInFlow(phases);
+ ArrayList phase = operation.getRemainingPhasesInFlow();
+ for (int i = 0; i < phase.size(); i++)
+ {
+ Phase phase1 = (Phase)phase.get(i);
+ if (PhaseMetadata.PHASE_POLICY_DETERMINATION.equals(phase1.getPhaseName()))
+ {
+ phase1.addHandler(inboundHandler);
+ }
+ }
+
+ phases = new ArrayList();
+ phases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
+ operation.setPhasesOutFlow(phases);
+ phase = operation.getPhasesOutFlow();
+ for (int i = 0; i < phase.size(); i++)
+ {
+ Phase phase1 = (Phase)phase.get(i);
+ if (PhaseMetadata.PHASE_POLICY_DETERMINATION.equals(phase1.getPhaseName()))
+ {
+ phase1.addHandler(outboundHandler);
+ }
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ UtilServer.unDeployService(TestConstants.serviceName);
+ UtilServer.unDeployClientService();
+ }
+
+ public void testSaveAndRestoreOfMessage() throws Exception
+ {
+ OMElement payload = TestingUtils.createDummyOMElement();
+ Options options = new Options();
+ options.setTo(TestConstants.targetEPR);
+ options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setAction(TestConstants.operationName.getLocalPart());
+ options.setUseSeparateListener(true);
+
+ ConfigurationContext configContext = UtilServer.createClientConfigurationContext();
+
+ ServiceClient sender = new ServiceClient(configContext, null);
+ sender.setOptions(options);
+ sender.engageModule(new QName("addressing"));
+
+ OMElement result = sender.sendReceive(payload);
+
+ TestingUtils.campareWithCreatedOMElement(result);
+ }
+
+ private Handler inboundHandler = new AbstractHandler()
+ {
+ private static final long serialVersionUID = 1L;
+ private String stateProperty = "InboundHandlerState";
+
+ public InvocationResponse invoke(MessageContext messageContext) throws AxisFault
+ {
+ System.out.println("MessageSaveAndRestoreTest:Inbound handler invoked");
+ if (messageContext.getProperty(stateProperty) == null)
+ {
+ System.out.println("MessageSaveAndRestoreTest:Suspending processing");
+ messageContext.setProperty(stateProperty, new Object());
+ messageContext.pause();
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ try
+ {
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+ objectOutputStream.writeObject(messageContext);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+ byteArrayOutputStream.flush();
+ byteArrayOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("An error occurred when serializing the MessageContext");
+ }
+ new Worker(byteArrayOutputStream.toByteArray(), messageContext.getConfigurationContext()).start();
+ return InvocationResponse.SUSPEND;
+ }
+ else
+ {
+ System.out.println("MessageSaveAndRestoreTest:Skipping previously invoked Inbound handler");
+ }
+
+ return InvocationResponse.CONTINUE;
+ }
+ };
+
+ private Handler outboundHandler = new AbstractHandler()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public InvocationResponse invoke(MessageContext messageContext) throws AxisFault
+ {
+ System.out.println("MessageSaveAndRestoreTest:Outbound handler invoked");
+ return InvocationResponse.CONTINUE;
+ }
+ };
+
+ private class Worker extends Thread
+ {
+ private byte[] serializedMessageContext;
+ private ConfigurationContext configurationContext;
+
+ public Worker(byte[] serializedMessageContext, ConfigurationContext configurationContext)
+ {
+ this.serializedMessageContext = serializedMessageContext;
+ this.configurationContext = configurationContext;
+ }
+
+ public void run()
+ {
+ try
+ {
+ System.out.println("MessageSaveAndRestoreTest:Worker thread started");
+ Thread.sleep(5000);
+ AxisEngine axisEngine = new AxisEngine(configurationContext);
+ System.out.println("MessageSaveAndRestoreTest:Resuming processing");
+ ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedMessageContext));
+ MessageContext reconstitutedMessageContext = (MessageContext)objectInputStream.readObject();
+ axisEngine.resume(reconstitutedMessageContext);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An error occurred in the worker thread");
+ }
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java (original)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java Wed Jan 10 20:04:31 2007
@@ -36,8 +36,17 @@
import javax.xml.namespace.QName;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import junit.framework.Test;
@@ -70,6 +79,8 @@
protected void setUp() throws Exception
{
+ //org.apache.log4j.BasicConfigurator.configure();
+
testResults = new ArrayList();
if (!initDone)
@@ -81,10 +92,12 @@
Phase globalInPhase = (Phase)globalInPhases.get(i);
if (PhaseMetadata.PHASE_PRE_DISPATCH.equals(globalInPhase.getPhaseName()))
{
+ System.out.println("Adding handlers to globalInPhase name ["+globalInPhase.getPhaseName()+"] ...");
globalInPhase.addHandler(new TestHandler("In1"));
middleGlobalInHandler = new TestHandler("In2");
globalInPhase.addHandler(middleGlobalInHandler);
globalInPhase.addHandler(new TestHandler("In3"));
+ System.out.println("...done adding handlers to globalInPhase name ["+globalInPhase.getPhaseName()+"] ...");
}
}
}
@@ -169,17 +182,38 @@
/*Since the response is going back separately, we need to give the server
*time to unwind the rest of the invocation.*/
- Thread.sleep(5000);
+ //Thread.sleep(5000);
+ Thread.sleep(7000);
+
+ Iterator it = testResults.iterator();
+ int count = 0;
+ while (it.hasNext())
+ {
+ count ++;
+ String tmp = (String) it.next();
+ System.out.println("Test Results ["+count+"] = ["+tmp+"]");
+ }
+
+ //-----------------------------------------------------------------------
+ // uncomment/comment out the desired results based on whether pausing
+ // the message context
+
+ // expected results when not pausing
+ //List expectedExecutionState = Arrays.asList(new String[] {"In1", "In2", "In3", "In4", "In5", "In6", "Out1", "Out2", "Out3", "FCOut3", "FCOut2", "FCOut1", "FCIn6", "FCIn5", "FCIn4", "FCIn3", "FCIn2", "FCIn1"});
+ // expected results when pausing
List expectedExecutionState = Arrays.asList(new String[] {"In1", "In2", "In2", "In3", "In4", "In5", "In6", "Out1", "Out2", "Out3", "FCOut3", "FCOut2", "FCOut1", "FCIn6", "FCIn5", "FCIn4", "FCIn3", "FCIn2", "FCIn1"});
+ //-----------------------------------------------------------------------
assertEquals(expectedExecutionState, testResults);
+
}
private class TestHandler extends AbstractHandler
{
private String handlerName;
- private boolean shouldFail;
- private boolean shouldPause;
+ private boolean shouldFail = false;
+ private boolean shouldPause = false;
+ private boolean shouldSave = true;
public TestHandler(String handlerName)
{
@@ -188,6 +222,7 @@
public void shouldFail(boolean fail)
{
+ System.out.println("Setting shouldFail to "+fail+" for "+handlerName);
this.shouldFail = fail;
}
@@ -199,50 +234,274 @@
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault
{
- System.out.println("TestHandler " + handlerName + " invoked");
+ String title = "TestHandler["+handlerName+"] ";
+ System.out.println(title+" invoked:");
+
+ // check if the handler should fail
if (shouldFail)
{
- testResults.add("kaboom");
- System.out.println("Handler went kaboom");
- throw new AxisFault("Handler failed");
+ String failmsg = title +" kaboom";
+ System.out.println(title+" adding ["+failmsg+"] to testResults list");
+ testResults.add(failmsg);
+ System.out.println(failmsg);
+ throw new AxisFault(failmsg + " Handler failed");
}
+
+ // add this handler to the list of invoked handlers
+ System.out.println(title+" adding this handler to testResults list");
testResults.add(handlerName);
+
+ boolean isPaused = msgContext.isPaused();
+ if (isPaused)
+ {
+ System.out.println(title+" message context is paused *****");
+ }
+ else
+ {
+ System.out.println(title+" message context is not paused");
+ }
+
+ checkLists(msgContext);
+
+ // check if the handler should pause
if (shouldPause)
{
- System.out.println("Handler pausing");
+ String pausemsg = title +" - pausing the message context";
+ System.out.println(pausemsg);
msgContext.pause();
shouldPause = false;
- new Worker(msgContext).start();
+
+ File theFile = null;
+ String theFilename = null;
+
+ try
+ {
+ theFile = File.createTempFile("pHexec",null);
+ theFilename = theFile.getName();
+ System.out.println(title + "temp file = ["+theFilename+"]");
+ }
+ catch (Exception ex)
+ {
+ System.out.println(title + "error creating temp file = ["+ex.getMessage()+"]");
+ theFile = null;
+ }
+
+ if (theFile != null)
+ {
+ // save to the temporary file
+ try
+ {
+ // setup an output stream to a physical file
+ FileOutputStream outStream = new FileOutputStream(theFile);
+
+ // attach a stream capable of writing objects to the
+ // stream connected to the file
+ ObjectOutputStream outObjStream = new ObjectOutputStream(outStream);
+
+ // try to save the message context
+ System.out.println(title + "saving message context.....");
+ outObjStream.writeObject(msgContext);
+
+ // close out the streams
+ outObjStream.flush();
+ outObjStream.close();
+ outStream.flush();
+ outStream.close();
+
+ System.out.println(title + "....saved message context.....");
+
+ long filesize = theFile.length();
+ System.out.println(title + "file size after save ["+filesize+"] temp file = ["+theFilename+"]");
+
+ new Worker(theFile, msgContext.getConfigurationContext()).start();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("An error occurred when serializing the MessageContext");
+ }
+ }
+ else
+ {
+ // couldn't get a temporary file
+ new Worker(msgContext, msgContext.getConfigurationContext()).start();
+ }
return InvocationResponse.SUSPEND;
- }
+ } // end if should pause
+
return InvocationResponse.CONTINUE;
}
public void flowComplete(MessageContext msgContext)
{
- System.out.println("TestHandler " + handlerName
- + " called for flowComplete()");
+ String title = "TestHandler["+handlerName+"] ";
+ String label = "FC" + handlerName;
+ System.out.println(title + " flowComplete(): adding ["+label+"] to testResults list");
testResults.add("FC" + handlerName);
}
+
+ private void checkLists(MessageContext mc)
+ {
+ if (mc == null)
+ {
+ return;
+ }
+
+ String title = "TestHandler["+handlerName+"] ";
+
+ System.out.println(title + "Checking execution chain.....");
+ ArrayList execList = mc.getExecutionChain();
+ Iterator execIt = null;
+ if (execList != null)
+ {
+ execIt = execList.iterator();
+ }
+ checkHandler(execIt);
+
+ System.out.println(title + "Checking inbound executed phases list.....");
+ Iterator inboundIt = mc.getInboundExecutedPhases();
+ checkHandler(inboundIt);
+
+ System.out.println(title + "Checking outbound executed phases list.....");
+ Iterator outboundIt = mc.getOutboundExecutedPhases();
+ checkHandler(outboundIt);
+ }
+
+ private void checkHandler(Iterator it)
+ {
+ if (it == null)
+ {
+ return;
+ }
+
+ while (it.hasNext())
+ {
+ Handler handler = (Handler) it.next();
+
+ if (handler instanceof Handler)
+ {
+ System.out.println("Handler name ["+handler.getName()+"]");
+ }
+ else if (handler instanceof Phase)
+ {
+ Phase phase = (Phase) handler;
+ System.out.println("Phase name ["+phase.getName()+"]");
+
+ ArrayList list2 = phase.getHandlers();
+ Iterator it2 = list2.iterator();
+ checkHandler(it2);
+ }
+ }
+
+ }
+
+
}
private class Worker extends Thread
{
- private MessageContext msgContext;
+ private byte[] serializedMessageContext = null;
+ private ConfigurationContext configurationContext = null;
+ private File theFile = null;
+ private String theFilename = null;
+ private MessageContext msgContext = null;
public Worker(MessageContext msgContext)
{
this.msgContext = msgContext;
+ this.configurationContext = msgContext.getConfigurationContext();
}
+ public Worker(byte[] serializedMessageContext, ConfigurationContext configurationContext)
+ {
+ this.serializedMessageContext = serializedMessageContext;
+ this.configurationContext = configurationContext;
+ }
+
+ public Worker(File theFile, ConfigurationContext configurationContext)
+ {
+ this.theFile = theFile;
+ this.configurationContext = configurationContext;
+ }
+
+ public Worker(MessageContext mc, ConfigurationContext configurationContext)
+ {
+ this.msgContext = mc;
+ this.configurationContext = configurationContext;
+ }
+
+
public void run()
{
try
{
System.out.println("Worker thread started");
Thread.sleep(5000);
- AxisEngine axisEngine = new AxisEngine(msgContext.getConfigurationContext());
- axisEngine.resume(msgContext);
+ AxisEngine axisEngine = new AxisEngine(configurationContext);
+
+ FileInputStream inStream = null;
+ ObjectInputStream objectInputStream = null;
+ MessageContext reconstitutedMessageContext = null;
+
+ if (theFile != null)
+ {
+ // setup an input stream to the file
+ inStream = new FileInputStream(theFile);
+
+ // attach a stream capable of reading objects from the
+ // stream connected to the file
+ objectInputStream = new ObjectInputStream(inStream);
+
+ System.out.println("Worker thread restoring message context from file");
+ reconstitutedMessageContext = (MessageContext)objectInputStream.readObject();
+ }
+ else if (serializedMessageContext != null)
+ {
+ // use the byte array
+ objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedMessageContext));
+
+ System.out.println("Worker thread restoring message context from byte array");
+ reconstitutedMessageContext = (MessageContext)objectInputStream.readObject();
+ }
+ else if (msgContext != null)
+ {
+ System.out.println("Worker thread using message context");
+ reconstitutedMessageContext = msgContext;
+ }
+
+ if (inStream != null)
+ {
+ inStream.close();
+ }
+
+ if (objectInputStream != null)
+ {
+ objectInputStream.close();
+ }
+
+ if (theFile != null)
+ {
+ // remove the temporary file
+ try
+ {
+ theFile.delete();
+ }
+ catch (Exception e)
+ {
+ // just absorb it
+ }
+ }
+
+ if (reconstitutedMessageContext != null)
+ {
+ System.out.println("Worker thread resuming message context");
+ axisEngine.resume(reconstitutedMessageContext);
+ }
+ else
+ {
+ fail("An error occurred in the worker thread - no message context");
+ }
+
}
catch (Exception e)
{
Added: webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/MessageSaveAndRestoreWithMTOMTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/MessageSaveAndRestoreWithMTOMTest.java?view=auto&rev=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/MessageSaveAndRestoreWithMTOMTest.java (added)
+++ webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/mtom/MessageSaveAndRestoreWithMTOMTest.java Wed Jan 10 20:04:31 2007
@@ -0,0 +1,273 @@
+/*
+ * Copyright 2006 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.mtom;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.engine.Handler;
+import org.apache.axis2.engine.Phase;
+import org.apache.axis2.engine.util.TestConstants;
+import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.integration.UtilServerBasedTestCase;
+import org.apache.axis2.phaseresolver.PhaseMetadata;
+import org.apache.axis2.util.Utils;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.imageio.ImageIO;
+import javax.xml.namespace.QName;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * This tests the saving and restoring of the Axis2 contexts from within a
+ * handler when MTOM is used. This is a more thorough test of the serialization
+ * mechanisms than the other unit tests, as the contexts are populated from the
+ * beginning of the Axis2 codepath.
+ */
+public class MessageSaveAndRestoreWithMTOMTest extends UtilServerBasedTestCase implements TestConstants
+{
+ private OMTextImpl expectedTextData = null;
+
+ public MessageSaveAndRestoreWithMTOMTest()
+ {
+ super(MessageSaveAndRestoreWithMTOMTest.class.getName());
+
+ org.apache.log4j.BasicConfigurator.configure();
+ }
+
+ public MessageSaveAndRestoreWithMTOMTest(String testName)
+ {
+ super(testName);
+
+ org.apache.log4j.BasicConfigurator.configure();
+ }
+
+ public static Test suite()
+ {
+ return getTestSetup2(new TestSuite(MessageSaveAndRestoreWithMTOMTest.class),Constants.TESTING_PATH + "MTOM-enabledRepository");
+ }
+
+ protected void setUp() throws Exception
+ {
+
+ AxisService service = Utils.createSimpleService(TestConstants.serviceName,
+ Echo.class.getName(),
+ TestConstants.operationName);
+ UtilServer.deployService(service);
+
+ AxisOperation operation = service.getOperation(TestConstants.operationName);
+
+ ArrayList phases = new ArrayList();
+ phases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
+ operation.setRemainingPhasesInFlow(phases);
+ ArrayList phase = operation.getRemainingPhasesInFlow();
+ for (int i = 0; i < phase.size(); i++)
+ {
+ Phase phase1 = (Phase)phase.get(i);
+ if (PhaseMetadata.PHASE_POLICY_DETERMINATION.equals(phase1.getPhaseName()))
+ {
+ phase1.addHandler(inboundHandler);
+ }
+ }
+
+ phases = new ArrayList();
+ phases.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
+ operation.setPhasesOutFlow(phases);
+ phase = operation.getPhasesOutFlow();
+ for (int i = 0; i < phase.size(); i++)
+ {
+ Phase phase1 = (Phase)phase.get(i);
+ if (PhaseMetadata.PHASE_POLICY_DETERMINATION.equals(phase1.getPhaseName()))
+ {
+ phase1.addHandler(outboundHandler);
+ }
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ UtilServer.unDeployService(TestConstants.serviceName);
+ UtilServer.unDeployClientService();
+ }
+
+ public void testSaveAndRestoreOfMessage() throws Exception
+ {
+ OMElement payload = createEnvelope();
+
+ Options options = new Options();
+ options.setTo(TestConstants.targetEPR);
+ options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
+ options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ options.setAction(Constants.AXIS2_NAMESPACE_URI+"/"+TestConstants.operationName.getLocalPart());
+ options.setUseSeparateListener(true);
+
+ ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem("target/test-resources/integrationRepo",null);
+
+ ServiceClient sender = new ServiceClient(configurationContext,null);
+ sender.setOptions(options);
+ sender.engageModule(new QName("addressing"));
+
+ OMElement result = sender.sendReceive(payload);
+
+ OMElement element = (OMElement) result.getFirstOMChild();
+ OMText binaryNode = (OMText) element.getFirstOMChild();
+
+ compareWithCreatedOMText(binaryNode);
+
+ DataHandler actualDH = (DataHandler) binaryNode.getDataHandler();
+ BufferedImage bi = ImageIO.read(actualDH.getDataSource().getInputStream());
+ }
+
+ protected OMElement createEnvelope() throws Exception
+ {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ OMNamespace omNamespace = omFactory.createOMNamespace("http://localhost/my", "my");
+ OMElement rpcWrapperElement = omFactory.createOMElement("echoOMElement", omNamespace);
+ OMElement data = omFactory.createOMElement("data", omNamespace);
+
+ FileDataSource fileDataSource = new FileDataSource("test-resources/mtom/test.jpg");
+ DataHandler expectedDataHandler = new DataHandler(fileDataSource);
+ expectedTextData = new OMTextImpl(expectedDataHandler, true, omFactory);
+ data.addChild(expectedTextData);
+ rpcWrapperElement.addChild(data);
+ return rpcWrapperElement;
+
+ }
+
+ protected InputStream getResourceAsStream(String path)
+ {
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
+ }
+
+ protected void compareWithCreatedOMText(OMText actualTextData)
+ {
+ String originalTextValue = expectedTextData.getText();
+ String returnedTextValue = actualTextData.getText();
+ TestCase.assertEquals(returnedTextValue, originalTextValue);
+ }
+
+ private Handler inboundHandler = new AbstractHandler()
+ {
+ private static final long serialVersionUID = 1L;
+ private String stateProperty = "InboundHandlerState";
+
+ public InvocationResponse invoke(MessageContext messageContext) throws AxisFault
+ {
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Inbound handler invoked");
+ if (messageContext.getProperty(stateProperty) == null)
+ {
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Suspending processing");
+ messageContext.setProperty(stateProperty, new Object());
+ messageContext.pause();
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ try
+ {
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+ objectOutputStream.writeObject(messageContext);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+ byteArrayOutputStream.flush();
+ byteArrayOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("An error occurred when serializing the MessageContext");
+ }
+ new Worker(byteArrayOutputStream.toByteArray(), messageContext.getConfigurationContext()).start();
+ }
+ else
+ {
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Skipping previously invoked Inbound handler");
+ }
+ return InvocationResponse.CONTINUE;
+ }
+ };
+
+ private Handler outboundHandler = new AbstractHandler()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public InvocationResponse invoke(MessageContext messageContext) throws AxisFault
+ {
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Outbound handler invoked");
+ return InvocationResponse.CONTINUE;
+ }
+ };
+
+ private class Worker extends Thread
+ {
+ private byte[] serializedMessageContext;
+ private ConfigurationContext configurationContext;
+
+ public Worker(byte[] serializedMessageContext, ConfigurationContext configurationContext)
+ {
+ this.serializedMessageContext = serializedMessageContext;
+ this.configurationContext = configurationContext;
+ }
+
+ public void run()
+ {
+ try
+ {
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Worker thread started");
+ Thread.sleep(5000);
+ AxisEngine axisEngine = new AxisEngine(configurationContext);
+ System.out.println("MessageSaveAndRestoreWithMTOMTest:Resuming processing");
+ ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(serializedMessageContext));
+ MessageContext reconstitutedMessageContext = (MessageContext)objectInputStream.readObject();
+ axisEngine.resume(reconstitutedMessageContext);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ fail("An error occurred in the worker thread");
+ }
+ }
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/EndpointReference.java Wed Jan 10 20:04:31 2007
@@ -409,4 +409,148 @@
}
+ /**
+ * Compares key parts of the state from the current instance of
+ * this class with the specified instance to see if they are
+ * equivalent.
+ * <P>
+ * This differs from the java.lang.Object.equals() method in
+ * that the equals() method generally looks at both the
+ * object identity (location in memory) and the object state
+ * (data).
+ * <P>
+ *
+ * @param epr The object to compare with
+ * @return TRUE if this object is equivalent with the specified object
+ * that is, key fields match
+ * FALSE, otherwise
+ */
+ public boolean isEquivalent(EndpointReference epr)
+ {
+ // NOTE: the input object is expected to exist (ie, be non-null)
+
+ if ((this.name != null) && (epr.getName() != null))
+ {
+ if (!this.name.equals(epr.getName()))
+ {
+ return false;
+ }
+ }
+ else if ((this.name == null) && (epr.getName() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+
+ if ((this.address != null) && (epr.getAddress() != null))
+ {
+ if (!this.address.equals(epr.getAddress()))
+ {
+ return false;
+ }
+ }
+ else if ((this.address == null) && (epr.getAddress() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+
+ // TODO: is a strict test ok to use?
+
+ ArrayList eprMetaData = epr.getMetaData();
+
+ if ( (this.metaData != null) && (eprMetaData != null) )
+ {
+ if (!this.metaData.equals(eprMetaData))
+ {
+ // This is a strict test
+ // Returns true if and only if the specified object
+ // is also a list, both lists have the same size, and
+ // all corresponding pairs of elements in the two lists
+ // are equal, ie, two lists are defined to be equal if
+ // they contain the same elements in the same order.
+
+ return false;
+ }
+ }
+ else if ((this.metaData == null) && (eprMetaData == null))
+ {
+ // keep going
+ }
+ else
+ {
+ // one of the lists is null
+ return false;
+ }
+
+
+
+ ArrayList eprExtensibleElements = epr.getExtensibleElements();
+
+ if ( (this.extensibleElements != null) && (eprExtensibleElements != null) )
+ {
+ if (!this.extensibleElements.equals(eprExtensibleElements))
+ {
+ // This is a strict test
+ // Returns true if and only if the specified object
+ // is also a list, both lists have the same size, and
+ // all corresponding pairs of elements in the two lists
+ // are equal, ie, two lists are defined to be equal if
+ // they contain the same elements in the same order.
+
+ return false;
+ }
+ }
+ else if ((this.extensibleElements == null) && (eprExtensibleElements == null))
+ {
+ // keep going
+ }
+ else
+ {
+ // one of the lists is null
+ return false;
+ }
+
+
+
+ ArrayList eprAttributes = epr.getAttributes();
+
+ if ( (this.attributes != null) && (eprAttributes != null) )
+ {
+ if (!this.attributes.equals(eprAttributes))
+ {
+ // This is a strict test
+ // Returns true if and only if the specified object
+ // is also a list, both lists have the same size, and
+ // all corresponding pairs of elements in the two lists
+ // are equal, ie, two lists are defined to be equal if
+ // they contain the same elements in the same order.
+
+ return false;
+ }
+ }
+ else if ((this.attributes == null) && (eprAttributes == null))
+ {
+ // keep going
+ }
+ else
+ {
+ // one of the lists is null
+ return false;
+ }
+
+ // TODO: check the Map referenceParameters for equivalency
+
+ return true;
+ }
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/client/Options.java Wed Jan 10 20:04:31 2007
@@ -1,3 +1,18 @@
+/*
+ * 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.
+ */
package org.apache.axis2.client;
import org.apache.axiom.om.OMElement;
@@ -7,30 +22,31 @@
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.RelatesTo;
+import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.util.MetaDataEntry;
+import org.apache.axis2.util.ObjectStateUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.xml.namespace.QName;
-import java.util.*;
+import java.io.ByteArrayOutputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-/*
- * 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.
- */
/**
* Holder for operation client options. This is used by the other classes in
@@ -42,20 +58,61 @@
* property inheritance, so that if a property is not set in one instance it
* will check its parent for a setting.
*/
-public class Options {
+public class Options implements Externalizable {
+
+ /*
+ * setup for logging
+ */
+ private static final Log log = LogFactory.getLog(Options.class);
+
+ private static final String myClassName = "Options";
+
+ /**
+ * @serial The serialization version ID tracks the version of the class.
+ * If a class definition changes, then the serialization/externalization
+ * of the class is affected. If a change to the class is made which is
+ * not compatible with the serialization/externalization of the class,
+ * then the serialization version ID should be updated.
+ * Refer to the "serialVer" utility to compute a serialization
+ * version ID.
+ */
+ private static final long serialVersionUID = -8318751890845181507L;
+
+ /**
+ * @serial Tracks the revision level of a class to identify changes to the
+ * class definition that are compatible to serialization/externalization.
+ * If a class definition changes, then the serialization/externalization
+ * of the class is affected.
+ * Refer to the writeExternal() and readExternal() methods.
+ */
+ // supported revision levels, add a new level to manage compatible changes
+ private static final int REVISION_1 = 1;
+ // current revision level of this object
+ private static final int revisionID = REVISION_1;
+
/**
* Default blocking timeout value.
*/
public static final int DEFAULT_TIMEOUT_MILLISECONDS = 30 * 1000;
+
+ /**
+ * @serial parent
+ */
private Options parent;
+
+ /**
+ * @serial properties
+ */
private Map properties = new HashMap();
+
// ==========================================================================
// Parameters that can be set via Options
// ==========================================================================
+
private String soapVersionURI; // defaults to
// SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
@@ -96,9 +153,44 @@
private EndpointReference to;
//To control , session management , default is set to true , if user wants he can set that to true
- // There operation client will manage session using ServiceGroupID if it is there in the response
+ // The operation client will manage session using ServiceGroupID if it is there in the response
private boolean manageSession = false;
+
+ //----------------------------------------------------------------
+ // MetaData for data to be restored in activate after readExternal
+ //----------------------------------------------------------------
+
+ /**
+ * Indicates whether this object has been reconstituted
+ * and needs to have its object references reconciled
+ */
+ private transient boolean needsToBeReconciled = false;
+
+ /**
+ * The TransportOutDescription metadata will be used during
+ * activate to match up with an existing object
+ */
+ private transient MetaDataEntry metaTransportOut = null;
+
+ /**
+ * The TransportInDescription metadata will be used during
+ * activate to match up with an existing object
+ */
+ private transient MetaDataEntry metaTransportIn = null;
+
+ /**
+ * The TransportListener metadata will be used during
+ * activate to match up with an existing object, if possible
+ */
+ private transient MetaDataEntry metaListener = null;
+
+ //----------------------------------------------------------------
+ // end MetaData section
+ //----------------------------------------------------------------
+
+
+
/**
* Default constructor
*/
@@ -158,6 +250,13 @@
* @return listener
*/
public TransportListener getListener() {
+ if (needsToBeReconciled) {
+ if (log.isWarnEnabled()) {
+ log.warn(myClassName+":getListener(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+ //System.out.println(myClassName+":getListener(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+
if (listener == null && parent != null) {
return parent.getListener();
}
@@ -170,6 +269,13 @@
* @return transport information
*/
public TransportInDescription getTransportIn() {
+ if (needsToBeReconciled) {
+ if (log.isWarnEnabled()) {
+ log.warn(myClassName+":getTransportIn(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+ //System.out.println(myClassName+":getTransportIn(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+
if (transportIn == null && parent != null) {
return parent.getTransportIn();
}
@@ -215,6 +321,11 @@
* @return copy of general properties
*/
public Map getProperties() {
+ // make sure that the Options properties exists
+ if (this.properties == null) {
+ this.properties = new HashMap();
+ }
+
if (parent == null) {
return new HashMap(properties);
} else {
@@ -231,6 +342,11 @@
* @return the value related to this key. <code>null</code>, if not found.
*/
public Object getProperty(String key) {
+ // make sure that the Options properties exists
+ if (this.properties == null) {
+ this.properties = new HashMap();
+ }
+
Object myPropValue = properties.get(key);
if (myPropValue == null && parent != null) {
return parent.getProperty(key);
@@ -252,7 +368,10 @@
if (relationships == null && parent != null) {
return parent.getRelatesTo(type);
}
- for (int i = 0; relationships != null && i < relationships.size(); i++) {
+ if (relationships == null) {
+ return null;
+ }
+ for (int i = 0;i < relationships.size(); i++) {
RelatesTo relatesTo = (RelatesTo) relationships.get(i);
String relationshipType = relatesTo.getRelationshipType();
if (relationshipType.equals(type)) {
@@ -273,7 +392,10 @@
if (relationships == null && parent != null) {
return parent.getRelatesTo();
}
- for (int i = 0; relationships != null && i < relationships.size(); i++) {
+ if (relationships == null) {
+ return null;
+ }
+ for (int i = 0;i < relationships.size(); i++) {
RelatesTo relatesTo = (RelatesTo) relationships.get(i);
String relationshipType = relatesTo.getRelationshipType();
if (relationshipType.equals(AddressingConstants.Final.WSA_DEFAULT_RELATIONSHIP_TYPE)
@@ -327,6 +449,13 @@
* @return description
*/
public TransportOutDescription getTransportOut() {
+ if (needsToBeReconciled) {
+ if (log.isWarnEnabled()) {
+ log.warn(myClassName+":getTransportOut(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+ //System.out.println(myClassName+":getTransportOut(): ****WARNING**** Options.activate(configurationContext) needs to be invoked.");
+ }
+
if (transportOut == null && parent != null) {
return parent.getTransportOut();
}
@@ -708,6 +837,10 @@
* @param property
*/
public void setProperty(String propertyKey, Object property) {
+ // make sure that the Options properties exists
+ if (this.properties == null) {
+ this.properties = new HashMap();
+ }
properties.put(propertyKey, property);
}
@@ -892,4 +1025,730 @@
public void setManageSession(boolean manageSession) {
this.manageSession = manageSession;
}
+
+
+
+ /* ===============================================================
+ * Externalizable support
+ * ===============================================================
+ */
+
+ /**
+ * Save the contents of this object.
+ * <p>
+ * NOTE: Transient fields and static fields are not saved.
+ *
+ * @param out The stream to write the object contents to
+ *
+ * @exception IOException
+ */
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ // write out contents of this object
+
+ // NOTES: For each item, where appropriate,
+ // write out the following information, IN ORDER:
+ // the class name
+ // the active or empty flag
+ // the data length, if appropriate
+ // the data
+
+ //---------------------------------------------------------
+ // in order to handle future changes to the message
+ // context definition, be sure to maintain the
+ // object level identifiers
+ //---------------------------------------------------------
+ // serialization version ID
+ out.writeLong(serialVersionUID);
+
+ // revision ID
+ out.writeInt(revisionID);
+
+ //---------------------------------------------------------
+ // various simple fields
+ //---------------------------------------------------------
+ out.writeLong(timeOutInMilliSeconds);
+
+ out.writeBoolean(manageSession);
+
+ // the following objects could be null
+ ObjectStateUtils.writeObject(out, isExceptionToBeThrownOnSOAPFault, "Options.isExceptionToBeThrownOnSOAPFault");
+ ObjectStateUtils.writeObject(out, useSeparateListener, "Options.useSeparateListener");
+
+
+ //---------------------------------------------------------
+ // various strings
+ //---------------------------------------------------------
+
+ // String soapVersionURI
+ ObjectStateUtils.writeString(out, soapVersionURI, "Options.soapVersionURI");
+
+ // String action
+ ObjectStateUtils.writeString(out, action, "Options.action");
+
+ // String transportInProtocol
+ ObjectStateUtils.writeString(out, transportInProtocol, "Options.transportInProtocol");
+
+ // String messageId
+ ObjectStateUtils.writeString(out, messageId, "Options.messageId");
+
+
+ //---------------------------------------------------------
+ // various objects
+ //---------------------------------------------------------
+
+ // EndpointReference faultTo
+ ObjectStateUtils.writeObject(out, faultTo, "Options.faultTo");
+
+ // EndpointReference from
+ ObjectStateUtils.writeObject(out, from, "Options.from");
+
+ // EndpointReference replyTo
+ ObjectStateUtils.writeObject(out, replyTo, "Options.replyTo");
+
+ // EndpointReference to
+ ObjectStateUtils.writeObject(out, to, "Options.to");
+
+
+ // TransportListener listener
+ if (listener != null)
+ {
+ metaListener = new MetaDataEntry(listener.getClass().getName(), null);
+ }
+ else
+ {
+ metaListener = null;
+ }
+ ObjectStateUtils.writeObject(out, metaListener, "Options.listener");
+
+
+ // TransportInDescription transportIn
+ if (transportIn != null)
+ {
+ metaTransportIn = new MetaDataEntry(null, transportIn.getName().toString());
+ }
+ else
+ {
+ metaTransportIn = null;
+ }
+ ObjectStateUtils.writeObject(out, metaTransportIn, "Options.transportIn");
+
+
+ // TransportOutDescription transportOut
+ if (transportOut != null)
+ {
+ metaTransportOut = new MetaDataEntry(null, transportOut.getName().toString());
+ }
+ else
+ {
+ metaTransportOut = null;
+ }
+ ObjectStateUtils.writeObject(out, metaTransportOut, "Options.transportOut");
+
+
+
+
+ //---------------------------------------------------------
+ // collections and lists
+ //---------------------------------------------------------
+
+ // List relationships, which is an array of RelatesTo objects
+ ArrayList tmp = null;
+
+ if (relationships != null)
+ {
+ // make sure this is an array list
+ tmp = new ArrayList(relationships);
+ }
+
+ ObjectStateUtils.writeArrayList(out, tmp, "Options.relationships");
+
+ // ArrayList referenceParameters
+ ObjectStateUtils.writeArrayList(out, referenceParameters, "Options.referenceParameters");
+
+ //---------------------------------------------------------
+ // properties
+ //---------------------------------------------------------
+
+ // HashMap properties
+ HashMap tmpHM = new HashMap(properties);
+
+ ObjectStateUtils.writeHashMap(out, tmpHM, "Options.properties");
+
+
+ //---------------------------------------------------------
+ // "nested"
+ //---------------------------------------------------------
+
+ // Options parent
+ ObjectStateUtils.writeObject(out, parent, "Options.parent");
+
+
+ }
+
+
+ /**
+ * Restore the contents of the MessageContext that was
+ * previously saved.
+ * <p>
+ * NOTE: The field data must read back in the same order and type
+ * as it was written. Some data will need to be validated when
+ * resurrected.
+ *
+ * @param in The stream to read the object contents from
+ *
+ * @exception IOException
+ * @exception ClassNotFoundException
+ */
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ // serialization version ID
+ long suid = in.readLong();
+
+ // revision ID
+ int revID = in.readInt();
+
+ // make sure the object data is in a version we can handle
+ if (suid != serialVersionUID)
+ {
+ throw new ClassNotFoundException(ObjectStateUtils.UNSUPPORTED_SUID);
+ }
+
+ // make sure the object data is in a revision level we can handle
+ if (revID != REVISION_1)
+ {
+ throw new ClassNotFoundException(ObjectStateUtils.UNSUPPORTED_REVID);
+ }
+
+
+ //---------------------------------------------------------
+ // various simple fields
+ //---------------------------------------------------------
+ timeOutInMilliSeconds = in.readLong();
+
+ manageSession = in.readBoolean();
+
+ // the following objects could be null
+ Object tmp1 = ObjectStateUtils.readObject(in, "Options.isExceptionToBeThrownOnSOAPFault");
+ if (tmp1 != null)
+ {
+ isExceptionToBeThrownOnSOAPFault = (Boolean) tmp1;
+ }
+
+ Object tmp2 = ObjectStateUtils.readObject(in, "Options.useSeparateListener");
+ if (tmp2 != null)
+ {
+ useSeparateListener = (Boolean) tmp2;
+ }
+
+
+ //---------------------------------------------------------
+ // various strings
+ //---------------------------------------------------------
+
+ // String soapVersionURI
+ soapVersionURI = ObjectStateUtils.readString(in,"Options.soapVersionURI");
+
+ // String action
+ action = ObjectStateUtils.readString(in, "Options.action");
+
+ // String transportInProtocol
+ transportInProtocol = ObjectStateUtils.readString(in, "Options.transportInProtocol");
+
+ // String messageId
+ messageId = ObjectStateUtils.readString(in, "Options.messageId");
+
+
+ //---------------------------------------------------------
+ // various objects
+ //---------------------------------------------------------
+
+ // EndpointReference faultTo
+ faultTo = (EndpointReference) ObjectStateUtils.readObject(in, "Options.faultTo");
+
+ // EndpointReference from
+ from = (EndpointReference) ObjectStateUtils.readObject(in, "Options.from");
+
+ // EndpointReference replyTo
+ replyTo = (EndpointReference) ObjectStateUtils.readObject(in, "Options.replyTo");
+
+ // EndpointReference to
+ to = (EndpointReference) ObjectStateUtils.readObject(in, "Options.to");
+
+
+ // TransportListener listener
+ // is not usable until the meta data has been reconciled
+ listener = null;
+ metaListener = (MetaDataEntry) ObjectStateUtils.readObject(in, "Options.metaListener");
+
+ // TransportInDescription transportIn
+ // is not usable until the meta data has been reconciled
+ transportIn = null;
+ metaTransportIn = (MetaDataEntry) ObjectStateUtils.readObject(in, "Options.metaTransportIn");
+
+ // TransportOutDescription transportOut
+ // is not usable until the meta data has been reconciled
+ transportOut = null;
+ metaTransportOut = (MetaDataEntry) ObjectStateUtils.readObject(in, "Options.metaTransportOut");
+
+
+ //---------------------------------------------------------
+ // collections and lists
+ //---------------------------------------------------------
+
+ // List relationships, which is an array of RelatesTo objects
+ ArrayList tmpAL1 = ObjectStateUtils.readArrayList(in, "Options.relationships");
+ if (tmpAL1 != null)
+ {
+ relationships = new ArrayList(tmpAL1);
+ }
+ else
+ {
+ relationships = null;
+ }
+
+ // ArrayList referenceParameters
+ ArrayList tmpAL2 = ObjectStateUtils.readArrayList(in, "Options.referenceParameters");
+ if (tmpAL2 != null)
+ {
+ referenceParameters = new ArrayList(tmpAL2);
+ }
+ else
+ {
+ referenceParameters = null;
+ }
+
+ //---------------------------------------------------------
+ // properties
+ //---------------------------------------------------------
+
+ // HashMap properties
+ HashMap tmpHM = ObjectStateUtils.readHashMap(in, "Options.properties");
+
+ if (tmpHM != null)
+ {
+ properties = new HashMap(tmpHM);
+ }
+ else
+ {
+ properties = new HashMap();
+ }
+
+
+ //---------------------------------------------------------
+ // "nested"
+ //---------------------------------------------------------
+
+ // Options parent
+ Object tmpParent = ObjectStateUtils.readObject(in, "Options.parent");
+
+ if (tmpParent != null)
+ {
+ parent = (Options) tmpParent;
+ }
+ else
+ {
+ parent = null;
+ }
+
+
+ }
+
+ /**
+ * This method checks to see if additional work needs to be
+ * done in order to complete the object reconstitution.
+ * Some parts of the object restored from the readExternal()
+ * cannot be completed until we have a configurationContext
+ * from the active engine. The configurationContext is used
+ * to help this object to plug back into the engine's
+ * configuration and deployment objects.
+ *
+ * @param cc The configuration context object representing the active configuration
+ */
+ public void activate(ConfigurationContext cc)
+ {
+ // see if there's any work to do
+ if (needsToBeReconciled == false)
+ {
+ // return quick
+ return;
+ }
+
+ // do a trace point
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+":activate(): BEGIN");
+ }
+ //System.out.println(myClassName+":activate(): BEGIN");
+
+
+ // use the supplied configuration context
+
+ // get the axis configuration
+ AxisConfiguration axisConfig = cc.getAxisConfiguration();
+
+ // We previously saved metaTransportIn; restore it
+ if (metaTransportIn != null)
+ {
+ QName qin = metaTransportIn.getQName();
+ TransportInDescription tmpIn = null;
+ try
+ {
+ tmpIn = axisConfig.getTransportIn(qin);
+ }
+ catch (Exception exin)
+ {
+ // if a fault is thrown, log it and continue
+ log.warn(myClassName+"activate(): exception caught when getting the TransportInDescription ["+qin.toString()+"] from the AxisConfiguration ["+exin.getClass().getName()+" : "+exin.getMessage()+"]");
+
+ //System.out.println(myClassName+"activate(): exception caught when getting the TransportInDescription ["+qin.toString()+"] from the AxisConfiguration ["+exin.getClass().getName()+" : "+exin.getMessage()+"]");
+ }
+
+ if (tmpIn != null)
+ {
+ transportIn = tmpIn;
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): No TransportInDescription found for ["+qin.toString()+"]");
+ }
+
+ //System.out.println(myClassName+"activate(): No TransportInDescription found for ["+qin.toString()+"]");
+
+ transportIn = null;
+ }
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): No TransportInDescription ");
+ }
+
+ //System.out.println(myClassName+"activate(): No TransportInDescription ");
+
+ transportIn = null;
+ }
+
+ // We previously saved metaTransportOut; restore it
+ if (metaTransportOut != null)
+ {
+ QName qout = metaTransportOut.getQName();
+ TransportOutDescription tmpOut = null;
+ try
+ {
+ tmpOut = axisConfig.getTransportOut(qout);
+ }
+ catch (Exception exout)
+ {
+ // if a fault is thrown, log it and continue
+ log.warn(myClassName+"activate(): exception caught when getting the TransportOutDescription ["+qout.toString()+"] from the AxisConfiguration ["+exout.getClass().getName()+" : "+exout.getMessage()+"]");
+
+ //System.out.println(myClassName+"activate(): exception caught when getting the TransportOutDescription ["+qout.toString()+"] from the AxisConfiguration ["+exout.getClass().getName()+" : "+exout.getMessage()+"]");
+ }
+
+ if (tmpOut != null)
+ {
+ transportOut = tmpOut;
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): No TransportOutDescription found for ["+qout.toString()+"]");
+ }
+
+ //System.out.println(myClassName+"activate(): No TransportOutDescription found for ["+qout.toString()+"]");
+
+
+ transportOut = null;
+ }
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): No TransportOutDescription ");
+ }
+
+ //System.out.println(myClassName+"activate(): No TransportOutDescription ");
+
+ transportOut = null;
+ }
+
+
+
+ // We previously saved metaListener; restore it
+ if (metaListener != null)
+ {
+ // see if we can find an existing object
+ String listenerClass = metaListener.getClassName();
+ TransportListener tmpListener = ObjectStateUtils.findTransportListener(axisConfig, listenerClass);
+
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): TransportListener found for ["+listenerClass+"] ");
+ }
+
+ //System.out.println(myClassName+"activate(): TransportListener found for ["+listenerClass+"] ");
+
+ }
+ else
+ {
+ listener = null;
+
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+"activate(): No TransportListener ");
+ }
+
+ //System.out.println(myClassName+"activate(): No TransportListener ");
+ }
+
+
+ //-------------------------------------------------------
+ // done, reset the flag
+ //-------------------------------------------------------
+ needsToBeReconciled = false;
+
+ if (log.isTraceEnabled())
+ {
+ log.trace(myClassName+":activate(): END");
+ }
+
+ //System.out.println(myClassName+":activate(): END");
+ }
+
+
+ /**
+ * Compares key parts of the state from the current instance of
+ * this class with the specified instance to see if they are
+ * equivalent.
+ * <P>
+ * This differs from the java.lang.Object.equals() method in
+ * that the equals() method generally looks at both the
+ * object identity (location in memory) and the object state
+ * (data).
+ * <P>
+ *
+ * @param obj The object to compare with
+ * @return TRUE if this object is equivalent with the specified object
+ * that is, key fields match
+ * FALSE, otherwise
+ */
+ public boolean isEquivalent(Options obj)
+ {
+ // NOTE: the input object is expected to exist (ie, be non-null)
+
+ if (this.timeOutInMilliSeconds != obj.getTimeOutInMilliSeconds())
+ {
+ return false;
+ }
+
+ if (this.isExceptionToBeThrownOnSOAPFault.booleanValue() != obj.isExceptionToBeThrownOnSOAPFault())
+ {
+ return false;
+ }
+
+ if (this.useSeparateListener.booleanValue() != obj.isUseSeparateListener())
+ {
+ return false;
+ }
+
+ if (this.manageSession != obj.isManageSession())
+ {
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.soapVersionURI != null) && (obj.getSoapVersionURI() != null))
+ {
+ if (!this.soapVersionURI.equals(obj.getSoapVersionURI()))
+ {
+ return false;
+ }
+ }
+ else if ((this.soapVersionURI == null) && (obj.getSoapVersionURI() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.action != null) && (obj.getAction() != null))
+ {
+ if (!this.action.equals(obj.getAction()))
+ {
+ return false;
+ }
+ }
+ else if ((this.action == null) && (obj.getAction() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.transportInProtocol != null) && (obj.getTransportInProtocol() != null))
+ {
+ if (!this.transportInProtocol.equals(obj.getTransportInProtocol()))
+ {
+ return false;
+ }
+ }
+ else if ((this.transportInProtocol == null) && (obj.getTransportInProtocol() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.messageId != null) && (obj.getMessageId() != null))
+ {
+ if (!this.messageId.equals(obj.getMessageId()))
+ {
+ return false;
+ }
+ }
+ else if ((this.messageId == null) && (obj.getMessageId() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.faultTo != null) && (obj.getFaultTo() != null))
+ {
+ if (!this.faultTo.isEquivalent(obj.getFaultTo()))
+ {
+ return false;
+ }
+ }
+ else if ((this.faultTo == null) && (obj.getFaultTo() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.from != null) && (obj.getFrom() != null))
+ {
+ if (!this.from.isEquivalent(obj.getFrom()))
+ {
+ return false;
+ }
+ }
+ else if ((this.from == null) && (obj.getFrom() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.replyTo != null) && (obj.getReplyTo() != null))
+ {
+ if (!this.replyTo.isEquivalent(obj.getReplyTo()))
+ {
+ return false;
+ }
+ }
+ else if ((this.replyTo == null) && (obj.getReplyTo() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.to != null) && (obj.getTo() != null))
+ {
+ if (!this.to.isEquivalent(obj.getTo()))
+ {
+ return false;
+ }
+ }
+ else if ((this.to == null) && (obj.getTo() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ if ((this.properties != null) && (obj.getProperties() != null))
+ {
+ if (!this.properties.equals(obj.getProperties()))
+ {
+ // This is a strict test.
+ // Returns true if the given object is also a map
+ // and the two maps represent the same mappings.
+ return false;
+ }
+ }
+ else if ((this.properties == null) && (obj.getProperties() == null))
+ {
+ // continue
+ }
+ else
+ {
+ // mismatch
+ return false;
+ }
+
+ // --------------------------------------------------------------------
+
+ // TODO: consider checking the following objects for equivalency
+ // List relationships;
+ // ArrayList referenceParameters;
+ // TransportListener listener;
+ // TransportInDescription transportIn;
+ // TransportOutDescription transportOut;
+
+ // TODO: consider checking the parent objects for equivalency
+
+
+ return true;
+ }
+
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java?view=diff&rev=495106&r1=495105&r2=495106
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/AbstractContext.java Wed Jan 10 20:04:31 2007
@@ -92,19 +92,39 @@
Boolean copyProperties = ((Boolean) properties.get(COPY_PROPERTIES));
if ((copyProperties != null) && copyProperties.booleanValue()) {
- Iterator iterator = properties.keySet().iterator();
-
- while (iterator.hasNext()) {
- Object key = iterator.next();
-
- this.properties.put(key, properties.get(key));
- }
+ mergeProperties(properties);
} else {
this.properties = properties;
}
}
}
+ /**
+ * This will do a copy of the given properties to the current properties
+ * table.
+ *
+ * @param props The table of properties to copy
+ */
+ public void mergeProperties(Map props) {
+ if (props != null)
+ {
+ Iterator iterator = props.keySet().iterator();
+
+ while (iterator.hasNext()) {
+ Object key = iterator.next();
+
+ if (this.properties == null)
+ {
+ this.properties = new HashMap();
+ }
+
+ this.properties.put(key, props.get(key));
+ }
+
+ }
+ }
+
+
/**
* Store a property for message context
*
@@ -135,4 +155,7 @@
return lastTouchedTime;
}
+ public void setLastTouchedTime(long t) {
+ lastTouchedTime = t;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org