Search in sources :

Example 16 with WSDLLocation

use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.

the class WSDLGeneratorImpl method testPartialWSDL2.

/**
 * Tests the binding, service, and port not specified in the WSDL.
 * <p/>
 * This test is based on the FVT test AddNumbersImplPartial2
 */
public void testPartialWSDL2() {
    String wsdlRelativeLocation = "test-resources/wsdl/";
    String wsdlFileName = "PartialWSDL2.wsdl";
    String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
    String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
    // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
    DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
    URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
    Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
    assertNotNull(wsdlDefn);
    WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
    assertNotNull(webServiceAnnot);
    webServiceAnnot.setWsdlLocation(wsdlLocation);
    webServiceAnnot.setTargetNamespace(targetNamespace);
    MethodDescriptionComposite mdc = new MethodDescriptionComposite();
    mdc.setMethodName("addTwoNumbers");
    mdc.setReturnType("int");
    ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    mdc.addParameterDescriptionComposite(pdc1);
    mdc.addParameterDescriptionComposite(pdc2);
    dbc.addMethodDescriptionComposite(mdc);
    dbc.setWebServiceAnnot(webServiceAnnot);
    dbc.setClassName(AddNumbersImplPartial1.class.getName());
    dbc.setWsdlDefinition(wsdlDefn);
    dbc.setwsdlURL(wsdlURL);
    dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
    List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
    assertEquals(1, serviceDescList.size());
    ServiceDescription sd = serviceDescList.get(0);
    assertNotNull(sd);
    EndpointDescription[] edArray = sd.getEndpointDescriptions();
    assertNotNull(edArray);
    assertEquals(1, edArray.length);
    EndpointDescription ed = edArray[0];
    assertNotNull(ed);
    // Test for presence of generated WSDL
    AxisService as = ed.getAxisService();
    assertNotNull(as);
    Parameter compositeParam = as.getParameter(MDQConstants.WSDL_COMPOSITE);
    assertNotNull(compositeParam);
    assertNotNull(compositeParam.getValue());
    EndpointInterfaceDescription eid = ed.getEndpointInterfaceDescription();
    assertNotNull(eid);
    OperationDescription[] odArray = eid.getOperations();
    assertNotNull(odArray);
    assertEquals(1, odArray.length);
    OperationDescription od = odArray[0];
}
Also used : HashMap(java.util.HashMap) AxisService(org.apache.axis2.description.AxisService) Definition(javax.wsdl.Definition) MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) URL(java.net.URL) ParameterDescriptionComposite(org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite) DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) WebServiceAnnot(org.apache.axis2.jaxws.description.builder.WebServiceAnnot) Parameter(org.apache.axis2.description.Parameter)

Example 17 with WSDLLocation

use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.

the class WSDLGeneratorImpl method testPartialWSDL1.

/**
 * Tests the binding, service, and port not specified in the WSDL.
 * <p/>
 * This test is based on the FVT test AddNumbersImplPartial1
 */
public void testPartialWSDL1() {
    String wsdlRelativeLocation = "test-resources/wsdl/";
    String wsdlFileName = "PartialWSDL1.wsdl";
    String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
    String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
    // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
    DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
    URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
    Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
    assertNotNull(wsdlDefn);
    WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
    assertNotNull(webServiceAnnot);
    webServiceAnnot.setWsdlLocation(wsdlLocation);
    webServiceAnnot.setTargetNamespace(targetNamespace);
    MethodDescriptionComposite mdc = new MethodDescriptionComposite();
    mdc.setMethodName("addTwoNumbers");
    mdc.setReturnType("int");
    ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    mdc.addParameterDescriptionComposite(pdc1);
    mdc.addParameterDescriptionComposite(pdc2);
    dbc.addMethodDescriptionComposite(mdc);
    dbc.setWebServiceAnnot(webServiceAnnot);
    dbc.setClassName(AddNumbersImplPartial1.class.getName());
    dbc.setWsdlDefinition(wsdlDefn);
    dbc.setwsdlURL(wsdlURL);
    dbc.setCustomWsdlGenerator(new WSDLGeneratorImpl(wsdlDefn));
    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    dbcMap.put(AddNumbersImplPartial1.class.getName(), dbc);
    List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
    assertEquals(1, serviceDescList.size());
    ServiceDescription sd = serviceDescList.get(0);
    assertNotNull(sd);
    EndpointDescription[] edArray = sd.getEndpointDescriptions();
    assertNotNull(edArray);
    assertEquals(1, edArray.length);
    EndpointDescription ed = edArray[0];
    assertNotNull(ed);
    // Test for presence of generated WSDL
    AxisService as = ed.getAxisService();
    assertNotNull(as);
    Parameter compositeParam = as.getParameter(MDQConstants.WSDL_COMPOSITE);
    assertNotNull(compositeParam);
    assertNotNull(compositeParam.getValue());
    EndpointInterfaceDescription eid = ed.getEndpointInterfaceDescription();
    assertNotNull(eid);
    OperationDescription[] odArray = eid.getOperations();
    assertNotNull(odArray);
    assertEquals(1, odArray.length);
    OperationDescription od = odArray[0];
}
Also used : HashMap(java.util.HashMap) AxisService(org.apache.axis2.description.AxisService) Definition(javax.wsdl.Definition) MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite) EndpointDescription(org.apache.axis2.jaxws.description.EndpointDescription) URL(java.net.URL) ParameterDescriptionComposite(org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite) DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) WebServiceAnnot(org.apache.axis2.jaxws.description.builder.WebServiceAnnot) Parameter(org.apache.axis2.description.Parameter)

