You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/07/02 21:06:15 UTC
svn commit: r552564 - in
/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src:
main/java/org/apache/servicemix/jms/endpoints/
test/java/org/apache/servicemix/jms/
test/resources/org/apache/servicemix/jms/
Author: gnodet
Date: Mon Jul 2 12:06:14 2007
New Revision: 552564
URL: http://svn.apache.org/viewvc?view=rev&rev=552564
Log:
Soap JMS InOut consumer support
Added:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml (with props)
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl (with props)
Modified:
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/JmsSoapConsumerMarshaler.java
incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsConsumerEndpointTest.java
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java?view=diff&rev=552564&r1=552563&r2=552564
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java Mon Jul 2 12:06:14 2007
@@ -18,7 +18,6 @@
import java.util.Iterator;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import javax.jbi.JBIException;
import javax.jbi.messaging.ExchangeStatus;
@@ -36,6 +35,9 @@
import org.apache.servicemix.common.ServiceUnit;
import org.apache.servicemix.common.endpoints.ConsumerEndpoint;
import org.apache.servicemix.jms.endpoints.JmsConsumerMarshaler.JmsContext;
+import org.apache.servicemix.store.Store;
+import org.apache.servicemix.store.StoreFactory;
+import org.apache.servicemix.store.memory.MemoryStoreFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.SessionCallback;
import org.springframework.jms.listener.adapter.ListenerExecutionFailedException;
@@ -52,7 +54,7 @@
private boolean pubSubDomain = false;
private ConnectionFactory connectionFactory;
private JmsTemplate template;
-
+
// Reply properties
private Boolean useMessageIdInResponse;
private Destination replyDestination;
@@ -62,8 +64,9 @@
private int replyPriority = Message.DEFAULT_PRIORITY;
private long replyTimeToLive = Message.DEFAULT_TIME_TO_LIVE;
private Map replyProperties;
-
- private Map<String, JmsContext> pendingExchanges;
+
+ private StoreFactory storeFactory;
+ private Store store;
public AbstractConsumerEndpoint() {
super();
@@ -273,6 +276,22 @@
this.synchronous = synchronous;
}
+ public Store getStore() {
+ return store;
+ }
+
+ public void setStore(Store store) {
+ this.store = store;
+ }
+
+ public StoreFactory getStoreFactory() {
+ return storeFactory;
+ }
+
+ public void setStoreFactory(StoreFactory storeFactory) {
+ this.storeFactory = storeFactory;
+ }
+
public String getLocationURI() {
// TODO: Need to return a real URI
return getService() + "#" + getEndpoint();
@@ -283,20 +302,29 @@
if (template == null) {
template = new JmsTemplate(getConnectionFactory());
}
- pendingExchanges = new ConcurrentHashMap<String, JmsContext>();
+ if (store == null) {
+ if (storeFactory == null) {
+ storeFactory = new MemoryStoreFactory();
+ }
+ store = storeFactory.open(getService().toString() + getEndpoint());
+ }
}
public synchronized void stop() throws Exception {
- pendingExchanges.clear();
- pendingExchanges = null;
+ if (store != null) {
+ if (storeFactory != null) {
+ storeFactory.close(store);
+ }
+ store = null;
+ }
super.stop();
}
-
+
public void process(MessageExchange exchange) throws Exception {
- JmsContext context = pendingExchanges.remove(exchange.getExchangeId());
+ JmsContext context = (JmsContext) store.load(exchange.getExchangeId());
processExchange(exchange, null, context);
}
-
+
protected void processExchange(final MessageExchange exchange, final Session session, final JmsContext context) throws Exception {
// Ignore DONE exchanges
if (exchange.getStatus() == ExchangeStatus.DONE) {
@@ -345,7 +373,7 @@
throw new IllegalStateException("Unrecognized exchange status");
}
}
-
+
protected void send(Message msg, Session session, Destination dest) throws JMSException {
MessageProducer producer = session.createProducer(dest);
try {
@@ -364,7 +392,7 @@
JmsUtils.closeMessageProducer(producer);
}
}
-
+
protected void onMessage(Message jmsMessage, Session session) throws JMSException {
if (logger.isTraceEnabled()) {
logger.trace("Received: " + jmsMessage);
@@ -379,7 +407,7 @@
processExchange(exchange, session, context);
}
} else {
- pendingExchanges.put(exchange.getExchangeId(), context);
+ store.store(exchange.getExchangeId(), context);
send(exchange);
}
} catch (JMSException e) {
@@ -388,7 +416,7 @@
throw (JMSException) new JMSException("Error sending JBI exchange").initCause(e);
}
}
-
+
protected Destination getReplyDestination(MessageExchange exchange, Object message, Session session, JmsContext context) throws JMSException {
// If a JMS ReplyTo property is set, use it
if (context.getMessage().getJMSReplyTo() != null) {
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/JmsSoapConsumerMarshaler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/JmsSoapConsumerMarshaler.java?view=diff&rev=552564&r1=552563&r2=552564
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/JmsSoapConsumerMarshaler.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/main/java/org/apache/servicemix/jms/endpoints/JmsSoapConsumerMarshaler.java Mon Jul 2 12:06:14 2007
@@ -17,9 +17,9 @@
package org.apache.servicemix.jms.endpoints;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringReader;
+import java.io.OutputStream;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.Fault;
@@ -28,11 +28,14 @@
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
+import javax.xml.namespace.QName;
import org.apache.servicemix.soap.api.InterceptorChain;
import org.apache.servicemix.soap.api.Policy;
import org.apache.servicemix.soap.api.InterceptorProvider.Phase;
import org.apache.servicemix.soap.api.model.Binding;
+import org.apache.servicemix.soap.bindings.soap.SoapFault;
+import org.apache.servicemix.soap.bindings.soap.SoapVersion;
import org.apache.servicemix.soap.interceptors.jbi.JbiConstants;
public class JmsSoapConsumerMarshaler implements JmsConsumerMarshaler {
@@ -89,6 +92,7 @@
public MessageExchange createExchange(JmsContext context) throws Exception {
org.apache.servicemix.soap.api.Message msg = binding.createMessage();
+ ((Context) context).msg = msg;
msg.put(ComponentContext.class, ((Context) context).componentContext);
msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
msg.setContent(InputStream.class, new ByteArrayInputStream(((TextMessage) context.getMessage()).getText().getBytes()));
@@ -99,18 +103,55 @@
}
public Message createOut(MessageExchange exchange, NormalizedMessage outMsg, Session session, JmsContext context) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ org.apache.servicemix.soap.api.Message in = ((Context) context).msg;
+ org.apache.servicemix.soap.api.Message msg = binding.createMessage(in);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ msg.setContent(OutputStream.class, baos);
+ msg.setContent(MessageExchange.class, exchange);
+ msg.setContent(NormalizedMessage.class, outMsg);
+ msg.put(SoapVersion.class, in.get(SoapVersion.class));
+ msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
+ InterceptorChain phase = getChain(Phase.ServerOut);
+ phase.doIntercept(msg);
+ return session.createTextMessage(baos.toString());
}
public Message createFault(MessageExchange exchange, Fault fault, Session session, JmsContext context) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ org.apache.servicemix.soap.api.Message in = ((Context) context).msg;
+ org.apache.servicemix.soap.api.Message msg = binding.createMessage(in);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ msg.setContent(OutputStream.class, baos);
+ msg.setContent(MessageExchange.class, exchange);
+ msg.setContent(NormalizedMessage.class, fault);
+ msg.put(SoapVersion.class, in.get(SoapVersion.class));
+ msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
+ InterceptorChain phase = getChain(Phase.ServerOutFault);
+ QName code = (QName) fault.getProperty("org.apache.servicemix.soap.fault.code");
+ String reason = (String) fault.getProperty("org.apache.servicemix.soap.fault.reason");
+ SoapFault soapFault = new SoapFault(code, reason, null, null, fault.getContent());
+ msg.setContent(Exception.class, soapFault);
+ phase.doIntercept(msg);
+ return session.createTextMessage(baos.toString());
}
public Message createError(MessageExchange exchange, Exception error, Session session, JmsContext context) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ org.apache.servicemix.soap.api.Message in = ((Context) context).msg;
+ org.apache.servicemix.soap.api.Message msg = binding.createMessage(in);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ msg.setContent(OutputStream.class, baos);
+ msg.setContent(MessageExchange.class, exchange);
+ msg.put(SoapVersion.class, in.get(SoapVersion.class));
+ msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper);
+ InterceptorChain phase = getChain(Phase.ServerOutFault);
+ SoapFault soapFault;
+ if (error instanceof SoapFault) {
+ soapFault = (SoapFault) error;
+ } else {
+ soapFault = new SoapFault(error);
+ }
+ msg.setContent(Exception.class, soapFault);
+ phase.doIntercept(msg);
+ return session.createTextMessage(baos.toString());
}
protected InterceptorChain getChain(Phase phase) {
@@ -126,6 +167,7 @@
protected static class Context implements JmsContext {
Message message;
ComponentContext componentContext;
+ org.apache.servicemix.soap.api.Message msg;
Context(Message message, ComponentContext componentContext) {
this.message = message;
this.componentContext = componentContext;
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsConsumerEndpointTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsConsumerEndpointTest.java?view=diff&rev=552564&r1=552563&r2=552564
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsConsumerEndpointTest.java (original)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsConsumerEndpointTest.java Mon Jul 2 12:06:14 2007
@@ -16,6 +16,9 @@
*/
package org.apache.servicemix.jms;
+import java.io.ByteArrayOutputStream;
+
+import javax.jms.Message;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -28,12 +31,15 @@
import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.components.util.MockServiceComponent;
import org.apache.servicemix.jbi.container.JBIContainer;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
+import org.apache.servicemix.jbi.util.FileUtil;
import org.apache.servicemix.jms.endpoints.DefaultConsumerMarshaler;
import org.apache.servicemix.jms.endpoints.JmsConsumerEndpoint;
+import org.apache.servicemix.jms.endpoints.JmsSoapConsumerEndpoint;
import org.apache.servicemix.tck.Receiver;
import org.apache.servicemix.tck.ReceiverComponent;
import org.jencks.GeronimoPlatformTransactionManager;
@@ -273,6 +279,38 @@
new JmsTemplate(connectionFactory).convertAndSend("destination", "<hello>world</hello>");
receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testSoapConsumerSimple() throws Exception {
+ JmsComponent component = new JmsComponent();
+ JmsSoapConsumerEndpoint endpoint = new JmsSoapConsumerEndpoint();
+ endpoint.setService(new QName("uri:HelloWorld", "HelloService"));
+ endpoint.setEndpoint("HelloPort");
+ endpoint.setTargetService(new QName("mock"));
+ endpoint.setListenerType("simple");
+ endpoint.setConnectionFactory(connectionFactory);
+ endpoint.setDestinationName("destination");
+ endpoint.setReplyDestinationName("reply");
+ endpoint.setWsdl(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC.wsdl"));
+ component.setEndpoints(new JmsConsumerEndpoint[] { endpoint });
+ container.activateComponent(component, "servicemix-jms");
+
+ MockServiceComponent mock = new MockServiceComponent();
+ mock.setService(new QName("mock"));
+ mock.setEndpoint("endpoint");
+ mock.setResponseXml("<jbi:message xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\"><jbi:part>hello</jbi:part></jbi:message>");
+ container.activateComponent(mock, "mock");
+
+ container.start();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Input.xml").getInputStream(), baos);
+ new JmsTemplate(connectionFactory).convertAndSend("destination", baos.toString());
+
+ Message msg = new JmsTemplate(connectionFactory).receive("reply");
+ assertNotNull(msg);
+ //System.err.println(msg);
+ //System.err.println(((TextMessage) msg).getText());
}
}
Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml?view=auto&rev=552564
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml Mon Jul 2 12:06:14 2007
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
+
+ <SOAP-ENV:Header>
+ <HelloHeader1 xmlns="uri:HelloWorld">
+ <id1>abcdefghij</id1>
+ </HelloHeader1>
+
+ <HelloHeader2 xmlns="uri:HelloWorld">
+ <id2>1234567890</id2>
+ </HelloHeader2>
+ </SOAP-ENV:Header>
+
+ <SOAP-ENV:Body>
+ <Hello xmlns="uri:HelloWorld">
+ <param1 xmlns="uri:HelloWorld">foo</param1>
+ <param2 xmlns="uri:HelloWorld">bar</param2>
+ </Hello>
+ </SOAP-ENV:Body>
+
+</SOAP-ENV:Envelope>
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC-Input.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl?view=auto&rev=552564
==============================================================================
--- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl (added)
+++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl Mon Jul 2 12:06:14 2007
@@ -0,0 +1,86 @@
+<?xml version="1.0"?>
+<!--
+
+ 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.
+
+-->
+<definitions name="Hello"
+ targetNamespace="uri:HelloWorld"
+ xmlns:tns="uri:HelloWorld"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="uri:HelloWorld"
+ xmlns="http://www.w3.org/2000/10/XMLSchema">
+ <element name="HelloHeader1">
+ <complexType>
+ <all>
+ <element name="id1" type="string"/>
+ </all>
+ </complexType>
+ </element>
+ <element name="HelloHeader2">
+ <complexType>
+ <all>
+ <element name="id2" type="string"/>
+ </all>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="HelloRequest">
+ <part name="header1" element="tns:HelloHeader1"/>
+ <part name="header2" element="tns:HelloHeader2"/>
+ <part name="param1" type="xsd:string"/>
+ <part name="param2" type="xsd:int"/>
+ </message>
+
+ <message name="HelloResponse">
+ <part name="text" type="xsd:string"/>
+ </message>
+
+ <portType name="HelloPortType">
+ <operation name="Hello">
+ <input message="tns:HelloRequest"/>
+ <output message="tns:HelloResponse"/>
+ </operation>
+ </portType>
+
+ <binding name="HelloSoapBinding" type="tns:HelloPortType">
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+ <operation name="Hello">
+ <soap:operation soapAction=""/>
+ <input>
+ <soap:body use="literal" parts="param1 param2" namespace="uri:HelloWorld"/>
+ <soap:header use="literal" message="tns:HelloRequest" part="header1"/>
+ <soap:header use="literal" message="tns:HelloRequest" part="header2"/>
+ </input>
+ <output>
+ <soap:body use="literal" parts="text" namespace="uri:HelloWorld"/>
+ </output>
+ </operation>
+ </binding>
+
+ <service name="HelloService">
+ <port name="HelloPort" binding="tns:HelloSoapBinding">
+ <soap:address location="http://localhost:8080/hello"/>
+ </port>
+ </service>
+
+</definitions>
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-jms/src/test/resources/org/apache/servicemix/jms/HelloWorld-RPC.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml