Search in sources :

Example 6 with AddNumbersService

use of org.apache.handlers.AddNumbersService in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcMessageMode.

@Test
public void testInvokeWithDOMSourcMessageMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.MESSAGE);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is);
    soapReq.saveChanges();
    DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
    DOMSource response = disp.invoke(domReqMessage);
    // XMLUtils.writeTo(response, System.out);
    assertNotNull(response);
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 7 with AddNumbersService

use of org.apache.handlers.AddNumbersService in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessageMessageMode.

@Test
public void testInvokeWithSOAPMessageMessageMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is2);
    SOAPMessage response = disp.invoke(soapReq);
    assertNotNull(response);
// response.writeTo(System.out);
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) MessageFactory(javax.xml.soap.MessageFactory) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) Test(org.junit.Test)

Example 8 with AddNumbersService

use of org.apache.handlers.AddNumbersService in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithJAXBPayloadMode.

@Test
public void testInvokeWithJAXBPayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);
    JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
    Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);
    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);
    org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();
    req.setArg0(10);
    req.setArg1(20);
    ObjectFactory factory = new ObjectFactory();
    JAXBElement<AddNumbers> e = factory.createAddNumbers(req);
    JAXBElement<?> response = (JAXBElement<?>) disp.invoke(e);
    assertNotNull(response);
    AddNumbersResponse value = (AddNumbersResponse) response.getValue();
    assertEquals(222, value.getReturn());
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) JAXBContext(javax.xml.bind.JAXBContext) AddNumbersResponse(org.apache.handlers.types.AddNumbersResponse) JAXBElement(javax.xml.bind.JAXBElement) URL(java.net.URL) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) AddNumbers(org.apache.handlers.types.AddNumbers) Test(org.junit.Test)

Aggregations

AddNumbersService (org.apache.handlers.AddNumbersService)8 URL (java.net.URL)7 Test (org.junit.Test)7 SOAPMessage (javax.xml.soap.SOAPMessage)5 InputStream (java.io.InputStream)4 MessageFactory (javax.xml.soap.MessageFactory)4 AddNumbers (org.apache.handlers.AddNumbers)3 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBElement (javax.xml.bind.JAXBElement)2 DOMSource (javax.xml.transform.dom.DOMSource)2 AddNumbersResponse (org.apache.handlers.types.AddNumbersResponse)2 ObjectFactory (org.apache.handlers.types.ObjectFactory)2 SmallNumberHandler (demo.handlers.common.SmallNumberHandler)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Handler (javax.xml.ws.handler.Handler)1 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 AddNumbersFault (org.apache.handlers.AddNumbersFault)1 AddNumbers (org.apache.handlers.types.AddNumbers)1