Java Code Examples for javax.xml.ws.Service#setHandlerResolver()

The following examples show how to use javax.xml.ws.Service#setHandlerResolver() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Create a JAX-WS Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 */
public Service createJaxWsService() {
	Assert.notNull(this.serviceName, "No service name specified");
	Service service;

	if (this.serviceFeatures != null) {
		service = (this.wsdlDocumentUrl != null ?
			Service.create(this.wsdlDocumentUrl, getQName(this.serviceName), this.serviceFeatures) :
			Service.create(getQName(this.serviceName), this.serviceFeatures));
	}
	else {
		service = (this.wsdlDocumentUrl != null ?
				Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
				Service.create(getQName(this.serviceName)));
	}

	if (this.executor != null) {
		service.setExecutor(this.executor);
	}
	if (this.handlerResolver != null) {
		service.setHandlerResolver(this.handlerResolver);
	}

	return service;
}
 
Example 2
/**
 * Create a JAX-WS Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 */
public Service createJaxWsService() {
	Assert.notNull(this.serviceName, "No service name specified");
	Service service;

	if (this.serviceFeatures != null) {
		service = (this.wsdlDocumentUrl != null ?
			Service.create(this.wsdlDocumentUrl, getQName(this.serviceName), this.serviceFeatures) :
			Service.create(getQName(this.serviceName), this.serviceFeatures));
	}
	else {
		service = (this.wsdlDocumentUrl != null ?
				Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
				Service.create(getQName(this.serviceName)));
	}

	if (this.executor != null) {
		service.setExecutor(this.executor);
	}
	if (this.handlerResolver != null) {
		service.setHandlerResolver(this.handlerResolver);
	}

	return service;
}
 
Example 3
/**
 * Create a JAX-WS Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 */
@UsesJava7  // optional use of Service#create with WebServiceFeature[]
public Service createJaxWsService() {
	Assert.notNull(this.serviceName, "No service name specified");
	Service service;

	if (this.serviceFeatures != null) {
		service = (this.wsdlDocumentUrl != null ?
			Service.create(this.wsdlDocumentUrl, getQName(this.serviceName), this.serviceFeatures) :
			Service.create(getQName(this.serviceName), this.serviceFeatures));
	}
	else {
		service = (this.wsdlDocumentUrl != null ?
				Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
				Service.create(getQName(this.serviceName)));
	}

	if (this.executor != null) {
		service.setExecutor(this.executor);
	}
	if (this.handlerResolver != null) {
		service.setHandlerResolver(this.handlerResolver);
	}

	return service;
}
 
Example 4
/**
 * Create a JAX-WS Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 */
@UsesJava7  // optional use of Service#create with WebServiceFeature[]
public Service createJaxWsService() {
	Assert.notNull(this.serviceName, "No service name specified");
	Service service;

	if (this.serviceFeatures != null) {
		service = (this.wsdlDocumentUrl != null ?
			Service.create(this.wsdlDocumentUrl, getQName(this.serviceName), this.serviceFeatures) :
			Service.create(getQName(this.serviceName), this.serviceFeatures));
	}
	else {
		service = (this.wsdlDocumentUrl != null ?
				Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
				Service.create(getQName(this.serviceName)));
	}

	if (this.executor != null) {
		service.setExecutor(this.executor);
	}
	if (this.handlerResolver != null) {
		service.setHandlerResolver(this.handlerResolver);
	}

	return service;
}
 
Example 5
@Test
public void transferClientTpicToServerBackend() throws Exception {
	clientBackend.put("inRequest", "yes");

	Service calculatorService = Service.create(new URL(ENDPOINT_URL + "?wsdl"), ENDPOINT_QNAME);
	calculatorService.setHandlerResolver(new TraceeClientHandlerResolver(clientBackend));

	final TraceeJaxWsEndpoint remote = calculatorService.getPort(TraceeJaxWsEndpoint.class);
	final List<String> result = remote.getCurrentTraceeContext();

	// checking server context as response.
	assertThat(result, hasItem(TraceeConstants.INVOCATION_ID_KEY));
	assertThat(result, hasItem("inRequest"));
	assertThat(result, hasItem("yes"));

	// checking client context. We should receive the pair "called"->"yes" and the invocationId from the server.
	assertThat(clientBackend.copyToMap(), hasKey(TraceeConstants.INVOCATION_ID_KEY));
	assertThat(clientBackend.copyToMap(), hasEntry("called", "yes"));
}
 
