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()); }
/** * 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; }
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; } }; }
public YpaXRoadRiClient(XRoadClientConfig config) { RovaServiceDetails details = RovaServices.getDetails(RovaServices.RovaService.ROLES.name()); for (Server server : config.getServers()) { endPoints.add(new EndPoint(server, details.getPath())); } HandlerResolver hs = createHandlerResolver(config, details); rovaRolesService.setHandlerResolver(hs); }
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); }
/** * 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; }
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; } }; }
public HandlerResolver getHandlerResolver() { verifyServiceDescriptionActive(); if (handlerResolver == null) { handlerResolver = new HandlerResolverImpl(serviceDescription, this); } return handlerResolver; }
public void testHandlerResolver() { String path = "/configuration/handlers/handler.xml"; File file = new File(testResourceDir, path); HandlerResolver resolver = new HandlerResolverImpl(file); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(2, list.size()); }
/** * Test creating a service with a sparse composite that contains handler configuration * information for this service delegate. Verify that the handlers are included in the * chain. */ public void testServiceWithComposite() { 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); ServiceDelegate.setServiceMetadata(sparseComposite); Service service = Service.create(serviceQName); ClientMetadataHandlerChainTestSEI port = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class); // Verify the HandlerResolver on the service knows about the handlers in the sparse composite HandlerResolver resolver = service.getHandlerResolver(); assertNotNull(resolver); PortInfo pi = new DummyPortInfo(); List<Handler> list = resolver.getHandlerChain(pi); assertEquals(2, list.size()); // Verify that ports created under the service have handlers BindingProvider bindingProvider = (BindingProvider) port; Binding binding = (Binding) bindingProvider.getBinding(); List<Handler> portHandlers = binding.getHandlerChain(); assertEquals(2, portHandlers.size()); assertTrue(containSameHandlers(portHandlers, list)); // Verify that a subsequent port are different and that they also gets the correct handlers ClientMetadataHandlerChainTestSEI port2 = service.getPort(portQName, ClientMetadataHandlerChainTestSEI.class); BindingProvider bindingProvider2 = (BindingProvider) port2; Binding binding2 = (Binding) bindingProvider2.getBinding(); List<Handler> portHandlers2 = binding2.getHandlerChain(); assertNotSame(port, port2); assertEquals(2, portHandlers2.size()); assertTrue(containSameHandlers(portHandlers2, list)); }
@Test public void shouldCreateSimpleHandlerResolver() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.createSimpleHandlerResolver(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverWithOtherHandlerByType() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add(TestHandler.class).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(2)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TestHandler.class)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(1).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverWithOtherHandlerByInstance() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add(new TestHandler()).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(2)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TestHandler.class)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(1).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverAndIgnoreHandlerWithoutDefaultConstructor() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add(TestHandlerWithoutDefaultConstructor.class).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverAndIgnoreNullValuedHandlerInstance() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add((SOAPHandler)null).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
@Test public void shouldCreateHandlerResolverAndIgnoreNullValuedHandlerType() { HandlerResolver handlerResolver = TraceeClientHandlerResolver.buildHandlerResolver().add((Class<SOAPHandler<SOAPMessageContext>>)null).build(); MatcherAssert.assertThat(handlerResolver, Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo), Matchers.notNullValue()); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).size(), Matchers.is(1)); MatcherAssert.assertThat(handlerResolver.getHandlerChain(portInfo).get(0).getClass(), Matchers.typeCompatibleWith(TraceeClientErrorLoggingHandler.class)); }
public HandlerResolverImpl(HandlerResolver resolver) { this.resolver = resolver; }
@Override HandlerResolver getResolver() { return resolver; }
public HandlerResolver getHandlerResolver() { return handlerConfigurator.getResolver(); }
public void setHandlerResolver(HandlerResolver resolver) { handlerConfigurator = new HandlerResolverImpl(resolver); }