1 17 package org.apache.servicemix.components.saaj; 18 19 import javax.jbi.messaging.ExchangeStatus; 20 import javax.jbi.messaging.InOut; 21 import javax.jbi.messaging.MessageExchange; 22 import javax.jbi.messaging.MessagingException; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.xml.messaging.URLEndpoint; 25 import javax.xml.namespace.QName ; 26 import javax.xml.soap.MessageFactory ; 27 28 import junit.framework.TestCase; 29 30 import org.apache.servicemix.MessageExchangeListener; 31 import org.apache.servicemix.client.DefaultServiceMixClient; 32 import org.apache.servicemix.components.http.HttpConnector; 33 import org.apache.servicemix.components.util.ComponentSupport; 34 import org.apache.servicemix.jbi.container.ActivationSpec; 35 import org.apache.servicemix.jbi.container.JBIContainer; 36 import org.apache.servicemix.jbi.jaxp.StringSource; 37 38 public class SaajSoapActionTest extends TestCase { 39 40 private JBIContainer jbi; 41 private SaajBinding saaj; 42 private HttpConnector http; 43 44 protected void setUp() throws Exception { 45 jbi = new JBIContainer(); 46 jbi.setEmbedded(true); 47 jbi.setUseMBeanServer(false); 48 jbi.setCreateMBeanServer(false); 49 jbi.init(); 50 } 51 52 protected void tearDown() throws Exception { 53 jbi.shutDown(); 54 } 55 56 protected String testSoapAction(String soapAction, MessageFactory messageFactory) throws Exception { 57 saaj = new SaajBinding(); 58 saaj.setService(new QName ("saaj")); 59 saaj.setEndpoint("endpoint"); 60 saaj.setSoapEndpoint(new URLEndpoint("http://localhost:8192/")); 61 saaj.setSoapAction(soapAction); 62 SaajMarshaler marshaler = new SaajMarshaler(); 63 marshaler.setMessageFactory(messageFactory); 64 saaj.setMarshaler(marshaler); 65 jbi.activateComponent(saaj, "saaj"); 66 67 http = new HttpConnector(new org.mortbay.jetty.nio.SelectChannelConnector()); 68 http.setHost("localhost"); 69 http.setPort(8192); 70 ActivationSpec httpAs = new ActivationSpec(); 72 httpAs.setComponent(http); 73 httpAs.setComponentName("http"); 74 httpAs.setDestinationService(new QName ("receiver")); 75 jbi.activateComponent(httpAs); 76 77 SoapActionReceiver receiver = new SoapActionReceiver(); 78 jbi.activateComponent(receiver, "receiver"); 79 80 jbi.start(); 81 82 DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); 83 InOut me = client.createInOutExchange(); 84 me.setService(new QName ("saaj")); 85 me.getInMessage().setContent(new StringSource("<hello>world</hello>")); 86 client.sendSync(me); 87 if (me.getStatus() == ExchangeStatus.ERROR) { 88 if (me.getError() != null) { 89 throw me.getError(); 90 } 91 } 92 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 93 client.done(me); 94 95 Thread.sleep(50); 96 97 return receiver.sentSoapAction; 98 } 99 100 public void testNullSoapActionAxis() throws Exception { 101 String received = testSoapAction(null, new org.apache.axis.soap.MessageFactoryImpl()); 102 assertEquals("\"\"", received); 103 } 104 105 111 112 public void testEmptySoapActionAxis() throws Exception { 113 String received = testSoapAction("", new org.apache.axis.soap.MessageFactoryImpl()); 114 assertEquals("\"\"", received); 115 } 116 117 123 124 public void testQuotesSoapActionAxis() throws Exception { 125 String received = testSoapAction("\"\"", new org.apache.axis.soap.MessageFactoryImpl()); 126 assertEquals("\"\"", received); 127 } 128 129 135 136 public void testWithSoapActionAxis() throws Exception { 137 String received = testSoapAction("action", new org.apache.axis.soap.MessageFactoryImpl()); 138 assertEquals("action", received); 139 } 140 141 147 148 protected static class SoapActionReceiver extends ComponentSupport implements MessageExchangeListener { 149 public String sentSoapAction; 150 public SoapActionReceiver() { 151 setService(new QName ("receiver")); 152 setEndpoint("endpoint"); 153 } 154 public void onMessageExchange(MessageExchange exchange) throws MessagingException { 155 if (exchange.getStatus() == ExchangeStatus.ACTIVE) { 156 NormalizedMessage msg = exchange.getMessage("in"); 157 sentSoapAction = (String ) msg.getProperty("SOAPAction"); 158 NormalizedMessage out = exchange.createMessage(); 159 out.setContent(msg.getContent()); 160 answer(exchange, out); 161 } 162 } 163 164 } 165 166 } 167 | Popular Tags |