Example 18 with WSDLLocation

use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.

the class ValidateWSDLImpl2 method testValidatePortType.

/**
 * The SEI used by the service impl does not contain all the methods defined on the PortType
 */
public void testValidatePortType() {
    String wsdlRelativeLocation = System.getProperty("basedir", ".") + "/" + "test-resources/wsdl/";
    String wsdlFileName = "ValidateWSDL1.wsdl";
    String targetNamespace = "http://serverPartial1.checkexception.webfault.annotations/";
    String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
    // Build up a DBC, including the WSDL Definition and the annotation information for the impl class.
    DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
    URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
    Definition wsdlDefn = DescriptionTestUtils.createWSDLDefinition(wsdlURL);
    assertNotNull(wsdlDefn);
    WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
    assertNotNull(webServiceAnnot);
    webServiceAnnot.setWsdlLocation(wsdlLocation);
    webServiceAnnot.setTargetNamespace(targetNamespace);
    MethodDescriptionComposite mdc = new MethodDescriptionComposite();
    mdc.setMethodName("addTwoNumbers");
    mdc.setReturnType("int");
    ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    ParameterDescriptionComposite pdc2 = new ParameterDescriptionComposite();
    pdc1.setParameterType("int");
    mdc.addParameterDescriptionComposite(pdc1);
    mdc.addParameterDescriptionComposite(pdc2);
    dbc.addMethodDescriptionComposite(mdc);
    dbc.setWebServiceAnnot(webServiceAnnot);
    dbc.setClassName(ValidateWSDLImpl1.class.getName());
    dbc.setWsdlDefinition(wsdlDefn);
    dbc.setwsdlURL(wsdlURL);
    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    dbcMap.put(ValidateWSDLImpl1.class.getName(), dbc);
    try {
        List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
    // Removing the fail() call here as we removed the Valdiation Error from
    // EndpointInterfaceDescriptionValidator.
    // Expected code path
    } catch (WebServiceException e) {
    // Expected code path
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite) URL(java.net.URL) ParameterDescriptionComposite(org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite) DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) WebServiceAnnot(org.apache.axis2.jaxws.description.builder.WebServiceAnnot)

Example 19 with WSDLLocation

use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.

the class AnnotationServiceImplWithDBCTests method testLoadWSDLSEI.

public void testLoadWSDLSEI() {
    String wsdlLocation = getEchoMessageServiceWSDLLocation();
    // Build up a DBC, including the WSDL Definition and the annotation information for
    // the impl class.
    JavaClassToDBCConverter converter = new JavaClassToDBCConverter(EchoMessageServiceSEI.class);
    HashMap<String, DescriptionBuilderComposite> dbcMap = converter.produceDBC();
    assertNotNull(dbcMap);
    DescriptionBuilderComposite dbc = dbcMap.get(EchoMessageServiceSEI.class.getName());
    assertNotNull(dbc);
    DescriptionBuilderComposite seiDBC = dbcMap.get(EchoMessageServiceInterface.class.getName());
    assertNotNull(seiDBC);
    dbc.setClassLoader(this.getClass().getClassLoader());
    WebServiceAnnot webServiceAnnot = seiDBC.getWebServiceAnnot();
    assertNotNull(webServiceAnnot);
    webServiceAnnot.setWsdlLocation(wsdlLocation);
    seiDBC.setWebServiceAnnot(webServiceAnnot);
    dbcMap.put(EchoMessageServiceInterface.class.getName(), seiDBC);
    List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
    assertEquals(1, serviceDescList.size());
    ServiceDescription sd = serviceDescList.get(0);
    assertNotNull(sd);
    // make sure the WSDL definition was read in from the appropriate location
    assertNotNull(((ServiceDescriptionWSDL) sd).getWSDLDefinition());
}
Also used : DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) JavaClassToDBCConverter(org.apache.axis2.jaxws.description.builder.converter.JavaClassToDBCConverter) WebServiceAnnot(org.apache.axis2.jaxws.description.builder.WebServiceAnnot)

Example 20 with WSDLLocation

use of org.apache.axis2.addressing.metadata.WSDLLocation in project axis-axis2-java-core by apache.

the class WSDL11Writer method writeWSDL.

