Search in sources :

Example 6 with JavaServiceClass

use of org.apache.cxf.tools.common.model.JavaServiceClass in project cxf by apache.

the class ServiceProcessor method processService.

private void processService(JavaModel model) throws ToolException {
    JavaServiceClass sclz = (JavaServiceClass) service.getProperty("JavaServiceClass");
    if (sclz != null) {
        return;
    }
    for (JavaServiceClass sc : model.getServiceClasses().values()) {
        if (sc.getServiceName().equals(service.getName().getLocalPart())) {
            sclz = sc;
        }
    }
    if (sclz == null) {
        sclz = new JavaServiceClass(model);
        service.setProperty("JavaServiceClass", sclz);
        String name = NameUtil.mangleNameToClassName(service.getName().getLocalPart());
        String namespace = service.getName().getNamespaceURI();
        String packageName = ProcessorUtil.parsePackageName(namespace, context.mapPackageName(namespace));
        // customizing
        JAXWSBinding serviceBinding = null;
        if (service.getDescription() != null) {
            serviceBinding = service.getDescription().getExtensor(JAXWSBinding.class);
        }
        JAXWSBinding serviceBinding2 = service.getExtensor(JAXWSBinding.class);
        // Handle service customized class
        if (serviceBinding != null) {
            if (serviceBinding.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding.getPackage());
            }
            if (serviceBinding.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            jaxwsBinding.setEnableWrapperStyle(serviceBinding.isEnableWrapperStyle());
            if (serviceBinding.getJaxwsClass() != null && serviceBinding.getJaxwsClass().getClassName() != null) {
                name = serviceBinding.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
                sclz.setClassJavaDoc(serviceBinding.getJaxwsClass().getComments());
            }
            sclz.setPackageJavaDoc(serviceBinding.getPackageJavaDoc());
        }
        if (serviceBinding2 != null) {
            if (serviceBinding2.getPackage() != null) {
                jaxwsBinding.setPackage(serviceBinding2.getPackage());
            }
            if (serviceBinding2.isEnableAsyncMapping()) {
                jaxwsBinding.setEnableAsyncMapping(true);
            }
            if (serviceBinding2.isEnableMime()) {
                jaxwsBinding.setEnableMime(true);
            }
            if (serviceBinding2.isEnableWrapperStyle()) {
                jaxwsBinding.setEnableWrapperStyle(true);
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getClassName() != null) {
                name = serviceBinding2.getJaxwsClass().getClassName();
                if (name.contains(".")) {
                    jaxwsBinding.setPackage(name.substring(0, name.lastIndexOf('.')));
                    name = name.substring(name.lastIndexOf('.') + 1);
                }
            }
            if (serviceBinding2.getJaxwsClass() != null && serviceBinding2.getJaxwsClass().getComments() != null) {
                jaxwsBinding.setClassJavaDoc(serviceBinding2.getJaxwsClass().getComments());
            }
            if (!serviceBinding2.getPackageJavaDoc().equals("")) {
                sclz.setPackageJavaDoc(serviceBinding2.getPackageJavaDoc());
            }
        }
        sclz.setServiceName(service.getName().getLocalPart());
        sclz.setNamespace(namespace);
        if (jaxwsBinding.getPackage() != null) {
            packageName = jaxwsBinding.getPackage();
        }
        sclz.setPackageName(packageName);
        name = mapName(packageName, name);
        sclz.setName(name);
        ClassCollector collector = context.get(ClassCollector.class);
        String checkName = name;
        int count = 0;
        while (collector.containServiceClass(packageName, checkName)) {
            checkName = name + (++count);
        }
        name = checkName;
        sclz.setName(name);
        collector.addServiceClassName(packageName, name, packageName + "." + name);
        Element handler = (Element) context.get(ToolConstants.HANDLER_CHAIN);
        sclz.setHandlerChains(handler);
    }
    Collection<EndpointInfo> ports = service.getEndpoints();
    for (EndpointInfo port : ports) {
        JavaPort javaport = processPort(model, service, port);
        sclz.addPort(javaport);
    }
    sclz.setClassJavaDoc(jaxwsBinding.getClassJavaDoc());
    if (StringUtils.isEmpty(sclz.getClassJavaDoc())) {
        sclz.setClassJavaDoc(service.getDocumentation());
    }
    model.addServiceClass(sclz.getName(), sclz);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) ClassCollector(org.apache.cxf.tools.util.ClassCollector) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JAnnotationElement(org.apache.cxf.tools.common.model.JAnnotationElement) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) JavaPort(org.apache.cxf.tools.common.model.JavaPort)

