1 17 package org.apache.servicemix.http; 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.net.URL ; 23 import java.net.URLConnection ; 24 25 import javax.jbi.messaging.ExchangeStatus; 26 import javax.jbi.messaging.InOut; 27 import javax.xml.namespace.QName ; 28 import javax.xml.transform.stream.StreamSource ; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.apache.servicemix.client.DefaultServiceMixClient; 33 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 34 import org.apache.servicemix.jbi.util.FileUtil; 35 import org.apache.servicemix.tck.SpringTestSupport; 36 import org.springframework.context.support.AbstractXmlApplicationContext; 37 import org.w3c.dom.Node ; 38 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 39 40 public class HttpAddressingTest extends SpringTestSupport { 41 42 private static Log logger = LogFactory.getLog(HttpAddressingTest.class); 43 44 public void testOk() throws Exception { 45 DefaultServiceMixClient client = new DefaultServiceMixClient(jbi); 46 InOut me = client.createInOutExchange(); 47 me.setService(new QName ("http://test", "MyProviderService")); 48 InputStream fis = getClass().getResourceAsStream("addressing-request.xml"); 49 me.getInMessage().setContent(new StreamSource (fis)); 50 client.sendSync(me); 51 if (me.getStatus() == ExchangeStatus.ERROR) { 52 if (me.getError() != null) { 53 throw me.getError(); 54 } else { 55 fail("Received ERROR status"); 56 } 57 } else if (me.getFault() != null) { 58 fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent())); 59 } else { 60 Node node = new SourceTransformer().toDOMNode(me.getOutMessage()); 61 logger.info(new SourceTransformer().toString(node)); 62 assertEquals("myid", textValueOfXPath(node, "//*[local-name()='RelatesTo']")); 63 assertNotNull(textValueOfXPath(node, "//*[local-name()='MessageID']")); 64 } 65 } 66 67 public void testOkFromUrl() throws Exception { 68 URLConnection connection = new URL ("http://localhost:8192/Service/").openConnection(); 69 connection.setDoOutput(true); 70 connection.setDoInput(true); 71 OutputStream os = connection.getOutputStream(); 72 InputStream fis = getClass().getResourceAsStream("addressing-request.xml"); 74 FileUtil.copyInputStream(fis, os); 75 InputStream is = connection.getInputStream(); 77 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 78 FileUtil.copyInputStream(is, baos); 79 System.err.println(baos.toString()); 80 } 81 82 public void testBad() throws Exception { 83 102 } 103 104 protected AbstractXmlApplicationContext createBeanFactory() { 105 return new ClassPathXmlApplicationContext("org/apache/servicemix/http/addressing.xml"); 106 } 107 108 } 109 | Popular Tags |