Author: ngallardo
Date: Mon Apr 16 07:19:05 2007
New Revision: 529258
URL: http://svn.apache.org/viewvc?view=rev&rev=529258
Log:
AXIS2-2532
Adding an implementation of the LogicalMessage with some initial tests.
Added:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java?view=diff&rev=529258&r1=529257&r2=529258
==============================================================================
---
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
(original)
+++
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
Mon Apr 16 07:19:05 2007
@@ -19,6 +19,7 @@
package org.apache.axis2.jaxws.handler;
import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.Message;
import javax.xml.ws.LogicalMessage;
@@ -29,6 +30,8 @@
public class LogicalMessageContext extends ProtectedMessageContext
implements javax.xml.ws.handler.LogicalMessageContext {
+ private LogicalMessage message;
+
public LogicalMessageContext() {
super();
}
@@ -38,10 +41,10 @@
}
public LogicalMessage getMessage() {
- return null;
- }
-
- public LogicalMessage getSource() {
- return null;
+ if (message == null) {
+ Message msg = getMessageObject();
+ message = new LogicalMessageImpl(msg);
+ }
+ return message;
}
}
Added:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java?view=auto&rev=529258
==============================================================================
---
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
(added)
+++
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageImpl.java
Mon Apr 16 07:19:05 2007
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.jaxws.handler;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.WebServiceException;
+
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+public class LogicalMessageImpl implements LogicalMessage {
+
+ private Message message;
+
+ public LogicalMessageImpl(Message m) {
+ message = m;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.ws.LogicalMessage#getPayload()
+ */
+ public Source getPayload() {
+ BlockFactory factory = (SourceBlockFactory)
FactoryRegistry.getFactory(SourceBlockFactory.class);
+ Source payload = (Source) _getPayload(null, factory);
+ return payload;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.ws.LogicalMessage#getPayload(javax.xml.bind.JAXBContext)
+ */
+ public Object getPayload(JAXBContext context) {
+ BlockFactory factory = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
+ Object payload = _getPayload(context, factory);
+ return payload;
+ }
+
+ private Object _getPayload(Object context, BlockFactory factory) {
+ Object payload = null;
+ try {
+ Block block = message.getBodyBlock(context, factory);
+ payload = block.getBusinessObject(true);
+
+ // For now, we have to create a new Block from the original content
+ // and set that back on the message. The Block is not currently
+ // able to create a copy of itself just yet.
+ Block cacheBlock = factory.createFrom(payload, context,
block.getQName());
+ message.setBodyBlock(cacheBlock);
+ } catch (WebServiceException e) {
+ ExceptionFactory.makeWebServiceException(e);
+ } catch (XMLStreamException e) {
+ ExceptionFactory.makeWebServiceException(e);
+ }
+
+ return payload;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.ws.LogicalMessage#setPayload(java.lang.Object,
javax.xml.bind.JAXBContext)
+ */
+ public void setPayload(Object obj, JAXBContext context) {
+ BlockFactory factory = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
+ _setPayload(obj, context, factory);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.ws.LogicalMessage#setPayload(javax.xml.transform.Source)
+ */
+ public void setPayload(Source source) {
+ BlockFactory factory = (SourceBlockFactory)
FactoryRegistry.getFactory(SourceBlockFactory.class);
+ _setPayload(source, null, factory);
+ }
+
+ private void _setPayload(Object object, Object context, BlockFactory
factory) {
+ Block block = factory.createFrom(object, context, null);
+
+ if (message != null) {
+ message.setBodyBlock(block);
+ }
+ }
+}
\ No newline at end of file
Modified:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=529258&r1=529257&r2=529258
==============================================================================
---
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
(original)
+++
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
Mon Apr 16 07:19:05 2007
@@ -38,6 +38,7 @@
import org.apache.axis2.jaxws.dispatch.SOAP12Dispatch;
import org.apache.axis2.jaxws.exception.ExceptionFactoryTests;
import org.apache.axis2.jaxws.handler.HandlerChainProcessorTests;
+import org.apache.axis2.jaxws.handler.context.LogicalMessageContextTests;
import org.apache.axis2.jaxws.i18n.JaxwsMessageBundleTests;
import org.apache.axis2.jaxws.injection.ResourceInjectionTests;
import org.apache.axis2.jaxws.lifecycle.EndpointLifecycleTests;
@@ -123,6 +124,7 @@
suite.addTestSuite(MTOMSerializationTests.class);
suite.addTestSuite(BindingToProtocolTests.class);
+ // ------ Metadata Tests ------
suite.addTestSuite(WSDLTests.class);
suite.addTestSuite(WSDLDescriptionTests.class);
suite.addTestSuite(AnnotationDescriptionTests.class);
@@ -130,7 +132,11 @@
suite.addTestSuite(ServiceTests.class);
suite.addTestSuite(PortSelectionTests.class);
+ // ------ Handler Tests ------
+ suite.addTestSuite(LogicalMessageContextTests.class);
suite.addTestSuite(HandlerChainProcessorTests.class);
+
+ // ------ Message Tests ------
suite.addTestSuite(JaxwsMessageBundleTests.class);
suite.addTestSuite(StringProviderTests.class);
Added:
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
URL:
http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java?view=auto&rev=529258
==============================================================================
---
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
(added)
+++
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/LogicalMessageContextTests.java
Mon Apr 16 07:19:05 2007
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.jaxws.handler.context;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.LogicalMessage;
+import javax.xml.ws.handler.LogicalMessageContext;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.Protocol;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+import test.EchoString;
+import test.ObjectFactory;
+
+/**
+ * Unit tests for the creation and usage of the LogicalMessageContext that is
+ * used for handler processing.
+ */
+public class LogicalMessageContextTests extends TestCase {
+
+ private final String INPUT = "sample input";
+
+ public LogicalMessageContextTests(String name) {
+ super(name);
+ }
+
+ /**
+ * Test the javax.xml.transform.Source based APIs on the LogicalMessage
interface.
+ * @throws Exception
+ */
+ public void testLogicalMessageContextWithSource() throws Exception {
+ MessageContext mc = createSampleMessageContext();
+ LogicalMessageContext lmc =
MessageContextFactory.createLogicalMessageContext(mc);
+
+ LogicalMessage msg = lmc.getMessage();
+ assertTrue("The returned LogicalMessage was null", msg != null);
+
+ Source payload = msg.getPayload();
+ assertTrue("The returned payload (Source) was null", payload != null);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer trans = factory.newTransformer();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(baos);
+
+ trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ trans.transform(payload, result);
+
+ String resultContent = new String(baos.toByteArray());
+ assertTrue("The content returned was null", resultContent != null);
+ assertTrue("The content returned was incomplete, unexpected element",
resultContent.indexOf("echoString") > -1);
+ assertTrue("The content returned was incomplete, unexpected content",
resultContent.indexOf(INPUT) > -1);
+ }
+
+ /**
+ * Test the JAXB based APIs on the LogicalMessage interface.
+ * @throws Exception
+ */
+ public void testLogicalMessageContextWithJAXB() throws Exception {
+ MessageContext mc = createSampleMessageContext();
+ LogicalMessageContext lmc =
MessageContextFactory.createLogicalMessageContext(mc);
+
+ LogicalMessage msg = lmc.getMessage();
+ assertTrue("The returned LogicalMessage was null", msg != null);
+
+ JAXBContext jbc = JAXBContext.newInstance("test");
+
+ Object obj = msg.getPayload(jbc);
+ //assertTrue("The returned payload (Object) was null", obj != null);
+ }
+
+ private MessageContext createSampleMessageContext() throws Exception {
+ MessageFactory factory = (MessageFactory)
FactoryRegistry.getFactory(MessageFactory.class);
+ Message msg = factory.create(Protocol.soap11);
+
+ // Create a jaxb object
+ ObjectFactory objFactory = new ObjectFactory();
+ EchoString echo = objFactory.createEchoString();
+ echo.setInput(INPUT);
+
+ // Create the necessary JAXBContext
+ JAXBContext jbc = JAXBContext.newInstance("test");
+ JAXBBlockContext blockCtx = new JAXBBlockContext(jbc);
+
+ // Create the Block
+ JAXBBlockFactory blockFactory = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
+ Block block = blockFactory.createFrom(echo, blockCtx, null);
+
+ msg.setBodyBlock(block);
+
+ MessageContext mc = new MessageContext();
+ mc.setMessage(msg);
+
+ return mc;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]