Search in sources :

Example 1 with ClientImpl

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

the class SimpleBatchSTSClient method createClient.

protected void createClient() throws BusException, EndpointException {
    if (client != null) {
        return;
    }
    bus.getExtension(Configurer.class).configureBean(name, this);
    if (wsdlLocation != null) {
        WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
        SourceDataBinding dataBinding = new SourceDataBinding();
        factory.setDataBinding(dataBinding);
        Service service = factory.create();
        service.setDataBinding(dataBinding);
        EndpointInfo ei = service.getEndpointInfo(endpointName);
        Endpoint endpoint = new EndpointImpl(bus, service, ei);
        client = new ClientImpl(bus, endpoint);
    } else {
        Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
        client = new ClientImpl(bus, endpoint);
    }
    client.getInFaultInterceptors().addAll(inFault);
    client.getInInterceptors().addAll(in);
    client.getOutInterceptors().addAll(out);
    client.getOutFaultInterceptors().addAll(outFault);
    in = null;
    out = null;
    inFault = null;
    outFault = null;
    if (features != null) {
        for (AbstractFeature f : features) {
            f.initialize(client, bus);
        }
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Configurer(org.apache.cxf.configuration.Configurer) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding)

Example 2 with ClientImpl

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

the class ComplexClient method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);
    }
    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }
    System.out.println(wsdlURL);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
    Client client = factory.createClient(wsdlURL.toExternalForm(), SERVICE_NAME);
    ClientImpl clientImpl = (ClientImpl) client;
    Endpoint endpoint = clientImpl.getEndpoint();
    ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0);
    QName bindingName = new QName("http://Company.com/Application", "Company_ESB_Application_Biztalk_AgentDetails_4405_AgentDetails_PrtSoap");
    BindingInfo binding = serviceInfo.getBinding(bindingName);
    // {
    QName opName = new QName("http://Company.com/Application", "GetAgentDetails");
    BindingOperationInfo boi = binding.getOperation(opName);
    BindingMessageInfo inputMessageInfo = boi.getInput();
    List<MessagePartInfo> parts = inputMessageInfo.getMessageParts();
    // only one part.
    MessagePartInfo partInfo = parts.get(0);
    Class<?> partClass = partInfo.getTypeClass();
    // GetAgentDetails
    System.out.println(partClass.getCanonicalName());
    Object inputObject = partClass.newInstance();
    // Unfortunately, the slot inside of the part object is also called 'part'.
    // this is the descriptor for get/set part inside the GetAgentDetails class.
    PropertyDescriptor partPropertyDescriptor = new PropertyDescriptor("part", partClass);
    // This is the type of the class which really contains all the parameter information.
    // AgentWSRequest
    Class<?> partPropType = partPropertyDescriptor.getPropertyType();
    System.out.println(partPropType.getCanonicalName());
    Object inputPartObject = partPropType.newInstance();
    partPropertyDescriptor.getWriteMethod().invoke(inputObject, inputPartObject);
    PropertyDescriptor numberPropertyDescriptor = new PropertyDescriptor("agentNumber", partPropType);
    numberPropertyDescriptor.getWriteMethod().invoke(inputPartObject, new Integer(314159));
    Object[] result = client.invoke(opName, inputObject);
    Class<?> resultClass = result[0].getClass();
    // GetAgentDetailsResponse
    System.out.println(resultClass.getCanonicalName());
    PropertyDescriptor resultDescriptor = new PropertyDescriptor("agentWSResponse", resultClass);
    Object wsResponse = resultDescriptor.getReadMethod().invoke(result[0]);
    Class<?> wsResponseClass = wsResponse.getClass();
    System.out.println(wsResponseClass.getCanonicalName());
    PropertyDescriptor agentNameDescriptor = new PropertyDescriptor("agentName", wsResponseClass);
    String agentName = (String) agentNameDescriptor.getReadMethod().invoke(wsResponse);
    System.out.println("Agent name: " + agentName);
}
Also used : JaxWsDynamicClientFactory(org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) PropertyDescriptor(java.beans.PropertyDescriptor) QName(javax.xml.namespace.QName) ClientImpl(org.apache.cxf.endpoint.ClientImpl) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) Client(org.apache.cxf.endpoint.Client) File(java.io.File)

