use of javax.xml.ws.handler.Handler in project tomee by apache.
the class HandlerResolverImpl method sortHandlers.
/**
* sorts the handlers into correct order. All of the logical handlers first
* followed by the protocol handlers
*
* @param handlers
* @return sorted list of handlers
*/
private List<Handler> sortHandlers(final List<Handler> handlers) {
final List<LogicalHandler> logicalHandlers = new ArrayList<>();
final List<Handler> protocolHandlers = new ArrayList<>();
for (final Handler handler : handlers) {
if (handler instanceof LogicalHandler) {
logicalHandlers.add((LogicalHandler) handler);
} else {
protocolHandlers.add(handler);
}
}
final List<Handler> sortedHandlers = new ArrayList<>();
sortedHandlers.addAll(logicalHandlers);
sortedHandlers.addAll(protocolHandlers);
return sortedHandlers;
}
use of javax.xml.ws.handler.Handler in project tomee by apache.
the class HandlerResolverImpl method buildHandlers.
private List<Handler> buildHandlers(final PortInfo portInfo, final HandlerChainData handlerChain) {
if (!matchServiceName(portInfo, handlerChain.getServiceNamePattern()) || !matchPortName(portInfo, handlerChain.getPortNamePattern()) || !matchBinding(portInfo, handlerChain.getProtocolBindings())) {
return Collections.emptyList();
}
final List<Handler> handlers = new ArrayList<>(handlerChain.getHandlers().size());
for (final HandlerData handler : handlerChain.getHandlers()) {
final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
if (webBeansContext != null) {
// cdi
final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
if (bm.isInUse()) {
try {
final Set<Bean<?>> beans = bm.getBeans(handler.getHandlerClass());
final Bean<?> bean = bm.resolve(beans);
if (bean != null) {
// proxy so faster to do it
final boolean normalScoped = bm.isNormalScope(bean.getScope());
final CreationalContextImpl<?> creationalContext = bm.createCreationalContext(bean);
final Handler instance = Handler.class.cast(bm.getReference(bean, bean.getBeanClass(), creationalContext));
// hack for destroyHandlers()
handlers.add(instance);
handlerInstances.add(new InjectionProcessor<Handler>(instance, Collections.<Injection>emptySet(), null) {
@Override
public void preDestroy() {
if (!normalScoped) {
creationalContext.release();
}
}
});
continue;
}
} catch (final InjectionException ie) {
LOGGER.info(ie.getMessage(), ie);
}
}
}
try {
// old way
final Class<? extends Handler> handlerClass = handler.getHandlerClass().asSubclass(Handler.class);
final InjectionProcessor<Handler> processor = new InjectionProcessor<>(handlerClass, injections, handler.getPostConstruct(), handler.getPreDestroy(), unwrap(context));
processor.createInstance();
processor.postConstruct();
final Handler handlerInstance = processor.getInstance();
handlers.add(handlerInstance);
handlerInstances.add(processor);
} catch (final Exception e) {
throw new WebServiceException("Failed to instantiate handler", e);
}
}
return handlers;
}
use of javax.xml.ws.handler.Handler in project tomee by apache.
the class HandlerResolverImplTest method testBasic.
public void testBasic() throws Exception {
final HandlerChains handlerChains = readHandlerChains("/handlers.xml");
assertEquals(3, handlerChains.getHandlerChain().size());
final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
List<Handler> handlers = null;
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
assertEquals(3, handlers.size());
}
use of javax.xml.ws.handler.Handler in project tomee by apache.
the class HandlerResolverImplTest method testServiceMatching.
public void testServiceMatching() throws Exception {
final HandlerChains handlerChains = readHandlerChains("/handlers_service.xml");
assertEquals(3, handlerChains.getHandlerChain().size());
final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
List<Handler> handlers = null;
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
assertEquals(0, handlers.size());
final QName serviceName1 = new QName("http://java.sun.com/xml/ns/javaee", "Bar");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName1));
assertEquals(1, handlers.size());
final QName serviceName2 = new QName("http://java.sun.com/xml/ns/javaee", "Foo");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName2));
assertEquals(2, handlers.size());
final QName serviceName3 = new QName("http://java.sun.com/xml/ns/javaee", "FooBar");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName3));
assertEquals(1, handlers.size());
final QName serviceName4 = new QName("http://java.sun.com/xml/ns/javaee", "BarFoo");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4));
assertEquals(0, handlers.size());
}
use of javax.xml.ws.handler.Handler in project openolat by klemens.
the class ViteroManager method checkConnection.
public boolean checkConnection(final String url, final String login, final String password, final int customerId) throws VmsNotAvailableException {
try {
LicenceService ss = new LicenceService();
ss.setHandlerResolver(new HandlerResolver() {
@SuppressWarnings("rawtypes")
@Override
public List<Handler> getHandlerChain(PortInfo portInfo) {
List<Handler> handlerList = new ArrayList<Handler>();
handlerList.add(new ViteroSecurityHandler(login, password));
return handlerList;
}
});
Licence port = ss.getLicenceSoap11();
String endPoint = UriBuilder.fromUri(url).path("services").path("LicenseService").build().toString();
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
GetModulesForCustomerRequest request = new GetModulesForCustomerRequest();
request.setCustomerid(customerId);
Modulestype modulesType = port.getModulesForCustomer(request);
return modulesType != null;
} catch (SOAPFaultException f) {
ErrorCode code = handleAxisFault(f);
switch(code) {
case unsufficientRights:
log.error("Unsufficient rights", f);
break;
default:
logAxisError("Cannot check connection", f);
}
return false;
} catch (WebServiceException e) {
if (e.getCause() instanceof ConnectException) {
throw new VmsNotAvailableException();
}
log.warn("Error checking connection", e);
return false;
}
}
Aggregations