use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.
the class EndToEndErrorTester method testServiceSpecificException1.
/*
* Have the endpoint throw a service specific exception and make
* sure that the client gets it back. Test case for bug 6232002.
*/
public void testServiceSpecificException1() throws Exception {
TestService_Service service = getService();
HandlerTracker tracker = HandlerTracker.getClientInstance();
// get stubs and clear the trackers
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
reportStub.clearHandlerTracker();
tracker.clearAll();
try {
testStub.testInt(SERVER_THROW_MYFAULT_EXCEPTION);
fail("did not receive exception (1)");
} catch (MyFaultException mfe) {
// passed
} catch (Exception e) {
fail("did not receive MyFaultException (1), received " + e);
}
// check closed handlers to be sure
List<String> actualClosed = tracker.getClosedHandlers();
int[] closed = { 7, 5, 4, 3, 1, 0 };
assertEquals("Did not get proper number of closed handlers", closed.length, actualClosed.size());
for (int i = 0; i < closed.length; i++) {
assertEquals("did not find expected handler", CLIENT_PREFIX + closed[i], actualClosed.get(i));
}
// remove all client handlers and try again
Binding binding = ((BindingProvider) testStub).getBinding();
binding.setHandlerChain(new ArrayList<Handler>());
tracker.clearAll();
try {
testStub.testInt(SERVER_THROW_MYFAULT_EXCEPTION);
fail("did not receive exception (2)");
} catch (MyFaultException mfe) {
// passed
} catch (Exception e) {
fail("did not receive MyFaultException (2), received " + e);
}
// this just makes sure there really were no handlers
actualClosed = tracker.getClosedHandlers();
assertTrue("should not have been closed handlers", actualClosed.isEmpty());
}
use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.
the class EndToEndTester method testRequestPropertyDispatch.
/*
* Sets a property on the request context with dispatch
* and verifies that the property exists in the handler.
* Also adds a handler to add 1 to the messages just to
* make sure handlers are being invoked.
*/
public void testRequestPropertyDispatch() throws Exception {
HandlerTracker tracker = HandlerTracker.getClientInstance();
Dispatch<Object> dispatch = getDispatchJAXB(testPortQName);
// tell the server handlers not to do anything
ReportService reportStub = getReportStub(getService());
reportStub.clearHandlerTracker();
// add handlers
String myHandlerName = "MyDispatchHandler";
BaseSOAPHandler propCheckingHandler = new BaseSOAPHandler();
propCheckingHandler.setName(CLIENT_PREFIX + myHandlerName);
propCheckingHandler.initTheHandler();
String otherHandlerName = "MyOtherHandler";
BaseSOAPHandler numberAddingHandler = new BaseSOAPHandler();
numberAddingHandler.setName(CLIENT_PREFIX + otherHandlerName);
numberAddingHandler.initTheHandler();
List<Handler> newHandlers = new ArrayList<Handler>();
newHandlers.add(propCheckingHandler);
newHandlers.add(numberAddingHandler);
dispatch.getBinding().setHandlerChain(newHandlers);
// add the property
dispatch.getRequestContext().put(USER_CLIENT_PROPERTY_NAME, USER_PROPERTY_CLIENT_SET);
// tell the client handlers what to do
tracker.clearAll();
tracker.setHandlerAction(CLIENT_PREFIX + myHandlerName, HA_CHECK_FOR_USER_PROPERTY_OUTBOUND);
tracker.setHandlerAction(CLIENT_PREFIX + otherHandlerName, HA_ADD_ONE);
// make the call (will get exception if handler doesn't see property)
int x = 1;
// for the number adding handler
int diff = 2;
TestInt request = new TestInt();
request.setIntin(x);
TestIntResponse response = (TestIntResponse) dispatch.invoke(request);
assertEquals("did not get proper response", x + diff, response.getIntout());
}
use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.
the class HandlerChainsModel method getHandlersForPortInfo.
public HandlerAnnotationInfo getHandlersForPortInfo(PortInfo info) {
HandlerAnnotationInfo handlerInfo = new HandlerAnnotationInfo();
List<Handler> handlerClassList = new ArrayList<>();
Set<String> roles = new HashSet<>();
for (HandlerChainType hchain : handlerChains) {
boolean hchainMatched = (!hchain.isConstraintSet()) || JAXWSUtils.matchQNames(info.getServiceName(), hchain.getServiceNamePattern()) || JAXWSUtils.matchQNames(info.getPortName(), hchain.getPortNamePattern()) || hchain.getProtocolBindings().contains(info.getBindingID());
if (hchainMatched) {
for (HandlerType handler : hchain.getHandlers()) {
try {
Handler handlerClass = (Handler) loadClass(annotatedClass.getClassLoader(), handler.getHandlerClass()).newInstance();
callHandlerPostConstruct(handlerClass);
handlerClassList.add(handlerClass);
} catch (InstantiationException | IllegalAccessException ie) {
throw new RuntimeException(ie);
}
roles.addAll(handler.getSoapRoles());
}
}
}
handlerInfo.setHandlers(handlerClassList);
handlerInfo.setRoles(roles);
return handlerInfo;
}
use of jakarta.xml.ws.handler.Handler in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method test2.
// public void testDispatch1() throws Exception {
// int x = 1; // what we send
// int diff = 2; // 4 handler invocations
//
// JAXBContext jxbContext = JAXBContext.newInstance(ObjectFactory.class);
// Dispatch dispatch = createDispatchForJAXB(
// new QName("urn:test", "HelloPort"), jxbContext);
//
// Hello_Type request = objectFactory.createHello_Type();
// request.setValue(1);
//
// // make first call with no client side handlers
// HelloResponse response = (HelloResponse) dispatch.invoke(request);
// assertNotNull("response cannot be null", response);
//
// int y = response.getValue();
// System.out.println("sent: " + x + ", expect " + (x+diff) +
// " back. received: " + y);
// assertTrue(y == x+diff);
//
// System.out.println("now adding handler to dispatch");
// Binding binding = dispatch.getBinding();
// assertNotNull("binding cannot be null", binding);
// int handlerChainLength = binding.getHandlerChain().size();
// assertEquals("the handler list is not empty", 0, handlerChainLength);
//
// // add handler
// HandlerInfo hInfo = new HandlerInfo(
// handler_tests.simple_handler_test.client.handlers.ClientHandler.class,
// null, null);
// List<HandlerInfo> newHandlers = new ArrayList<HandlerInfo>();
// newHandlers.add(hInfo);
// binding.setHandlerChain(newHandlers);
//
// // now try again
// diff = 4;
// response = (HelloResponse) dispatch.invoke(request);
// assertNotNull("response cannot be null", response);
//
// y = response.getValue();
// System.out.println("sent: " + x + ", expect " + (x+diff) +
// " back. received: " + y);
// assertTrue(y == x+diff);
// }
/*
* Test tries to add a handler programmatically after clearing
* handlers out of registry in the service.
*/
public void test2() throws Exception {
HelloService service = createService();
service.setHandlerResolver(new HandlerResolver() {
public List<Handler> getHandlerChain(PortInfo info) {
return new ArrayList<Handler>();
}
});
HelloPortType stub = createStub(service);
int x = 1;
// 2 per handler invoked
int diff = 2;
int y = stub.hello(x);
System.out.println("sent: " + x + ", expect " + (x + diff) + " back. received: " + y);
assertTrue(y == x + diff);
// now add client handler
service.setHandlerResolver(new HandlerResolver() {
public List<Handler> getHandlerChain(PortInfo info) {
List<Handler> handlers = new ArrayList<Handler>();
handlers.add(new TestHandler());
return handlers;
}
});
stub = createStub(service);
// test again
diff = 4;
y = stub.hello(x);
System.out.println("sent: " + x + ", expect " + (x + diff) + " back. received: " + y);
assertTrue(y == x + diff);
}
use of jakarta.xml.ws.handler.Handler 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);
}
Aggregations