Search in sources :

Example 36 with Service

use of org.apache.cxf.service.Service in project cxf by apache.

the class ServiceImpl method createEndpointInfo.

private EndpointInfo createEndpointInfo(AbstractServiceFactoryBean serviceFactory, QName portName, PortInfoImpl portInfo) throws BusException {
    String address = portInfo.getAddress();
    String bindingID = BindingID.getBindingID(portInfo.getBindingID());
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        // the bindingId might be the transportId, just attempt to
        // load it to force the factory to load
        dfm.getDestinationFactory(bindingID);
    } catch (BusException ex) {
    // ignore
    }
    DestinationFactory df = dfm.getDestinationFactoryForUri(address);
    final String transportId;
    if (df != null && df.getTransportIds() != null && !df.getTransportIds().isEmpty()) {
        transportId = df.getTransportIds().get(0);
    } else {
        transportId = bindingID;
    }
    Object config = null;
    if (serviceFactory instanceof JaxWsServiceFactoryBean) {
        config = new JaxWsSoapBindingConfiguration((JaxWsServiceFactoryBean) serviceFactory);
    }
    BindingInfo bindingInfo = bus.getExtension(BindingFactoryManager.class).getBindingFactory(bindingID).createBindingInfo(serviceFactory.getService(), bindingID, config);
    Service service = serviceFactory.getService();
    service.getServiceInfos().get(0).addBinding(bindingInfo);
    EndpointInfo ei = new EndpointInfo(service.getServiceInfos().get(0), transportId);
    ei.setName(portName);
    ei.setAddress(address);
    ei.setBinding(bindingInfo);
    service.getServiceInfos().get(0).addEndpoint(ei);
    return ei;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) JaxWsSoapBindingConfiguration(org.apache.cxf.jaxws.binding.soap.JaxWsSoapBindingConfiguration) BusException(org.apache.cxf.BusException)

Example 37 with Service

use of org.apache.cxf.service.Service 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 38 with Service

use of org.apache.cxf.service.Service in project cxf by apache.

the class ServiceImpl method createDispatchService.

private AbstractServiceFactoryBean createDispatchService(DataBinding db) {
    AbstractServiceFactoryBean serviceFactory;
    final Service dispatchService;
    if (null != wsdlURL) {
        WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
        dispatchService = sf.create();
        dispatchService.setDataBinding(db);
        serviceFactory = sf;
    } else {
        ReflectionServiceFactoryBean sf = new JaxWsServiceFactoryBean();
        sf.setBus(bus);
        sf.setServiceName(serviceName);
        // maybe we can find another way to create service which have no SEI
        sf.setServiceClass(DummyImpl.class);
        sf.setDataBinding(db);
        dispatchService = sf.create();
        serviceFactory = sf;
    }
    configureObject(dispatchService);
    for (ServiceInfo si : dispatchService.getServiceInfos()) {
        si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
        if (null == wsdlURL) {
            for (EndpointInfo ei : si.getEndpoints()) {
                ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
            }
        }
        for (BindingInfo bind : si.getBindings()) {
            for (BindingOperationInfo bop : bind.getOperations()) {
                // force to bare, no unwrapping
                if (bop.isUnwrappedCapable()) {
                    bop.getOperationInfo().setUnwrappedOperation(null);
                    bop.setUnwrappedOperation(null);
                }
            }
        }
    }
    return serviceFactory;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)

Example 39 with Service

use of org.apache.cxf.service.Service in project cxf by apache.

the class OutgoingChainInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    control = EasyMock.createNiceControl();
    phases = new ArrayList<>();
    phases.add(new Phase(Phase.SEND, 1000));
    empty = new ArrayList<>();
    bus = control.createMock(Bus.class);
    PhaseManager pm = new PhaseManagerImpl();
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(pm).anyTimes();
    service = control.createMock(Service.class);
    endpoint = control.createMock(Endpoint.class);
    binding = control.createMock(Binding.class);
    EasyMock.expect(endpoint.getBinding()).andStubReturn(binding);
    MessageImpl m = new MessageImpl();
    EasyMock.expect(binding.createMessage()).andStubReturn(m);
    EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
    EasyMock.expect(endpoint.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(service.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(bus.getOutInterceptors()).andReturn(empty);
    bopInfo = control.createMock(BindingOperationInfo.class);
    opInfo = control.createMock(OperationInfo.class);
    mInfo = control.createMock(MessageInfo.class);
    bmInfo = control.createMock(BindingMessageInfo.class);
    EasyMock.expect(bopInfo.getOperationInfo()).andReturn(opInfo).times(3);
    EasyMock.expect(opInfo.getOutput()).andReturn(mInfo);
    EasyMock.expect(opInfo.isOneWay()).andReturn(false);
    EasyMock.expect(bopInfo.getOutput()).andReturn(bmInfo);
    control.replay();
}
Also used : Binding(org.apache.cxf.binding.Binding) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Phase(org.apache.cxf.phase.Phase) PhaseManager(org.apache.cxf.phase.PhaseManager) Service(org.apache.cxf.service.Service) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) MessageImpl(org.apache.cxf.message.MessageImpl) Before(org.junit.Before)

Example 40 with Service

use of org.apache.cxf.service.Service in project cxf by apache.

the class OperationInfoAuthorizingInterceptorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    Exchange ex = setUpExchange();
    Service service = EasyMock.createMock(Service.class);
    ex.put(Service.class, service);
    MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
    EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md).anyTimes();
    BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
    ex.put(BindingOperationInfo.class, boi);
    EasyMock.expect(md.getMethod(boi)).andReturn(null);
    OperationInfo opinfo = EasyMock.createMock(OperationInfo.class);
    EasyMock.expect(opinfo.getName()).andReturn(new QName("urn:test", "echo")).anyTimes();
    EasyMock.expect(boi.getOperationInfo()).andReturn(opinfo).anyTimes();
    EasyMock.replay(service, md, boi, opinfo);
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Before(org.junit.Before)

Aggregations

Service (org.apache.cxf.service.Service)270 Test (org.junit.Test)167 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)138 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)138 Client (org.apache.cxf.endpoint.Client)128 HashMap (java.util.HashMap)100 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)89 ArrayList (java.util.ArrayList)81 QName (javax.xml.namespace.QName)69 Properties (java.util.Properties)65 Endpoint (org.apache.cxf.endpoint.Endpoint)45 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)44 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)37 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)33 Server (org.apache.cxf.endpoint.Server)27 OperationInfo (org.apache.cxf.service.model.OperationInfo)26 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)23 Exchange (org.apache.cxf.message.Exchange)22 Bus (org.apache.cxf.Bus)21 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)21