You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2006/06/30 19:16:46 UTC
svn commit: r418332 - in /incubator/servicemix/trunk/servicemix-core/src:
main/java/org/apache/servicemix/client/ main/java/org/apache/servicemix/tck/
test/java/org/apache/servicemix/client/
test/resources/org/apache/servicemix/client/
Author: jstrachan
Date: Fri Jun 30 10:16:45 2006
New Revision: 418332
URL: http://svn.apache.org/viewvc?rev=418332&view=rev
Log:
removed the experimental Client API for now (we can bring it back later if we think its a good idea) - and instead merged the Destination feature into the existing ServiceMixClient so that you can create a Destination for a URI to act as a factory of exchanges so that Destinations can be used kinda like in JMS
Added:
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java (with props)
Removed:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Client.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultDestination.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultJBIClient.java
Modified:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultServiceMixClient.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Destination.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClient.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClientFacade.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/XPathHelper.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/MessageList.java
incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ServiceMixClientTest.java
incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml
incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/remote.xml
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultServiceMixClient.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultServiceMixClient.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultServiceMixClient.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/DefaultServiceMixClient.java Fri Jun 30 10:16:45 2006
@@ -131,6 +131,10 @@
return exchange;
}
+ public Destination createDestination(String uri) throws MessagingException {
+ return new DefaultDestination(this, uri);
+ }
+
public void send(MessageExchange exchange) throws MessagingException {
getDeliveryChannel().send(exchange);
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Destination.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Destination.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Destination.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/Destination.java Fri Jun 30 10:16:45 2006
@@ -15,13 +15,10 @@
*/
package org.apache.servicemix.client;
-import javax.jbi.messaging.Fault;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOptionalOut;
import javax.jbi.messaging.InOut;
-import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.RobustInOnly;
/**
@@ -32,119 +29,6 @@
public interface Destination {
/**
- * Indicates that the endpoint is no longer required
- */
- void close();
-
- // Simple one-way messaging API
- // -------------------------------------------------------------------------
-
- /**
- * Registers an asynchronous listener to messages so that they can be
- * processed as they become available
- */
- public void setMessageListener(MessageListener processor);
-
- /**
- * Creates a message ready to be sent to the endpoint via
- * {@link #sendMessage(NormalizedMessage)}
- *
- * @return
- */
- Message createMessage();
-
- /**
- * Creates a message ready to be sent to the endpoint via
- * {@link #sendMessage(NormalizedMessage)}. The message has the given body
- * attached
- *
- * @return
- * @throws MessagingException
- */
- Message createMessage(Object body) throws MessagingException;
-
- /**
- * Sends the message to the endpoint
- *
- * @throws MessagingException
- */
- public void send(NormalizedMessage message) throws MessagingException;
-
- // Methods which can block for a long time
- // -------------------------------------------------------------------------
-
- /**
- * Receives a message from the endpoint.
- *
- * Depending on the implementation this method could work with a declarative
- * transaction model to know when you have completed processing the message
- * correctly, otherwise for RobustInOnly then the message is acknowedged
- * immediately.
- *
- * @throws MessagingException
- */
- Message receive() throws MessagingException;
-
- /**
- * Pulls a single message from the endpoint and processes it ensuring that
- * the message exchange is complete as soon as this method is called.
- *
- * This method implicitly defines a unit of work around the message exchange
- */
- public void receive(MessageListener listener);
-
- /**
- * Performs a request response with the endpoint blocking until a response
- * is available.
- */
- Message waitForResponse(Message requestMessage);
-
- // Send and receive of message exchanges
- // -------------------------------------------------------------------------
-
- /**
- * Sends the message exchange to the endpoint.
- *
- * @param exchange
- * @throws MessagingException
- */
- void send(MessageExchange exchange) throws MessagingException;
-
- /**
- * Sends the message exchange to the endpoint, blocking until the send has
- * completed.
- *
- * @param exchange
- * @throws MessagingException
- * @return true if the exchange has been processed and returned by the
- * servicing component, false otherwise.
- */
- boolean sendSync(MessageExchange exchange) throws MessagingException;
-
- /**
- * Receives an inbound message exchange, blocking forever until one is
- * available.
- *
- * @return the received message exchange
- * @throws MessagingException
- */
- MessageExchange receiveExchange() throws MessagingException;
-
- /**
- * Receives an inbound message exchange, blocking until the given timeout
- * period.
- *
- * @param timeout
- * the maximum amount of time to wait for a message
- * @return the received message exchange or null if the timeout occurred.
- * @throws MessagingException
- */
- MessageExchange receiveExchange(long timeout) throws MessagingException;
-
- // Factory methods to make MessageExchange instances
- // -------------------------------------------------------------------------
-
- /**
* Creates an {@link InOnly} (one way) message exchange.
*
* @return the newly created message exchange
@@ -177,43 +61,4 @@
*/
RobustInOnly createRobustInOnlyExchange() throws MessagingException;
- // API to explicitly acknowledge an inbound message as being complete
- // -------------------------------------------------------------------------
-
- /**
- * Marks this exchange as being complete; typically used for inbound
- * messages
- *
- * @throws MessagingException
- */
- public void done(MessageExchange message) throws MessagingException;
-
- /**
- * Marks this exchange as being complete; typically used for inbound
- * messages
- *
- * @throws MessagingException
- */
- public void done(Message message) throws MessagingException;
-
- /**
- * Marks this exchange as being failed with a fault
- *
- * @throws MessagingException
- */
- public void fail(Fault fault) throws MessagingException;
-
- /**
- * Marks this exchange as being failed with an error
- *
- * @throws MessagingException
- */
- public void fail(Message message, Exception fault) throws MessagingException;
-
- /**
- * Marks this exchange as being failed with an error
- *
- * @throws MessagingException
- */
- public void fail(MessageExchange exchange, Exception fault) throws MessagingException;
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClient.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClient.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClient.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClient.java Fri Jun 30 10:16:45 2006
@@ -28,6 +28,7 @@
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchangeFactory;
import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.RobustInOnly;
import javax.xml.namespace.QName;
@@ -96,10 +97,6 @@
MessageExchange receive(long timeout) throws MessagingException;
- // Helper methods to make JBI a little more concise to use from a client
- //-------------------------------------------------------------------------
-
-
/**
* Performs a request-response (using an {@link InOut} to the endpoint denoted by the given resolver,
* blocking until the response is received and then returning the result.
@@ -286,6 +283,15 @@
EndpointResolver createResolverForExternalInterface(QName service, String endpoint);
+ // Create a destination
+ //-------------------------------------------------------------------------
+
+ /**
+ * Creates a destination which represents some JBI endpoint that message exchanges can be created with.
+ * @throws MessagingException
+ */
+ Destination createDestination(String uri) throws MessagingException;
+
// Helper methods and access to the JBI context information
//-------------------------------------------------------------------------
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClientFacade.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClientFacade.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClientFacade.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/ServiceMixClientFacade.java Fri Jun 30 10:16:45 2006
@@ -136,6 +136,10 @@
return exchange;
}
+ public Destination createDestination(String uri) throws MessagingException {
+ return new DefaultDestination(this, uri);
+ }
+
public void send(MessageExchange exchange) throws MessagingException {
getDeliveryChannel().send(exchange);
done(exchange);
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/XPathHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/XPathHelper.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/XPathHelper.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/client/XPathHelper.java Fri Jun 30 10:16:45 2006
@@ -16,6 +16,8 @@
package org.apache.servicemix.client;
+import org.apache.servicemix.nms.Message;
+
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/MessageList.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/MessageList.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/MessageList.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/tck/MessageList.java Fri Jun 30 10:16:45 2006
@@ -15,11 +15,14 @@
*/
package org.apache.servicemix.tck;
+import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.Message;
+import org.apache.servicemix.client.MessageListener;
import java.util.ArrayList;
import java.util.List;
@@ -31,11 +34,12 @@
*
* @version $Revision$
*/
-public class MessageList extends Assert {
+public class MessageList extends Assert implements MessageListener {
private static final Log log = LogFactory.getLog(MessageList.class);
private List messages = new ArrayList();
+
private Object semaphore;
public MessageList() {
@@ -128,5 +132,11 @@
public boolean hasReceivedMessages(int messageCount) {
return getMessageCount() >= messageCount;
+ }
+
+ // MessageListener interface
+ // -------------------------------------------------------------------------
+ public void onMessage(MessageExchange exchange, Message message) throws Exception {
+ addMessage(message);
}
}
Added: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java?rev=418332&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java Fri Jun 30 10:16:45 2006
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2005-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.servicemix.client;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.TestBean;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.StringReader;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class ClientDestinationTest extends TestCase {
+ private static final transient Log log = LogFactory.getLog(ClientDestinationTest.class);
+
+ protected AbstractXmlApplicationContext context;
+ protected ServiceMixClient client;
+ protected MessageList messageList = new MessageList();
+ protected Destination inOnlyDestination;
+ protected Destination inOutDestination;
+ protected String inOnlyUri = "service:http://servicemix.org/cheese/receiver";
+ protected String inOutUri = "service:http://servicemix.org/cheese/myService";
+
+ public void testSendUsingInOnlyExchange() throws Exception {
+ InOnly exchange = inOnlyDestination.createInOnlyExchange();
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setProperty("name", "James");
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ client.send(exchange);
+
+ messageList.assertMessagesReceived(1);
+ }
+
+ public void testRequestResponse() throws Exception {
+ InOut exchange = inOutDestination.createInOutExchange();
+
+ NormalizedMessage request = exchange.getInMessage();
+ request.setProperty("name", "James");
+ request.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ client.sendSync(exchange);
+
+ NormalizedMessage response = exchange.getOutMessage();
+
+ assertNotNull("Should have returned a non-null response!", response);
+
+ log.info("Received result: " + response);
+ }
+
+
+ /*
+ public void testSendUsingMessage() throws Exception {
+ Message message = inOnlyDestination.createMessage();
+ message.setProperty("name", "James");
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ inOnlyDestination.send(message);
+
+ messageList.assertMessagesReceived(1);
+ }
+
+ public void testSendUsingMessageUsingPOJOWithXStreamMarshaling() throws Exception {
+ TestBean bean = new TestBean();
+ bean.setName("James");
+ bean.setLength(12);
+ bean.getAddresses().addAll(Arrays.asList(new String[] { "London", "LA" }));
+
+ Message message = inOnlyDestination.createMessage(bean);
+ message.setProperty("name", "James");
+
+ inOnlyDestination.send(message);
+
+ messageList.assertMessagesReceived(1);
+ }
+
+ public void testRequestResponse() throws Exception {
+ InOut exchange = inOutDestination.createInOutExchange();
+ Message request = inOutDestination.createMessage();
+ exchange.setInMessage(request);
+ Message response = inOutDestination.invoke(exchange);
+
+ assertNotNull("Should have returned a non-null response!", response);
+
+ log.info("Received result: " + response);
+ }
+ */
+
+ protected void setUp() throws Exception {
+ context = createBeanFactory();
+ client = (ServiceMixClient) getBean("client");
+
+ inOnlyDestination = client.createDestination(inOnlyUri);
+ inOutDestination = client.createDestination(inOutUri);
+
+ messageList = createMessageList();
+ }
+
+ /*
+ * protected MessageList createMessageList() throws Exception { MessageList
+ * answer = new MessageList(); Destination consumer =
+ * client.createEndpoint(destinationUri, messageList); return answer; }
+ */
+
+ protected MessageList createMessageList() throws Exception {
+ SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
+ Receiver receiver = (Receiver) jbi.getBean("receiver");
+ assertNotNull("receiver not found in JBI container", receiver);
+ return receiver.getMessageList();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ protected Object getBean(String name) {
+ Object answer = context.getBean(name);
+ assertNotNull("Could not find object in Spring for key: " + name, answer);
+ return answer;
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/client/example.xml");
+ }
+}
Propchange: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ClientDestinationTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ServiceMixClientTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ServiceMixClientTest.java?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ServiceMixClientTest.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/java/org/apache/servicemix/client/ServiceMixClientTest.java Fri Jun 30 10:16:45 2006
@@ -62,7 +62,7 @@
message.setProperty("name", "James");
message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
- QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ QName service = new QName("http://servicemix.org/cheese", "receiver");
exchange.setService(service);
client.send(exchange);
@@ -74,7 +74,7 @@
Map properties = new HashMap();
properties.put("name", "James");
- QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ QName service = new QName("http://servicemix.org/cheese", "receiver");
EndpointResolver resolver = client.createResolverForService(service);
client.send(resolver, null, properties, "<hello>world</hello>");
@@ -113,17 +113,17 @@
// Request methods
//-------------------------------------------------------------------------
public void testRequestUsingJbiAPIsByServiceName() throws Exception {
- QName service = new QName("http://servicemix.org/cheese/", "myService");
+ QName service = new QName("http://servicemix.org/cheese", "myService");
assertRequestUsingJBIAPIs(service);
}
public void testRequestUsingMapAndPOJOsByServiceName() throws Exception {
- QName service = new QName("http://servicemix.org/cheese/", "myService");
+ QName service = new QName("http://servicemix.org/cheese", "myService");
assertRequestUsingMapAndPOJOByServiceName(service);
}
public void testRequestUsingPOJOWithXStreamMarshaling() throws Exception {
- QName service = new QName("http://servicemix.org/cheese/", "myService");
+ QName service = new QName("http://servicemix.org/cheese", "myService");
ServiceMixClient client = (ServiceMixClient) context.getBean("clientWithXStream");
Modified: incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/example.xml Fri Jun 30 10:16:45 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
- xmlns:foo="http://servicemix.org/cheese/">
+ xmlns:foo="http://servicemix.org/cheese">
<!-- the JBI container -->
<sm:container id="jbi" embedded="true">
Modified: incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/remote.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/remote.xml?rev=418332&r1=418331&r2=418332&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/remote.xml (original)
+++ incubator/servicemix/trunk/servicemix-core/src/test/resources/org/apache/servicemix/client/remote.xml Fri Jun 30 10:16:45 2006
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:amq="http://activemq.org/config/1.0"
- xmlns:foo="http://servicemix.org/cheese/">
+ xmlns:foo="http://servicemix.org/cheese">
<amq:broker id="broker" singleton="true" useJmx="false" persistent="false">