use of javax.xml.ws.handler.HandlerResolver in project scout.rt by eclipse.
the class PortProducer method provide.
/**
* Creates a new Port to interact with the webservice endpoint.
*/
@Override
public PORT provide() {
try {
// Create the service
final Constructor<? extends Service> constructor = m_serviceClazz.getConstructor(URL.class, QName.class);
@SuppressWarnings("unchecked") final SERVICE service = (SERVICE) constructor.newInstance(m_wsdlLocation, new QName(m_targetNamespace, m_serviceName));
// Install the handler chain
service.setHandlerResolver(new HandlerResolver() {
@Override
public List<Handler> getHandlerChain(final PortInfo portInfo) {
final List<Handler<? extends MessageContext>> handlerChain = new ArrayList<>();
m_initializer.initHandlers(handlerChain);
for (int i = 0; i < handlerChain.size(); i++) {
handlerChain.set(i, proxyHandler(handlerChain.get(i)));
}
@SuppressWarnings("unchecked") final List<Handler> handlers = TypeCastUtility.castValue(handlerChain, List.class);
return handlers;
}
});
// Install implementor specific webservice features
final List<WebServiceFeature> webServiceFeatures = new ArrayList<>();
m_initializer.initWebServiceFeatures(webServiceFeatures);
// Create the port
return service.getPort(m_portTypeClazz, CollectionUtility.toArray(webServiceFeatures, WebServiceFeature.class));
} catch (final ReflectiveOperationException e) {
throw new WebServiceException("Failed to instantiate webservice stub.", e);
}
}
use of javax.xml.ws.handler.HandlerResolver in project scout.rt by eclipse.
the class ServicePool method createElement.
@Override
protected SERVICE createElement() {
try {
// Create the service
final Constructor<? extends Service> constructor = m_serviceClazz.getConstructor(URL.class, QName.class);
@SuppressWarnings("unchecked") final SERVICE service = (SERVICE) constructor.newInstance(m_wsdlLocation, new QName(m_targetNamespace, m_serviceName));
// Install the handler chain
service.setHandlerResolver(new HandlerResolver() {
@Override
public List<Handler> getHandlerChain(final PortInfo portInfo) {
final List<Handler<? extends MessageContext>> handlerChain = new ArrayList<>();
m_initializer.initHandlers(handlerChain);
for (int i = 0; i < handlerChain.size(); i++) {
handlerChain.set(i, proxyHandler(handlerChain.get(i)));
}
@SuppressWarnings("unchecked") final List<Handler> handlers = TypeCastUtility.castValue(handlerChain, List.class);
return handlers;
}
});
return service;
} catch (ReflectiveOperationException e) {
throw new WebServiceException("Failed to instantiate webservice stub.", e);
}
}
use of javax.xml.ws.handler.HandlerResolver in project jbossws-cxf by jbossws.
the class HandlerChainClient method testService1.
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);
}
use of javax.xml.ws.handler.HandlerResolver in project tomee by apache.
the class JaxWsServiceReference method getObject.
public Object getObject() throws NamingException {
final String referenceClassName = referenceClass != null ? referenceClass.getName() : null;
final Set<PortAddress> portAddresses = getPortAddressRegistry().getPorts(id, serviceQName, referenceClassName);
// if we only have one address, use that address for the wsdl and the serviceQName
URL wsdlUrl = this.wsdlUrl;
QName serviceQName = this.serviceQName;
if (portAddresses.size() == 1) {
final PortAddress portAddress = portAddresses.iterator().next();
try {
wsdlUrl = new URL(portAddress.getAddress() + "?wsdl");
} catch (final MalformedURLException e) {
// no-op
}
serviceQName = portAddress.getServiceQName();
}
// add the port addresses to the portRefData
final Map<QName, PortRefData> portsByQName = new HashMap<>();
final List<PortRefData> ports = new ArrayList<>(portRefs.size() + portAddresses.size());
for (final PortRefData portRef : portRefs) {
final PortRefData port = new PortRefData(portRef);
if (port.getQName() != null) {
portsByQName.put(port.getQName(), port);
}
ports.add(port);
}
// add PortRefData for any portAddress not added above
for (final PortAddress portAddress : portAddresses) {
PortRefData port = portsByQName.get(portAddress.getPortQName());
if (port == null) {
port = new PortRefData();
port.setQName(portAddress.getPortQName());
port.setServiceEndpointInterface(portAddress.getServiceEndpointInterface());
port.getAddresses().add(portAddress.getAddress());
ports.add(port);
} else {
port.getAddresses().add(portAddress.getAddress());
if (port.getServiceEndpointInterface() == null) {
port.setServiceEndpointInterface(portAddress.getServiceEndpointInterface());
}
}
}
final WebServiceClientCustomizer customizer = SystemInstance.get().getComponent(WebServiceClientCustomizer.class);
final Properties configuration = properties == null ? new Properties() : properties;
ProviderWrapper.beforeCreate(ports, customizer, properties);
Service instance;
try {
instance = null;
if (Service.class.equals(serviceClass)) {
instance = Service.create(wsdlUrl, serviceQName);
} else {
try {
instance = serviceClass.getConstructor(URL.class, QName.class).newInstance(wsdlUrl, serviceQName);
} catch (final Throwable e) {
throw (NamingException) new NamingException("Could not instantiate jax-ws service class " + serviceClass.getName()).initCause(e);
}
}
} finally {
ProviderWrapper.afterCreate();
}
if (!handlerChains.isEmpty()) {
final HandlerResolver handlerResolver = new HandlerResolverImpl(handlerChains, injections, new InitialContext());
instance.setHandlerResolver(handlerResolver);
}
final Object port;
if (referenceClass != null && !Service.class.isAssignableFrom(referenceClass)) {
final WebServiceFeature[] features = customizer == null ? null : customizer.features(serviceQName, configuration);
// do port lookup
if (features == null || features.length == 0) {
port = instance.getPort(referenceClass);
} else {
port = instance.getPort(referenceClass, features);
}
} else {
// return service
port = instance;
}
// register the service data so it can be fetched when the service is passed over the EJBd protocol
final ServiceRefData serviceRefData = new ServiceRefData(id, serviceQName, serviceClass, portQName, referenceClass, wsdlUrl, handlerChains, portRefs);
ServiceRefData.putServiceRefData(port, serviceRefData);
return port;
}
use of javax.xml.ws.handler.HandlerResolver in project tomee by apache.
the class WsMetaData method createWebservice.
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;
}
Aggregations