Search in sources :

Example 1 with PortInfoImpl

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);
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) Handler(javax.xml.ws.handler.Handler) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) WebServiceFeature(javax.xml.ws.WebServiceFeature) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 2 with PortInfoImpl

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);
}
Also used : HandlerResolverImpl(org.apache.openejb.core.webservices.HandlerResolverImpl) Handler(javax.xml.ws.handler.Handler) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl)

Example 3 with PortInfoImpl

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);
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) BusException(org.apache.cxf.BusException)

Example 4 with PortInfoImpl

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);
}
Also used : PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl)

Example 5 with PortInfoImpl

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;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Aggregations

PortInfoImpl (org.apache.cxf.jaxws.handler.PortInfoImpl)6 Handler (javax.xml.ws.handler.Handler)3 WebService (javax.jws.WebService)2 QName (javax.xml.namespace.QName)2 WebServiceException (javax.xml.ws.WebServiceException)2 WebServiceFeature (javax.xml.ws.WebServiceFeature)2 Client (org.apache.cxf.endpoint.Client)2 JaxWsEndpointImpl (org.apache.cxf.jaxws.support.JaxWsEndpointImpl)2 Service (org.apache.cxf.service.Service)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 Map (java.util.Map)1 Bus (org.apache.cxf.Bus)1 BusException (org.apache.cxf.BusException)1 Message (org.apache.cxf.common.i18n.Message)1 DataBinding (org.apache.cxf.databinding.DataBinding)1 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)1 ClientImpl (org.apache.cxf.endpoint.ClientImpl)1 EndpointException (org.apache.cxf.endpoint.EndpointException)1