1 17 package org.apache.servicemix.client; 18 19 import org.apache.servicemix.client.DefaultServiceMixClient; 20 import org.apache.servicemix.client.ServiceMixClient; 21 import org.apache.servicemix.components.util.OutBinding; 22 import org.apache.servicemix.jbi.container.ActivationSpec; 23 import org.apache.servicemix.jbi.container.JBIContainer; 24 25 import javax.jbi.messaging.InOnly; 26 import javax.jbi.messaging.MessageExchange; 27 import javax.jbi.messaging.MessagingException; 28 import javax.jbi.messaging.NormalizedMessage; 29 import javax.xml.namespace.QName ; 30 import javax.xml.transform.stream.StreamSource ; 31 32 import java.io.StringReader ; 33 34 import junit.framework.TestCase; 35 36 39 public class SimpleClientTest extends TestCase { 40 protected JBIContainer container; 41 protected OutBinding out; 42 protected ServiceMixClient client; 43 44 protected void setUp() throws Exception { 45 container = new JBIContainer(); 46 container.setEmbedded(true); 47 container.init(); 48 container.start(); 49 out = new OutBinding() { 50 protected void process(MessageExchange exchange, NormalizedMessage message) throws MessagingException { 51 System.out.println("Received: " + message); 52 done(exchange); 53 } 54 }; 55 ActivationSpec as = new ActivationSpec("out",out); 56 as.setService(new QName ("out")); 57 container.activateComponent(as); 58 client = new DefaultServiceMixClient(container); 59 } 60 61 protected void tearDown() throws Exception { 62 container.shutDown(); 63 } 64 65 70 public void testSimple() throws Exception { 71 InOnly exchange = client.createInOnlyExchange(); 72 NormalizedMessage message = exchange.getInMessage(); 73 message.setProperty("name", "john"); 74 message.setContent(new StreamSource (new StringReader ("<hello>world</hello>"))); 75 QName service = new QName ("out"); 76 exchange.setService(service); 77 client.sendSync(exchange); 78 } 79 } 80 | Popular Tags |