use of org.apache.openejb.core.webservices.HandlerResolverImpl 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<QName, PortRefData>();
final List<PortRefData> ports = new ArrayList<PortRefData>(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 org.apache.openejb.core.webservices.HandlerResolverImpl in project tomee by apache.
the class CxfEndpoint method initHandlers.
/**
* Set appropriate handlers for the port/service/bindings.
*/
protected void initHandlers() throws Exception {
PortInfoImpl portInfo = new PortInfoImpl(implInfo.getBindingType(), serviceFactory.getEndpointName(), service.getName());
handlerResolver = new HandlerResolverImpl(port.getHandlerChains(), port.getInjections(), context);
List<Handler> chain = handlerResolver.getHandlerChain(portInfo);
getBinding().setHandlerChain(chain);
}
Aggregations