use of org.apache.handlers.AddNumbersService in project cxf by apache.
the class Client method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.err.println("please provide wsdl");
System.exit(0);
}
File wsdl = new File(args[0]);
AddNumbersService service = new AddNumbersService(wsdl.toURI().toURL(), serviceName);
AddNumbers port = (AddNumbers) service.getPort(portName, AddNumbers.class);
// Add client side handlers programmatically
SmallNumberHandler sh = new SmallNumberHandler();
List<Handler> newHandlerChain = new ArrayList<>();
newHandlerChain.add(sh);
((BindingProvider) port).getBinding().setHandlerChain(newHandlerChain);
try {
int number1 = 10;
int number2 = 20;
System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
int result = port.addNumbers(number1, number2);
System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
number1 = 3;
number2 = 5;
System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
result = port.addNumbers(number1, number2);
System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
number1 = -10;
System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
result = port.addNumbers(number1, number2);
System.out.printf("The result of adding %d and %d is %d.\n", number1, number2, result);
} catch (AddNumbersFault ex) {
System.out.printf("Caught AddNumbersFault: %s\n", ex.getFaultInfo().getMessage());
}
System.exit(0);
}
use of org.apache.handlers.AddNumbersService in project cxf by apache.
the class HandlerInvocationUsingAddNumbersTest method testInvokeFromDispatchWithJAXBPayload.
@Test
public void testInvokeFromDispatchWithJAXBPayload() 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);
SmallNumberHandler sh = new SmallNumberHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler(false) {
public boolean handleMessage(SOAPMessageContext ctx) {
super.handleMessage(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
try {
SOAPMessage msg = ctx.getMessage();
// System.out.println("aaaaaaaaaaaa");
// msg.writeTo(System.out);
assertNotNull(msg);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
return true;
}
};
addHandlersProgrammatically(disp, sh, soapHandler);
org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();
req.setArg0(10);
req.setArg1(20);
ObjectFactory factory = new ObjectFactory();
JAXBElement<org.apache.handlers.types.AddNumbers> e = factory.createAddNumbers(req);
JAXBElement<?> response = (JAXBElement<?>) disp.invoke(e);
assertNotNull(response);
AddNumbersResponse value = (AddNumbersResponse) response.getValue();
assertEquals(200, value.getReturn());
}
use of org.apache.handlers.AddNumbersService in project cxf by apache.
the class HandlerInvocationUsingAddNumbersTest method testAddHandlerProgrammaticallyClientSide.
@Test
public void testAddHandlerProgrammaticallyClientSide() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
AddNumbers port = service.getPort(portName, AddNumbers.class);
setAddress(port, addNumbersAddress);
SmallNumberHandler sh = new SmallNumberHandler();
addHandlersProgrammatically((BindingProvider) port, sh);
int result = port.addNumbers(10, 20);
assertEquals(200, result);
int result1 = port.addNumbers(5, 6);
assertEquals(11, result1);
}
use of org.apache.handlers.AddNumbersService in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessagePayloadMode.
@Test
public void testInvokeWithSOAPMessagePayloadMode() 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.PAYLOAD);
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);
try {
disp.invoke(soapReq);
fail("Did not get expected exception");
} catch (SOAPFaultException e) {
assertTrue("Did not get expected exception message: " + e.getMessage(), e.getMessage().indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
}
}
use of org.apache.handlers.AddNumbersService in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcPayloadMode.
@Test
public void testInvokeWithDOMSourcPayloadMode() 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.PAYLOAD);
setAddress(disp, addNumbersAddress);
TestHandler handler = new TestHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler();
addHandlersProgrammatically(disp, handler, soapHandler);
InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReqPayload.xml");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage(null, is2);
DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
DOMSource response = disp.invoke(domReqMessage);
assertNotNull(response);
}
Aggregations