use of org.apache.cxf.jaxws.handler.PortInfoImpl in project cxf by apache.
the class ServiceImpl method createPort.
protected <T> T createPort(QName portName, EndpointReferenceType epr, Class<T> serviceEndpointInterface, WebServiceFeature... features) {
LOG.log(Level.FINE, "creating port for portName", portName);
LOG.log(Level.FINE, "endpoint reference:", epr);
LOG.log(Level.FINE, "endpoint interface:", serviceEndpointInterface);
JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
JaxWsClientFactoryBean clientFac = (JaxWsClientFactoryBean) proxyFac.getClientFactoryBean();
JaxWsServiceFactoryBean serviceFactory = (JaxWsServiceFactoryBean) proxyFac.getServiceFactory();
List<WebServiceFeature> f = getAllFeatures(features);
proxyFac.initFeatures();
if (f != null) {
serviceFactory.setWsFeatures(f);
}
proxyFac.setBus(bus);
proxyFac.setServiceClass(serviceEndpointInterface);
proxyFac.setServiceName(serviceName);
if (epr != null && epr.getAddress() != null && epr.getAddress().getValue() != null) {
clientFac.setAddress(epr.getAddress().getValue());
}
if (wsdlURL != null) {
proxyFac.setWsdlURL(wsdlURL);
}
configureObject(proxyFac);
configureObject(clientFac);
if (portName == null) {
QName portTypeName = getPortTypeName(serviceEndpointInterface);
Service service = serviceFactory.getService();
if (service == null) {
serviceFactory.setServiceClass(serviceEndpointInterface);
serviceFactory.setBus(getBus());
service = serviceFactory.create();
}
EndpointInfo ei = ServiceModelUtil.findBestEndpointInfo(portTypeName, service.getServiceInfos());
if (ei != null) {
portName = ei.getName();
} else {
portName = serviceFactory.getEndpointName();
}
}
serviceFactory.setEndpointName(portName);
if (epr != null) {
clientFac.setEndpointReference(epr);
}
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null) {
clientFac.setBindingId(portInfo.getBindingID());
clientFac.setAddress(portInfo.getAddress());
}
// configureObject(portName.toString() + ".jaxws-client.proxyFactory", proxyFac);
if (clazz != ServiceImpl.class) {
// handlerchain should be on the generated Service object
proxyFac.setLoadHandlers(false);
}
Object obj = proxyFac.create();
// Configure the Service
Service service = serviceFactory.getService();
configureObject(service);
// Configure the JaxWsEndpoitnImpl
Client client = ClientProxy.getClient(obj);
client.getEndpoint().setExecutor(executor);
client.setExecutor(executor);
JaxWsEndpointImpl jaxwsEndpoint = (JaxWsEndpointImpl) client.getEndpoint();
configureObject(jaxwsEndpoint);
@SuppressWarnings("rawtypes") List<Handler> hc = jaxwsEndpoint.getJaxwsBinding().getHandlerChain();
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
jaxwsEndpoint.getJaxwsBinding().setHandlerChain(hc);
LOG.log(Level.FINE, "created proxy", obj);
if (portInfo == null) {
addPort(portName, clientFac.getBindingId(), clientFac.getAddress());
}
return serviceEndpointInterface.cast(obj);
}
use of org.apache.cxf.jaxws.handler.PortInfoImpl 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);
}
use of org.apache.cxf.jaxws.handler.PortInfoImpl in project cxf by apache.
the class ServiceImpl method getJaxwsEndpoint.
private JaxWsClientEndpointImpl getJaxwsEndpoint(QName portName, AbstractServiceFactoryBean sf, WebServiceFeature... features) {
Service service = sf.getService();
EndpointInfo ei;
if (portName == null) {
ei = service.getServiceInfos().get(0).getEndpoints().iterator().next();
} else {
ei = service.getEndpointInfo(portName);
if (ei == null) {
PortInfoImpl portInfo = getPortInfo(portName);
if (null != portInfo) {
try {
ei = createEndpointInfo(sf, portName, portInfo);
} catch (BusException e) {
throw new WebServiceException(e);
}
}
}
}
if (ei == null) {
Message msg = new Message("INVALID_PORT", BUNDLE, portName);
throw new WebServiceException(msg.toString());
}
// When the dispatch is created from EPR, the EPR's address will be set in portInfo
PortInfoImpl portInfo = getPortInfo(portName);
if (portInfo != null && portInfo.getAddress() != null && !portInfo.getAddress().equals(ei.getAddress())) {
ei.setAddress(portInfo.getAddress());
}
try {
return new JaxWsClientEndpointImpl(bus, service, ei, this, getAllFeatures(features));
} catch (EndpointException e) {
throw new WebServiceException(e);
}
}
use of org.apache.cxf.jaxws.handler.PortInfoImpl in project cxf by apache.
the class ServiceImpl method addPort.
public final void addPort(QName portName, String bindingId, String address) {
PortInfoImpl portInfo = new PortInfoImpl(bindingId, portName, serviceName);
portInfo.setAddress(address);
portInfos.put(portName, portInfo);
}
use of org.apache.cxf.jaxws.handler.PortInfoImpl in project cxf by apache.
the class ServiceImpl method createDispatch.
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
// using this instead of JaxWsClientFactoryBean so that handlers are configured
JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
// Initialize Features.
configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
final AbstractServiceFactoryBean sf;
try {
DataBinding db;
if (context != null) {
db = new JAXBDataBinding(context);
} else {
db = new SourceDataBinding(type);
}
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
}
JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
// if the client factory has properties specified, then set those into the endpoint
if (clientFac.getProperties() != null) {
endpoint.putAll(clientFac.getProperties());
}
// add all the client factory features onto the endpoint feature list
endpoint.getFeatures().addAll(clientFac.getFeatures());
// if the client factory has a bus specified (other than the thread default),
// then use that for the client. Otherwise use the bus from this service.
Bus clientBus = getBus();
if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
clientBus = clientFac.getBus();
}
@SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
// CXF-3956
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
endpoint.getJaxwsBinding().setHandlerChain(hc);
// create the client object, then initialize the endpoint features against it
Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
for (Feature af : endpoint.getFeatures()) {
af.initialize(client, clientBus);
}
// CXF-2822
initIntercepors(client, clientFac);
if (executor != null) {
client.getEndpoint().setExecutor(executor);
}
// then try to get it from the wsdl
if (!StringUtils.isEmpty(clientFac.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
} else {
// Set the the EPR's address in EndpointInfo
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
}
}
Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
configureObject(disp);
return disp;
}
Aggregations