Search in sources :

Example 6 with ClientImpl

use of org.apache.cxf.endpoint.ClientImpl in project cxf by apache.

the class ClientMtomXopTest method createPort.

private <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface, boolean enableMTOM, boolean installInterceptors) throws Exception {
    ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
    Bus bus = getStaticBus();
    serviceFactory.setBus(bus);
    serviceFactory.setServiceName(serviceName);
    serviceFactory.setServiceClass(serviceEndpointInterface);
    serviceFactory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl"));
    Service service = serviceFactory.create();
    EndpointInfo ei = service.getEndpointInfo(portName);
    JaxWsEndpointImpl jaxwsEndpoint = new JaxWsEndpointImpl(bus, service, ei);
    SOAPBinding jaxWsSoapBinding = new SOAPBindingImpl(ei.getBinding(), jaxwsEndpoint);
    jaxWsSoapBinding.setMTOMEnabled(enableMTOM);
    if (installInterceptors) {
        // jaxwsEndpoint.getBinding().getInInterceptors().add(new TestMultipartMessageInterceptor());
        jaxwsEndpoint.getBinding().getOutInterceptors().add(new TestAttachmentOutInterceptor());
    }
    jaxwsEndpoint.getBinding().getInInterceptors().add(new LoggingInInterceptor());
    jaxwsEndpoint.getBinding().getOutInterceptors().add(new LoggingOutInterceptor());
    Client client = new ClientImpl(bus, jaxwsEndpoint);
    InvocationHandler ih = new JaxWsClientProxy(client, jaxwsEndpoint.getJaxwsBinding());
    Object obj = Proxy.newProxyInstance(serviceEndpointInterface.getClassLoader(), new Class[] { serviceEndpointInterface, BindingProvider.class }, ih);
    updateAddressPort(obj, PORT);
    return serviceEndpointInterface.cast(obj);
}
Also used : Bus(org.apache.cxf.Bus) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) Service(org.apache.cxf.service.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) ClientImpl(org.apache.cxf.endpoint.ClientImpl) InvocationHandler(java.lang.reflect.InvocationHandler) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) JaxWsClientProxy(org.apache.cxf.jaxws.JaxWsClientProxy) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SOAPBindingImpl(org.apache.cxf.jaxws.binding.soap.SOAPBindingImpl) Client(org.apache.cxf.endpoint.Client) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)

Example 7 with ClientImpl

use of org.apache.cxf.endpoint.ClientImpl 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);
    AbstractServiceFactoryBean sf = null;
    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<T>(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)

Example 8 with ClientImpl

use of org.apache.cxf.endpoint.ClientImpl in project cxf by apache.