Example 6
/**
 * 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;
}
 
Example 7
Source Project: development   File: WebServiceProxy.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> T get(String baseUrl, final String versionWSDL,
        String versionHeader, String auth, String namespace,
        Class<T> remoteInterface, String userName, String password, String tenantId, String orgId)
        throws Exception {
    String wsdlUrl = baseUrl + "/oscm/" + versionWSDL + "/"
            + remoteInterface.getSimpleName() + "/" + auth + "?wsdl";
    
    if (tenantId != null) {
        wsdlUrl += "&" + TENANT_ID + "=" + tenantId;
    }
    
    URL url = new URL(wsdlUrl);
    QName qName = new QName(namespace, remoteInterface.getSimpleName());
    Service service = Service.create(url, qName);
    if ("v1.7".equals(versionWSDL) || "v1.8".equals(versionWSDL)) {
        service.setHandlerResolver(new HandlerResolver() {
            @SuppressWarnings("rawtypes")
            @Override
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlerList = new ArrayList<Handler>();
                handlerList.add(new VersionHandlerCtmg(versionWSDL));
                return handlerList;
            }
        });
    } else {
        ClientVersionHandler versionHandler = new ClientVersionHandler(
                versionHeader);
        service = versionHandler.addVersionInformationToClient(service);
    }
    T port = service.getPort(remoteInterface);
    BindingProvider bindingProvider = (BindingProvider) port;
    Map<String, Object> clientRequestContext = bindingProvider
            .getRequestContext();
    if ("STS".equals(auth)) {
        clientRequestContext.put(XWSSConstants.USERNAME_PROPERTY, userName);
        clientRequestContext.put(XWSSConstants.PASSWORD_PROPERTY, password);
        
        
        clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                baseUrl + "/" + remoteInterface.getSimpleName() + "/"
                        + auth);
        
        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        
        if(tenantId!= null){
            headers.put(TENANT_ID, Collections.singletonList(tenantId)); 
        }
        
        if(orgId!= null){
            headers.put("organizationId", Collections.singletonList(orgId)); 
        }
        
        clientRequestContext.put(MessageContext.HTTP_REQUEST_HEADERS,
                headers);
        
    } else {
        clientRequestContext.put(BindingProvider.USERNAME_PROPERTY,
                userName);
        clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY,
                password);
        clientRequestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                baseUrl + "/" + remoteInterface.getSimpleName() + "/"
                        + auth);
    }
    return port;
}
 
Example 8
Source Project: tomee   File: WsMetaData.java    License: Apache License 2.0 4 votes vote down vote up
public Object createWebservice() throws Exception {
    // load service class which is used to construct the port
    Class<? extends Service> serviceClass = loadClass(serviceClassName).asSubclass(Service.class);
    if (serviceClass == null) {
        throw new NamingException("Could not load service type class " + serviceClassName);
    }

    // load the reference class which is the ultimate type of the port
    final Class<?> referenceClass = loadClass(referenceClassName);

    // if ref class is a subclass of Service, use it for the service class
    if (referenceClass != null && Service.class.isAssignableFrom(referenceClass)) {
        serviceClass = referenceClass.asSubclass(Service.class);
    }

    // Service QName
    final QName serviceQName = QName.valueOf(this.serviceQName);

    // WSDL URL
    final URL wsdlLocation = new URL(this.wsdlUrl);

    JaxWsProviderWrapper.beforeCreate(portRefs);
    Service instance;
    try {
        instance = null;
        if (Service.class.equals(serviceClass)) {
            instance = Service.create(wsdlLocation, serviceQName);
        } else {
            try {
                instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(wsdlLocation, serviceQName);
            } catch (Throwable e) {
                throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
            }
        }
    } finally {
        JaxWsProviderWrapper.afterCreate();
    }

    if (!handlerChains.isEmpty()) {
        final InjectionMetaData injectionMetaData = ClientInstance.get().getComponent(InjectionMetaData.class);
        final List<Injection> injections = injectionMetaData.getInjections();
        final HandlerResolver handlerResolver = new ClientHandlerResolverImpl(handlerChains, injections, new InitialContext());
        instance.setHandlerResolver(handlerResolver);
    }

    final Object port;
    if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
        // do port lookup
        port = instance.getPort(referenceClass);
    } else {
        // return service
        port = instance;
    }
    return port;
}