Example 7 with JavaServiceClass

use of org.apache.cxf.tools.common.model.JavaServiceClass in project cxf by apache.

the class JAXWSContainerTest method testSuppressCodeGen.

@Test
public void testSuppressCodeGen() {
    try {
        JAXWSContainer container = new JAXWSContainer(null);
        ToolContext context = new ToolContext();
        // Do not generate any artifacts, we just want the code model.
        context.put(ToolConstants.CFG_SUPPRESS_GEN, "suppress");
        // Where to put the generated source code
        context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
        context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
        // Delegate jaxb to generate the type classes
        context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
        context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
        container.setContext(context);
        // Now shoot
        container.execute();
        // At this point you should be able to get the
        // SEI/Service(Client stub)/Exception classes/Types classes
        assertNotNull(output.list());
        assertEquals(0, output.list().length);
        // Now you can get the JavaModel from the context.
        Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(WSDLToJavaProcessor.MODEL_MAP));
        JavaModel javaModel = map.get(new QName("http://cxf.apache.org/w2j/hello_world_soap_http", "SOAPService"));
        assertNotNull(javaModel);
        Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
        assertEquals(1, interfaces.size());
        JavaInterface intf = interfaces.values().iterator().next();
        String interfaceName = intf.getName();
        assertEquals("Greeter", interfaceName);
        assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http", intf.getNamespace());
        assertEquals("org.apache.cxf.w2j.hello_world_soap_http", intf.getPackageName());
        List<JavaMethod> methods = intf.getMethods();
        assertEquals(6, methods.size());
        Boolean methodSame = false;
        JavaMethod m1 = null;
        for (JavaMethod m2 : methods) {
            if (m2.getName().equals("testDocLitFault")) {
                methodSame = true;
                m1 = m2;
                break;
            }
        }
        assertTrue(methodSame);
        assertNotNull(m1);
        assertEquals(2, m1.getExceptions().size());
        List<String> names = new ArrayList<>();
        for (JavaException exc : m1.getExceptions()) {
            names.add(exc.getName());
        }
        assertTrue("BadRecordLitFault", names.contains("BadRecordLitFault"));
        assertTrue("NoSuchCodeLitFault", names.contains("NoSuchCodeLitFault"));
        String address = null;
        for (JavaServiceClass service : javaModel.getServiceClasses().values()) {
            if ("SOAPService_Test1".equals(service.getName())) {
                continue;
            }
            List<JavaPort> ports = service.getPorts();
            for (JavaPort port : ports) {
                if (interfaceName.equals(port.getPortType())) {
                    address = port.getBindingAdress();
                    break;
                }
            }
            if (!"".equals(address)) {
                break;
            }
        }
        assertEquals("http://localhost:9000/SoapContext/SoapPort", address);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JavaInterface(org.apache.cxf.tools.common.model.JavaInterface) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaServiceClass(org.apache.cxf.tools.common.model.JavaServiceClass) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) JAXWSContainer(org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer) ToolContext(org.apache.cxf.tools.common.ToolContext) URISyntaxException(java.net.URISyntaxException) JavaException(org.apache.cxf.tools.common.model.JavaException) JavaPort(org.apache.cxf.tools.common.model.JavaPort) JavaModel(org.apache.cxf.tools.common.model.JavaModel) JavaMethod(org.apache.cxf.tools.common.model.JavaMethod) Test(org.junit.Test)

Aggregations

JavaPort (org.apache.cxf.tools.common.model.JavaPort)7 JavaServiceClass (org.apache.cxf.tools.common.model.JavaServiceClass)7 QName (javax.xml.namespace.QName)6 JavaModel (org.apache.cxf.tools.common.model.JavaModel)6 JavaInterface (org.apache.cxf.tools.common.model.JavaInterface)5 Message (org.apache.cxf.common.i18n.Message)4 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 HashMap (java.util.HashMap)2 ClassCollector (org.apache.cxf.tools.util.ClassCollector)2 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 BindingProvider (javax.xml.ws.BindingProvider)1 Client (org.apache.cxf.endpoint.Client)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 ToolContext (org.apache.cxf.tools.common.ToolContext)1