Example 3 with ClientImpl

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

the class SpringBeansTest method testClientFromFactory.

@Test
public void testClientFromFactory() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    Greeter g = factory.create(Greeter.class);
    ClientImpl c = (ClientImpl) ClientProxy.getClient(g);
    for (Interceptor<? extends Message> i : c.getInInterceptors()) {
        if (i instanceof LoggingInInterceptor) {
            ctx.close();
            return;
        }
    }
    ctx.close();
    fail("Did not configure the client");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Greeter(org.apache.hello_world_soap_http.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) ClientImpl(org.apache.cxf.endpoint.ClientImpl) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 4 with ClientImpl

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

the class DynamicClientFactory method createClient.

public Client createClient(String wsdlUrl, QName service, ClassLoader classLoader, QName port, List<String> bindingFiles) {
    if (classLoader == null) {
        classLoader = Thread.currentThread().getContextClassLoader();
    }
    LOG.log(Level.FINE, "Creating client from WSDL " + wsdlUrl);
    WSDLServiceFactory sf = (service == null) ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, service));
    sf.setAllowElementRefs(allowRefs);
    Service svc = sf.create();
    // all SI's should have the same schemas
    SchemaCollection schemas = svc.getServiceInfos().get(0).getXmlSchemaCollection();
    SchemaCompiler compiler = createSchemaCompiler();
    InnerErrorListener listener = new InnerErrorListener(wsdlUrl);
    Object elForRun = ReflectionInvokationHandler.createProxyWrapper(listener, JAXBUtils.getParamClass(compiler, "setErrorListener"));
    compiler.setErrorListener(elForRun);
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    hackInNewInternalizationLogic(compiler, catalog);
    addSchemas(compiler.getOptions(), compiler, svc.getServiceInfos(), schemas);
    addBindingFiles(bindingFiles, compiler);
    S2JJAXBModel intermediateModel = compiler.bind();
    listener.throwException();
    JCodeModel codeModel = intermediateModel.generateCode(null, elForRun);
    StringBuilder sb = new StringBuilder();
    boolean firstnt = false;
    for (Iterator<JPackage> packages = codeModel.packages(); packages.hasNext(); ) {
        JPackage jpackage = packages.next();
        if (!isValidPackage(jpackage)) {
            continue;
        }
        if (firstnt) {
            sb.append(':');
        } else {
            firstnt = true;
        }
        sb.append(jpackage.name());
    }
    JAXBUtils.logGeneratedClassNames(LOG, codeModel);
    String packageList = sb.toString();
    // our hashcode + timestamp ought to be enough.
    String stem = toString() + "-" + System.currentTimeMillis();
    File src = new File(tmpdir, stem + "-src");
    if (!src.mkdir()) {
        throw new IllegalStateException("Unable to create working directory " + src.getPath());
    }
    try {
        Object writer = JAXBUtils.createFileCodeWriter(src);
        codeModel.build(writer);
    } catch (Exception e) {
        throw new IllegalStateException("Unable to write generated Java files for schemas: " + e.getMessage(), e);
    }
    File classes = new File(tmpdir, stem + "-classes");
    if (!classes.mkdir()) {
        throw new IllegalStateException("Unable to create working directory " + classes.getPath());
    }
    StringBuilder classPath = new StringBuilder();
    try {
        setupClasspath(classPath, classLoader);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    List<File> srcFiles = FileUtils.getFilesRecurse(src, ".+\\.java$");
    if (!srcFiles.isEmpty() && !compileJavaSrc(classPath.toString(), srcFiles, classes.toString())) {
        LOG.log(Level.SEVERE, new Message("COULD_NOT_COMPILE_SRC", LOG, wsdlUrl).toString());
    }
    FileUtils.removeDir(src);
    URL[] urls = null;
    try {
        urls = new URL[] { classes.toURI().toURL() };
    } catch (MalformedURLException mue) {
        throw new IllegalStateException("Internal error; a directory returns a malformed URL: " + mue.getMessage(), mue);
    }
    final ClassLoader cl = ClassLoaderUtils.getURLClassLoader(urls, classLoader);
    JAXBContext context;
    Map<String, Object> contextProperties = jaxbContextProperties;
    if (contextProperties == null) {
        contextProperties = Collections.emptyMap();
    }
    try {
        if (StringUtils.isEmpty(packageList)) {
            context = JAXBContext.newInstance(new Class[0], contextProperties);
        } else {
            context = JAXBContext.newInstance(packageList, cl, contextProperties);
        }
    } catch (JAXBException jbe) {
        throw new IllegalStateException("Unable to create JAXBContext for generated packages: " + jbe.getMessage(), jbe);
    }
    JAXBDataBinding databinding = new JAXBDataBinding();
    databinding.setContext(context);
    svc.setDataBinding(databinding);
    ClientImpl client = new DynamicClientImpl(bus, svc, port, getEndpointImplFactory(), cl);
    ServiceInfo svcfo = client.getEndpoint().getEndpointInfo().getService();
    // Setup the new classloader!
    ClassLoaderUtils.setThreadContextClassloader(cl);
    TypeClassInitializer visitor = new TypeClassInitializer(svcfo, intermediateModel, allowWrapperOps());
    visitor.walk();
    // delete the classes files
    FileUtils.removeDir(classes);
    return client;
}
Also used : MalformedURLException(java.net.MalformedURLException) Message(org.apache.cxf.common.i18n.Message) JAXBContext(javax.xml.bind.JAXBContext) SchemaCompiler(org.apache.cxf.common.jaxb.JAXBUtils.SchemaCompiler) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) URLClassLoader(java.net.URLClassLoader) S2JJAXBModel(org.apache.cxf.common.jaxb.JAXBUtils.S2JJAXBModel) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) JAXBException(javax.xml.bind.JAXBException) JPackage(org.apache.cxf.common.jaxb.JAXBUtils.JPackage) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) JCodeModel(org.apache.cxf.common.jaxb.JAXBUtils.JCodeModel) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlSchemaSerializerException(org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException) DOMException(org.w3c.dom.DOMException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) JDefinedClass(org.apache.cxf.common.jaxb.JAXBUtils.JDefinedClass) SchemaCollection(org.apache.cxf.common.xmlschema.SchemaCollection) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 5 with ClientImpl

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

