use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method testDispatchJAXB.
/*
* Creates a Dispatch object with jaxb and tests that the
* handler is called.
*/
public void testDispatchJAXB() throws Exception {
QName portQName = new QName("urn:test", "HelloPort");
String endpointAddress = getEndpointAddress("http://localhost:8080/jaxrpc-fromwsdl_handler_simple/hello");
// create service with just qname -- no handlers in that case
// Hello_Service service = createService();
QName serviceQName = new QName("urn:test", "Hello");
Service service = Service.create(serviceQName);
service.addPort(portQName, SOAP11HTTP_BINDING, setTransport(endpointAddress));
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Dispatch<Object> dispatch = service.createDispatch(portQName, jaxbContext, Service.Mode.PAYLOAD);
// ClientServerTestUtil.setTransport(dispatch, null);
int numHandlers = 0;
assertEquals("Should be " + numHandlers + " handler(s) on dispatch object", numHandlers, dispatch.getBinding().getHandlerChain().size());
int x = 1;
// 2 per handler
int diff = 2;
Hello_Type hello = new Hello_Type();
hello.setIntin(x);
HelloResponse response = (HelloResponse) dispatch.invoke(hello);
assertEquals(x + diff, response.getIntout());
// add handler programatically
ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), dispatch);
diff = 4;
response = (HelloResponse) dispatch.invoke(hello);
assertEquals(x + diff, response.getIntout());
}
use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method testDynamic2.
/*
* Test tries to add a handler programmatically after clearing
* handlers out of the service. Adds handler using HandlerResolver.
* Uses a null HandlerResolver to clear the service.
*/
public void testDynamic2() throws Exception {
Hello_Service service = createService();
service.setHandlerResolver(null);
Hello stub = createStub(service);
int x = 1;
// 2 per handler invoked
int diff = 2;
int y = stub.hello(x);
assertEquals(x + diff, y);
// now add client handler
service.setHandlerResolver(new HandlerResolver() {
public List<Handler> getHandlerChain(PortInfo info) {
List list = new ArrayList<Handler>();
list.add(new SOAPTestHandler());
return list;
}
});
stub = createStub(service);
// test again
diff = 4;
y = stub.hello(x);
assertTrue(y == x + diff);
}
use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method testDispatchSourceSOAPHandler.
/*
* Creates a Dispatch object with source and tests that
* the handler is called. Test uses a SOAP handler.
*/
public void testDispatchSourceSOAPHandler() throws Exception {
String req = "<?xml version=\"1.0\" ?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><Hello xmlns=\"urn:test:types\"><intin>1</intin></Hello></soapenv:Body></soapenv:Envelope>";
QName portQName = new QName("urn:test", "HelloPort");
String endpointAddress = getEndpointAddress("http://localhost:8080/jaxrpc-fromwsdl_handler_simple/hello");
// create service with just qname -- no handlers in that case
QName serviceQName = new QName("urn:test", "Hello");
Service service = Service.create(serviceQName);
service.addPort(portQName, SOAP11HTTP_BINDING, setTransport(endpointAddress));
Dispatch<Source> dispatch = service.createDispatch(portQName, Source.class, Service.Mode.MESSAGE);
// ClientServerTestUtil.setTransport(dispatch, null);
int numHandlers = 0;
assertEquals("Should be " + numHandlers + " handler(s) on dispatch object", numHandlers, dispatch.getBinding().getHandlerChain().size());
int x = 1;
// 2 per handler
int diff = 2;
ByteArrayInputStream iStream = new ByteArrayInputStream(req.getBytes());
Source requestSource = new StreamSource(iStream);
Source response = dispatch.invoke(requestSource);
int responseInt = getIntFromResponse(response);
assertEquals(x + diff, responseInt);
// add handler programatically
ClientServerTestUtil.addHandlerToBinding(new SOAPTestHandler(), dispatch);
diff = 4;
// make new call
iStream = new ByteArrayInputStream(req.getBytes());
requestSource = new StreamSource(iStream);
response = dispatch.invoke(requestSource);
responseInt = getIntFromResponse(response);
assertEquals(x + diff, responseInt);
}
use of fromwsdl.handler_simple.common.SOAPTestHandler in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method testDynamic1.
/*
* Test tries to add a handler programmatically after clearing
* handlers out of the service. Adds handler to binding. Uses
* an empty handler resolver for clearing the service.
*/
public void testDynamic1() throws Exception {
Hello_Service service = createService();
service.setHandlerResolver(new HandlerResolver() {
public List<Handler> getHandlerChain(PortInfo info) {
return new ArrayList<Handler>();
}
});
Hello stub = createStub(service);
int x = 1;
// 2 per handler invoked
int diff = 2;
int y = stub.hello(x);
assertTrue(y == x + diff);
// now add client handler
List<Handler> handlerList = new ArrayList<Handler>();
handlerList.add(new SOAPTestHandler());
Binding binding = ((BindingProvider) stub).getBinding();
binding.setHandlerChain(handlerList);
// test again
diff = 4;
y = stub.hello(x);
assertTrue(y == x + diff);
}
Aggregations