private void writeWSDL(Definition definition, String fileName, Map changedMap, Map baseURIwsdlNameMap) throws Exception {
    // first process the imports and save them.
    Map imports = definition.getImports();
    if (imports != null && (imports.size() > 0)) {
        Vector importsVector = null;
        Import wsdlImport = null;
        String wsdlName = null;
        String wsdlLocation = null;
        for (Iterator improtsVectorIter = imports.values().iterator(); improtsVectorIter.hasNext(); ) {
            importsVector = (Vector) improtsVectorIter.next();
            for (Iterator importsIter = importsVector.iterator(); importsIter.hasNext(); ) {
                wsdlImport = (Import) importsIter.next();
                wsdlLocation = wsdlImport.getDefinition().getDocumentBaseURI();
                // we have to process this wsdl file only if it has not been processed earlier
                if (!baseURIwsdlNameMap.containsKey(wsdlLocation)) {
                    wsdlName = wsdlLocation.substring(wsdlLocation.lastIndexOf('/') + 1);
                    if (!wsdlName.endsWith(".wsdl") && !wsdlName.endsWith(".xsd")) {
                        // this seems to be an online wsdl so we generate a dummy name
                        if (wsdlName.indexOf("xsd") > -1) {
                            wsdlName = "xsd" + count++ + ".xsd";
                        } else {
                            wsdlName = "wsdl" + count++ + ".wsdl";
                        }
                    }
                    // trim the wsdl part
                    while (baseURIwsdlNameMap.containsValue(wsdlName)) {
                        // import file name can either be xsd or wsdl
                        String fileNamePart = wsdlName.substring(0, wsdlName.lastIndexOf("."));
                        String extension = wsdlName.substring(wsdlName.lastIndexOf("."));
                        wsdlName = fileNamePart + count++ + extension;
                    }
                    baseURIwsdlNameMap.put(wsdlLocation, wsdlName);
                    Definition innerDefinition = wsdlImport.getDefinition();
                    writeWSDL(innerDefinition, wsdlName, changedMap, baseURIwsdlNameMap);
                }
                wsdlImport.setLocationURI((String) baseURIwsdlNameMap.get(wsdlLocation));
            }
        }
    }
    // change the locations on the imported schemas
    adjustWSDLSchemaLocations(definition, changedMap);
    // finally save the file
    WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
    File outputFile = FileWriter.createClassFile(baseFolder, null, fileName, null);
    FileOutputStream out = new FileOutputStream(outputFile);
    if (definition.getServices().size() > 1) {
        List removedServices = new ArrayList();
        List servicesList = new ArrayList();
        Map services = definition.getServices();
        // populate the services list
        for (Iterator iter = services.values().iterator(); iter.hasNext(); ) {
            servicesList.add(iter.next());
        }
        Service service;
        String serviceNameFromFileName = fileName;
        if (fileName.indexOf(".wsdl") > -1) {
            serviceNameFromFileName = fileName.substring(0, fileName.lastIndexOf(".wsdl"));
        }
        if (fileName.indexOf(".xsd") > -1) {
            serviceNameFromFileName = fileName.substring(0, fileName.lastIndexOf(".xsd"));
        }
        for (Iterator iter = servicesList.iterator(); iter.hasNext(); ) {
            service = (Service) iter.next();
            if (!service.getQName().getLocalPart().equals(serviceNameFromFileName)) {
                definition.removeService(service.getQName());
                removedServices.add(service);
            }
        }
        // now we have only the required service so write it
        wsdlWriter.writeWSDL(definition, out);
        // again add the removed services
        for (Iterator iter = removedServices.iterator(); iter.hasNext(); ) {
            service = (Service) iter.next();
            definition.addService(service);
        }
    } else {
        // no problem proceed normaly
        wsdlWriter.writeWSDL(definition, out);
    }
    out.flush();
    out.close();
}
Also used : Import(javax.wsdl.Import) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) Definition(javax.wsdl.Definition) ArrayList(java.util.ArrayList) AxisService(org.apache.axis2.description.AxisService) Service(javax.wsdl.Service) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) WSDLWriter(javax.wsdl.xml.WSDLWriter) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) Vector(java.util.Vector) File(java.io.File)

Aggregations

URL (java.net.URL)38 DescriptionBuilderComposite (org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite)27 File (java.io.File)23 Definition (javax.wsdl.Definition)21 Service (javax.xml.ws.Service)18 HashMap (java.util.HashMap)15 QName (javax.xml.namespace.QName)15 AxisService (org.apache.axis2.description.AxisService)14 WebServiceAnnot (org.apache.axis2.jaxws.description.builder.WebServiceAnnot)14 ServiceDescription (org.apache.axis2.jaxws.description.ServiceDescription)13 WSDL4JWrapper (org.apache.axis2.jaxws.util.WSDL4JWrapper)13 MethodDescriptionComposite (org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite)12 ParameterDescriptionComposite (org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite)12 BindingProvider (javax.xml.ws.BindingProvider)10 Test (org.junit.Test)10 WebServiceClientAnnot (org.apache.axis2.jaxws.description.builder.WebServiceClientAnnot)8 WebServiceClient (javax.xml.ws.WebServiceClient)7 DocLitWrappedProxy (org.apache.axis2.jaxws.proxy.doclitwrapped.DocLitWrappedProxy)7 ProxyDocLitWrappedService (org.apache.axis2.jaxws.proxy.doclitwrapped.ProxyDocLitWrappedService)7 WSDLLocation (org.apache.axis2.addressing.metadata.WSDLLocation)6