1 16 17 package org.apache.axis2.rest; 18 19 21 import junit.framework.TestCase; 22 import org.apache.axis2.Constants; 23 import org.apache.axis2.addressing.AddressingConstants; 24 import org.apache.axis2.addressing.EndpointReference; 25 import org.apache.axis2.context.MessageContext; 26 import org.apache.axis2.context.ServiceContext; 27 import org.apache.axis2.description.Parameter; 28 import org.apache.axis2.description.ParameterImpl; 29 import org.apache.axis2.description.ServiceDescription; 30 import org.apache.axis2.engine.AxisConfiguration; 31 import org.apache.axis2.engine.AxisConfigurationImpl; 32 import org.apache.axis2.engine.Echo; 33 import org.apache.axis2.integration.UtilServer; 34 import org.apache.axis2.om.*; 35 import org.apache.axis2.soap.SOAPFactory; 36 import org.apache.axis2.util.Utils; 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 40 import javax.xml.namespace.QName ; 41 import javax.xml.stream.XMLOutputFactory; 42 43 44 public class RESTBasedEchoRawXMLTest extends TestCase { 45 private EndpointReference targetEPR = 46 new EndpointReference(AddressingConstants.WSA_TO, 47 "http://127.0.0.1:" 48 + (UtilServer.TESTING_PORT) 49 + "/axis/services/EchoXMLService/echoOMElement"); 50 private Log log = LogFactory.getLog(getClass()); 51 private QName serviceName = new QName ("EchoXMLService"); 52 private QName operationName = new QName ("echoOMElement"); 53 private QName transportName = new QName ("http://localhost/my", "NullTransport"); 54 55 private AxisConfiguration engineRegistry; 56 private MessageContext mc; 57 private ServiceContext serviceContext; 60 private ServiceDescription service; 61 62 private boolean finish = false; 63 64 65 private Thread thread; 66 67 private final MessageInformation messageInfo = new MessageInformation(); 68 69 public RESTBasedEchoRawXMLTest() { 70 super(RESTBasedEchoRawXMLTest.class.getName()); 71 } 72 73 public RESTBasedEchoRawXMLTest(String testName) { 74 super(testName); 75 } 76 77 protected void setUp() throws Exception { 78 UtilServer.start(); 79 Parameter parameter = new ParameterImpl(Constants.Configuration.ENABLE_REST,"true"); 80 ((AxisConfigurationImpl)UtilServer.getConfigurationContext().getAxisConfiguration()).addParameter(parameter); 81 service = 82 Utils.createSimpleService(serviceName, 83 Echo.class.getName(), 84 operationName); 85 UtilServer.deployService(service); 86 serviceContext = 87 UtilServer.getConfigurationContext().createServiceContext(service.getName()); 88 130 131 } 132 133 protected void tearDown() throws Exception { 134 UtilServer.unDeployService(serviceName); 135 UtilServer.stop(); 136 } 137 138 private OMElement createEnvelope() { 139 OMFactory fac = OMAbstractFactory.getOMFactory(); 140 OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); 141 OMElement method = fac.createOMElement("echoOMElement", omNs); 142 OMElement value = fac.createOMElement("myValue", omNs); 143 value.addChild(fac.createText(value, "Isaac Assimov, the foundation Sega")); 144 method.addChild(value); 145 146 return method; 147 } 148 149 150 public void testEchoXMLSync() throws Exception { 151 SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 152 153 OMElement payload = createEnvelope(); 154 155 org.apache.axis2.clientapi.Call call = new org.apache.axis2.clientapi.Call(); 156 157 call.setTo(targetEPR); 158 call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, false); 159 call.setDoREST(true); 160 OMElement result = 161 (OMElement) call.invokeBlocking(operationName.getLocalPart(), payload); 162 result.serializeWithCache(new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out))); 163 164 System.out.println(messageInfo.requestMessage); 165 call.close(); 166 } 167 168 public class MessageInformation{ 169 private String requestMessage = null; 170 private String responseMessage = null; 171 } 172 } 173 | Popular Tags |