@SuppressWarnings("rawtypes") public List<Handler> getHandlerChain(PortInfo portInfo) { synchronized (handlerMap) { List<Handler> handlerChain = handlerMap.get(portInfo); if (handlerChain == null) { QName portQName = portInfo.getPortName(); QName serviceQName = portInfo.getServiceName(); String bindingId = portInfo.getBindingID(); handlerChain = createHandlerChain(portInfo, portQName, serviceQName, bindingId); handlerMap.put(portInfo, handlerChain); } return handlerChain; } }
public <I> I buildWsClient(T wsServiceImplementation, Class<I> ifaceImplementationClass, final List<Handler>extraHandlers, Map<String,Object> ctxSettings){ final WsSettings settings = WsSettingsLoader.loadSettings(); wsServiceImplementation.setHandlerResolver(new HandlerResolver() { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { final List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new AuthHandler(settings.getUsername(), settings.getPassword())); handlerList.addAll(extraHandlers); return handlerList; } }); final I serviceIface = wsServiceImplementation.getPort(ifaceImplementationClass); final BindingProvider bindingProvider = (BindingProvider) serviceIface; final Map<String, Object> req_ctx = bindingProvider.getRequestContext(); req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, settings.getWsUrl()); req_ctx.putAll(ctxSettings); bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, settings.getWsUrl()); return serviceIface; }
/** * Test creating a service without a sparse composite. This verifies pre-existing default * behavior. */ public void testServiceAndPortNoComposite() { QName serviceQName = new QName(namespaceURI, svcLocalPart); QName portQName = new QName(namespaceURI, portLocalPart); Service service = Service.create(serviceQName); HandlerResolver resolver = service.getHandlerResolver(); assertNotNull(resolver); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(0, list.size()); ClientMetadataHandlerChainTestSEI port = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class); // Verify that ports created under the service have no handlers from the sparse composite BindingProvider bindingProvider = (BindingProvider) port; Binding binding = (Binding) bindingProvider.getBinding(); List<Handler> portHandlers = binding.getHandlerChain(); assertEquals(0, portHandlers.size()); }
/** * Validate that handler information can NOT be cached on the client. That is because the client * can specify handler information per instance of a service delegate. Those service * delegates could share a ServiceDescription, but since each service delegate could specify * unique handler information, we can't use common handler information stored on the * ServiceDescription */ public void testCachingOnClient() { ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(RoleBasedMUServiceImpl.class); HandlerResolverImpl handlerResolver1 = new HandlerResolverImpl(serviceDesc, "sd1"); HandlerResolverImpl handlerResolver2 = new HandlerResolverImpl(serviceDesc, "sd2"); EndpointDescription epDesc = serviceDesc.getEndpointDescriptions()[0]; PortInfo portInfo = epDesc.getPortInfo(); List<String> roles1 = handlerResolver1.getRoles(portInfo); List<String> roles2 = handlerResolver2.getRoles(portInfo); assertNotNull(roles1); assertNotNull(roles2); assertTrue(roles1 != roles2); }
/** * Test that setting the handler chain type on a sparse composite, but not * specifying that composite during construction of the HandlerResolver (i.e. no * Delegate key specified) results in no hanlders returned from this resolver. */ public void testHandlerResolverNoKey() { QName serviceQName = new QName(namespaceURI, svcLocalPart); // Create a composite with a JAXB Handler Config DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite(); HandlerChainsType handlerChainsType = getHandlerChainsType(); sparseComposite.setHandlerChainsType(handlerChainsType); Object serviceDelegateKey = "CompositeKey"; ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(null, serviceQName, HandlerResolverTestService.class, sparseComposite, serviceDelegateKey); HandlerResolver resolver = new HandlerResolverImpl(serviceDesc); assertNotNull(resolver); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(0, list.size()); }
/** * The sparse composite has handler config information for the key that the HandlerResolver * is created with, so that handler resolver contains those handlers. However, the * portInfo specified on the getHandlerChain does NOT match the QName in the config file * so no handlers should be returned. */ public void testHandlerResolverInvalidPortInfo() { QName serviceQName = new QName(namespaceURI, svcLocalPart); QName portQName = new QName(namespaceURI, portWrongLocalPart); // Create a composite with a JAXB Handler Config DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite(); HandlerChainsType handlerChainsType = getHandlerChainsType(); sparseComposite.setHandlerChainsType(handlerChainsType); Object serviceDelegateKey = "CompositeKey"; // The getHandlerChain will do handler lifecycle management as well, so there needs to be // and EnpdointDescription (representing the Port) under the ServiceDescription ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(null, serviceQName, HandlerResolverTestService.class, sparseComposite, serviceDelegateKey); EndpointDescription endpointDesc = DescriptionFactory.updateEndpoint(serviceDesc, HandlerResolverTestSEI.class, portQName, DescriptionFactory.UpdateType.GET_PORT); HandlerResolver resolver = new HandlerResolverImpl(serviceDesc, serviceDelegateKey); assertNotNull(resolver); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(0, list.size()); }
/** * The sparse composite has handler config information for the key that the HandlerResolver * is created with, so that handler resolver contains those handlers. */ public void testHandlerResolverValidPortInfo() { QName serviceQName = new QName(namespaceURI, svcLocalPart); QName portQName = new QName(namespaceURI, portLocalPart); // Create a composite with a JAXB Handler Config DescriptionBuilderComposite sparseComposite = new DescriptionBuilderComposite(); HandlerChainsType handlerChainsType = getHandlerChainsType(); sparseComposite.setHandlerChainsType(handlerChainsType); Object serviceDelegateKey = "CompositeKey"; // The getHandlerChain will do handler lifecycle management as well, so there needs to be // and EnpdointDescription (representing the Port) under the ServiceDescription ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(null, serviceQName, HandlerResolverTestService.class, sparseComposite, serviceDelegateKey); EndpointDescription endpointDesc = DescriptionFactory.updateEndpoint(serviceDesc, HandlerResolverTestSEI.class, portQName, DescriptionFactory.UpdateType.GET_PORT); HandlerResolver resolver = new HandlerResolverImpl(serviceDesc, serviceDelegateKey); assertNotNull(resolver); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(2, list.size()); }
/** * Sends the specified content file to the WebService * * @param name The name of the content to be stored * @param content The content to be stored * @return The message that tthe server sent back */ public String storeContent(String name, DataHandler content) { ContentStoreHttpPortService service = new ContentStoreHttpPortService(); service.setHandlerResolver(new HandlerResolver() { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerList = new ArrayList<>(); handlerList.add(wsSecurityHandler); return handlerList; } }); ContentStoreHttpPort contentStorePort = service.getContentStoreHttpPortSoap11(); SOAPBinding binding = (SOAPBinding) ((BindingProvider) contentStorePort).getBinding(); binding.setMTOMEnabled(true); StoreContentRequest request = objectFactory.createStoreContentRequest(); request.setName(name); request.setContent(content); StoreContentResponse response = contentStorePort.storeContent(request); return response.getMessage(); }
/** * Loads the content with the specified name from the WebService * * @param name The name of the content * @return The loaded content * @throws IOException If an IO error occurs */ public DataHandler loadContent(String name) throws IOException { ContentStoreHttpPortService service = new ContentStoreHttpPortService(); service.setHandlerResolver(new HandlerResolver() { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerList = new ArrayList<>(); handlerList.add(wsSecurityHandler); return handlerList; } }); ContentStoreHttpPort loadContentPort = service.getContentStoreHttpPortSoap11(); SOAPBinding binding = (SOAPBinding) ((BindingProvider) loadContentPort).getBinding(); binding.setMTOMEnabled(true); LoadContentRequest request = objectFactory.createLoadContentRequest(); request.setName(name); LoadContentResponse response = loadContentPort.loadContent(request); DataHandler content = response.getContent(); return content; }
public static void addWsSecurityAndHttpConfigWithClientCert(Service ss, final String username, final String password, final String p12, final String jks, final String passwordP12, final String passwordJks){ String url = WsClientConfig.getDocboxServiceUrl(); final boolean clientcert = url.contains("ihe"); ss.setHandlerResolver(new HandlerResolver() { @SuppressWarnings("rawtypes") public List<Handler> getHandlerChain(PortInfo portInfo){ List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new SecurityHandler(username, password, clientcert, p12, jks, passwordP12, passwordJks)); return handlerList; } }); }
/** * This method adds a version SOAP Handler into the handler chain of a web * service. The version SOAP Handler is responsible to add a version * information in the header of the outbound SOAP message. * * @param service * set HandlerResolver for service by invoking service * <code>setHandlerResolver</code> method. * @return service with handler chain for handling version information. */ public Service addVersionInformationToClient(Service service) { service.setHandlerResolver(new HandlerResolver() { @SuppressWarnings("rawtypes") @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new VersionHandler(version)); return handlerList; } }); return service; }
public HandlerAnnotationInfo getHandlersForPortInfo(PortInfo info){ HandlerAnnotationInfo handlerInfo = new HandlerAnnotationInfo(); List<Handler> handlerClassList = new ArrayList<Handler>(); Set<String> roles = new HashSet<String>(); for(HandlerChainType hchain : handlerChains) { boolean hchainMatched = false; if((!hchain.isConstraintSet()) || JAXWSUtils.matchQNames(info.getServiceName(), hchain.getServiceNamePattern()) || JAXWSUtils.matchQNames(info.getPortName(), hchain.getPortNamePattern()) || hchain.getProtocolBindings().contains(info.getBindingID()) ){ hchainMatched = true; } if(hchainMatched) { for(HandlerType handler : hchain.getHandlers()) { try { Handler handlerClass = (Handler) loadClass(annotatedClass.getClassLoader(), handler.getHandlerClass()).newInstance(); callHandlerPostConstruct(handlerClass); handlerClassList.add(handlerClass); } catch (InstantiationException ie){ throw new RuntimeException(ie); } catch (IllegalAccessException e) { throw new RuntimeException(e); } roles.addAll(handler.getSoapRoles()); } } } handlerInfo.setHandlers(handlerClassList); handlerInfo.setRoles(roles); return handlerInfo; }
/** * Object.equals is overridden here so that PortInfo objects * can be compared when using them as keys in the map in * HandlerResolverImpl. This method relies on the equals() * methods of java.lang.String and javax.xml.namespace.QName. * * @param obj The PortInfo object to test for equality. * @return True if they match, and false if they do not or * if the object passed in is not a PortInfo. */ public boolean equals(Object obj) { if (obj instanceof PortInfo) { PortInfo info = (PortInfo) obj; if (bindingId.toString().equals(info.getBindingID()) && portName.equals(info.getPortName()) && serviceName.equals(info.getServiceName())) { return true; } } return false; }
HandlerResolver getResolver() { return new HandlerResolver() { public List<Handler> getHandlerChain(PortInfo portInfo) { return new ArrayList<Handler>( handlerModel.getHandlersForPortInfo(portInfo).getHandlers()); } }; }
protected HandlerResolver createHandlerResolver(XRoadClientConfig config, RovaServiceDetails details) { headerHandler = new HeaderHandler(config, details); return new HandlerResolver() { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlers = new ArrayList<>(); handlers.add(headerHandler); return handlers; } }; }
@SuppressWarnings("rawtypes") public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = new ArrayList<Handler>(); HeaderHandler hh = new HeaderHandler(username, password); handlerChain.add(hh); return handlerChain; }
public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = new ArrayList<Handler>(); HeaderHandler hh = new HeaderHandler(userName, password); handlerChain.add(hh); return handlerChain; }
@SuppressWarnings("unchecked") public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = new ArrayList<Handler>(); QName serviceQName = portInfo.getServiceName(); if(serviceQName.getLocalPart().equals("AWSECommerceService")) { handlerChain.add(new AwsHandler(awsSecretKey)); } return handlerChain; }
public String testService1(String reqStr) throws Exception { PortInfo info = new PortInfo() { @Override public String getBindingID() { return "http://schemas.xmlsoap.org/wsdl/soap/http"; } @Override public QName getPortName() { return null; } @Override public QName getServiceName() { return null; } }; HandlerResolver resolver = service1.getHandlerResolver(); @SuppressWarnings("rawtypes") List<Handler> handlerChain = resolver.getHandlerChain(info); if("[LogHandler, AuthorizationHandler, RoutingHandler, MimeHandler]".equals(handlerChain.toString()) == false) throw new IllegalStateException("Unexpected resolver handlers: " + handlerChain); Endpoint port = service1.getPort(Endpoint.class); return port.echo(reqStr); }
@SuppressWarnings("rawtypes") protected List<Handler> createHandlerChain(PortInfo portInfo, QName portQName, QName serviceQName, String bindingID) { List<Handler> chain = new ArrayList<Handler>(); InputStream is = getInputStream(); try { if (is == null) { throw MESSAGES.handlerConfigFileNotFound(handlerFile); } Element el = DOMUtils.parse(is, Holder.builder); if (!ParserConstants.JAVAEE_NS.equals(el.getNamespaceURI()) || !ParserConstants.HANDLER_CHAINS.equals(el.getLocalName())) { throw MESSAGES.differentElementExpected(handlerFile, "{" + ParserConstants.JAVAEE_NS + "}" + ParserConstants.HANDLER_CHAINS, "{" + el.getNamespaceURI() + "}" + el.getLocalName()); } Node node = el.getFirstChild(); while (node != null) { if (node instanceof Element) { el = (Element)node; if (!el.getNamespaceURI().equals(ParserConstants.JAVAEE_NS) || !el.getLocalName().equals(ParserConstants.HANDLER_CHAIN)) { throw MESSAGES.differentElementExpected(handlerFile, "{" + ParserConstants.JAVAEE_NS + "}" + ParserConstants.HANDLER_CHAIN, "{" + el.getNamespaceURI() + "}" + el.getLocalName()); } processHandlerChainElement(el, chain, portQName, serviceQName, bindingID); } node = node.getNextSibling(); } } catch (WebServiceException e) { throw e; } catch (Exception e) { throw MESSAGES.noHandlerChainFound(handlerFile, e); } assert chain != null; return sortHandlers(chain); }
/** * Creates an object implementing the service interface that needs to be called. * * @return the service object implementing the service interface */ public T getService() { authorizationData.validate(); WebService webServiceAnnotation = serviceInterface.getAnnotation(WebService.class); final String ns = webServiceAnnotation.targetNamespace(); final Map<String, String> headers = new HashMap<String, String>(); headers.put("CustomerAccountId", Long.toString(authorizationData.getAccountId())); headers.put("CustomerId", Long.toString(authorizationData.getCustomerId())); headers.put("DeveloperToken", authorizationData.getDeveloperToken()); refreshOAuthTokensIfNeeded(); this.authorizationData.getAuthentication().addHeaders(new HeadersImpl() { @Override public void addHeader(String name, String value) { headers.put(name, value); } }); service.setHandlerResolver(new HandlerResolver() { @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new HeaderHandler(ns, headers)); handlerList.add(MessageHandler.getInstance()); return handlerList; } }); T port = serviceFactory.createProxyFromService(service, environment, serviceInterface); return port; }
@SuppressWarnings("rawtypes") @Override public List<Handler> getHandlerChain(PortInfo arg0) { List<Handler> handlerChain = new ArrayList<Handler>(); handlerChain.add(new SOAPMessageLoggingHandler()); return handlerChain; }
private HandlerResolver handlerResolver() { return new HandlerResolver() { @SuppressWarnings("rawtypes") @Override public List<Handler> getHandlerChain(PortInfo arg0) { List<Handler> handlerChain = new ArrayList<Handler>(); handlerChain.add(new SOAPMessageLoggingHandler()); return handlerChain; } }; }
@SuppressWarnings("rawtypes") @Override public List<Handler> getHandlerChain(PortInfo portInfo) { List<Handler> handlerChain = new ArrayList<Handler>(); handlerChain.add(new SOAPMessageLoggingHandler()); return handlerChain; }
@Override @SuppressWarnings("rawtypes") public List<Handler> getHandlerChain(PortInfo arg0) { List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(handler); return handlerList; }