the class JaxWsClientTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);
    bean.setInvoker(invoker);
    Service service = bean.create();
    String namespace = "http://apache.org/hello_world_soap_http";
    EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(new QName(namespace, "SoapPort"));
    JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(), service, ei);
    ClientImpl client = new ClientImpl(getBus(), endpoint);
    BindingOperationInfo bop = ei.getBinding().getOperation(new QName(namespace, "sayHi"));
    assertNotNull(bop);
    bop = bop.getUnwrappedOperation();
    assertNotNull(bop);
    MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
    assertEquals(0, part.getIndex());
    d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
    Object[] ret = client.invoke(bop, new Object[] { "hi" }, null);
    assertNotNull(ret);
    assertEquals("Wrong number of return objects", 1, ret.length);
    // test fault handling
    bop = ei.getBinding().getOperation(new QName(namespace, "testDocLitFault"));
    bop = bop.getUnwrappedOperation();
    d.setMessageObserver(new MessageReplayObserver("testDocLitFault.xml"));
    try {
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (BadRecordLitFault fault) {
        assertEquals("foo", fault.getFaultInfo().trim());
        assertEquals("Hadrian did it.", fault.getMessage());
    }
    try {
        client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
        client.getEndpoint().getOutInterceptors().add(new FaultThrower());
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (Fault fault) {
        assertEquals(true, fault.getMessage().indexOf("Foo") >= 0);
    }
    client.close();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test)

Example 9 with ClientImpl

use of org.apache.cxf.endpoint.ClientImpl in project cxf by apache.

the class AbstractSTSClient method configureViaEPR.

public void configureViaEPR(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
    if (client != null) {
        return;
    }
    location = EndpointReferenceUtils.getAddress(ref);
    if (location != null) {
        location = location.trim();
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("EPR address: " + location);
    }
    final QName sName = EndpointReferenceUtils.getServiceName(ref, bus);
    if (sName != null) {
        serviceName = sName;
        final QName epName = EndpointReferenceUtils.getPortQName(ref, bus);
        if (epName != null) {
            endpointName = epName;
        }
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("EPR endpoint: " + serviceName + " " + endpointName);
        }
    }
    final String wsdlLoc = EndpointReferenceUtils.getWSDLLocation(ref);
    if (wsdlLoc != null) {
        wsdlLocation = wsdlLoc;
    }
    String mexLoc = findMEXLocation(ref, useEPRWSAAddrAsMEXLocation);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("WS-MEX location: " + mexLoc);
    }
    if (mexLoc != null) {
        try {
            JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
            proxyFac.setBindingId(soapVersion);
            proxyFac.setAddress(mexLoc);
            MetadataExchange exc = proxyFac.create(MetadataExchange.class);
            Metadata metadata = exc.get2004();
            Definition definition = null;
            List<Schema> schemas = new ArrayList<>();
            // Parse the MetadataSections into WSDL definition + associated schemas
            for (MetadataSection s : metadata.getMetadataSection()) {
                if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
                    definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
                } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                    Element schemaElement = (Element) s.getAny();
                    if (schemaElement == null) {
                        String schemaLocation = s.getLocation();
                        LOG.info("XSD schema location: " + schemaLocation);
                        schemaElement = downloadSchema(schemaLocation);
                    }
                    QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
                    ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
                    ((Schema) exElement).setElement(schemaElement);
                    schemas.add((Schema) exElement);
                }
            }
            if (definition != null) {
                // Add any extra schemas to the WSDL definition
                for (Schema schema : schemas) {
                    definition.getTypes().addExtensibilityElement(schema);
                }
                WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
                SourceDataBinding dataBinding = new SourceDataBinding();
                factory.setDataBinding(dataBinding);
                Service service = factory.create();
                service.setDataBinding(dataBinding);
                // Get the endpoint + service names by matching the 'location' to the
                // address in the WSDL. If the 'location' is 'anonymous' then just fall
                // back to the first service + endpoint name in the WSDL, if the endpoint
                // name is not defined in the Metadata
                List<ServiceInfo> services = service.getServiceInfos();
                String anonymousAddress = "http://www.w3.org/2005/08/addressing/anonymous";
                if (!anonymousAddress.equals(location)) {
                    for (ServiceInfo serv : services) {
                        for (EndpointInfo ei : serv.getEndpoints()) {
                            if (ei.getAddress().equals(location)) {
                                endpointName = ei.getName();
                                serviceName = serv.getName();
                                LOG.fine("Matched endpoint to location");
                            }
                        }
                    }
                }
                EndpointInfo ei = service.getEndpointInfo(endpointName);
                if (ei == null && anonymousAddress.equals(location) && !services.isEmpty() && !services.get(0).getEndpoints().isEmpty()) {
                    LOG.fine("Anonymous location so taking first endpoint");
                    serviceName = services.get(0).getName();
                    endpointName = services.get(0).getEndpoints().iterator().next().getName();
                    ei = service.getEndpointInfo(endpointName);
                }
                if (ei == null) {
                    throw new TrustException(LOG, "ADDRESS_NOT_MATCHED", location);
                }
                if (location != null && !anonymousAddress.equals(location)) {
                    ei.setAddress(location);
                }
                Endpoint endpoint = new EndpointImpl(bus, service, ei);
                client = new ClientImpl(bus, endpoint);
            }
        } catch (Exception ex) {
            throw new TrustException("WS_MEX_ERROR", ex, LOG);
        }
    }
}
Also used : Types(javax.wsdl.Types) MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) Schema(javax.wsdl.extensions.schema.Schema) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) ArrayList(java.util.ArrayList) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) Base64DecodingException(org.apache.xml.security.exceptions.Base64DecodingException) EndpointException(org.apache.cxf.endpoint.EndpointException) BusException(org.apache.cxf.BusException) WSDLManager(org.apache.cxf.wsdl.WSDLManager)

Example 10 with ClientImpl

use of org.apache.cxf.endpoint.ClientImpl in project cxf by apache.

the class DOMMappingTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    createService(DocumentService.class, "DocService");
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    ReflectionServiceFactoryBean factory = new ReflectionServiceFactoryBean();
    factory.getServiceConfigurations().add(0, new org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration());
    proxyFac.setServiceFactory(factory);
    proxyFac.setDataBinding(new AegisDatabinding());
    proxyFac.setAddress("local://DocService");
    proxyFac.setBus(getBus());
    Object proxyObj = proxyFac.create(IDocumentService.class);
    docClient = (IDocumentService) proxyObj;
    Client client = ClientProxy.getClient(proxyObj);
    ClientImpl clientImpl = (ClientImpl) client;
    clientImpl.setSynchronousTimeout(1000000000);
}
Also used : ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) ClientImpl(org.apache.cxf.endpoint.ClientImpl) AegisDatabinding(org.apache.cxf.aegis.databinding.AegisDatabinding) Client(org.apache.cxf.endpoint.Client) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Before(org.junit.Before)

Aggregations

ClientImpl (org.apache.cxf.endpoint.ClientImpl)10 Service (org.apache.cxf.service.Service)6 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)5 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)4 Client (org.apache.cxf.endpoint.Client)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 URL (java.net.URL)3 QName (javax.xml.namespace.QName)3 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)3 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)3 WSDLServiceFactory (org.apache.cxf.wsdl11.WSDLServiceFactory)3 File (java.io.File)2 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 Bus (org.apache.cxf.Bus)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 Feature (org.apache.cxf.feature.Feature)2 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)2 JaxWsEndpointImpl (org.apache.cxf.jaxws.support.JaxWsEndpointImpl)2 ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)2