the class AbstractSTSClient method createClient.

protected void createClient() throws BusException, EndpointException {
    if (client != null) {
        return;
    }
    if (wsdlLocation != null) {
        WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
        SourceDataBinding dataBinding = new SourceDataBinding();
        factory.setDataBinding(dataBinding);
        Service service = factory.create();
        service.setDataBinding(dataBinding);
        EndpointInfo ei = service.getEndpointInfo(endpointName);
        Endpoint endpoint = new EndpointImpl(bus, service, ei);
        client = new ClientImpl(bus, endpoint);
    } else if (location != null) {
        Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
        client = new ClientImpl(bus, endpoint);
    } else {
        throw new TrustException(LOG, "NO_LOCATION");
    }
    client.getInFaultInterceptors().addAll(inFault);
    client.getInInterceptors().addAll(in);
    client.getOutInterceptors().addAll(out);
    client.getOutFaultInterceptors().addAll(outFault);
    if (tlsClientParameters != null) {
        HTTPConduit http = (HTTPConduit) client.getConduit();
        http.setTlsClientParameters(tlsClientParameters);
    }
    in = null;
    out = null;
    inFault = null;
    outFault = null;
    if (features != null) {
        for (Feature f : features) {
            f.initialize(client, bus);
        }
    }
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature)

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