Search in sources :

Example 1 with MethodDescriptionComposite

use of org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite in project axis-axis2-java-core by apache.

the class OperationDescriptionImplTests method testDetermineOperationQName.

public void testDetermineOperationQName() {
    String wsdlRelativeLocation = "test-resources/wsdl/";
    String wsdlFileName = "BindingNamespaceDefaults.wsdl";
    String targetNamespace = "http://nonanonymous.complextype.test.org";
    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);
    webServiceAnnot.setServiceName("EchoMessageService");
    webServiceAnnot.setPortName("EchoMessagePort");
    MethodDescriptionComposite mdc = new MethodDescriptionComposite();
    mdc.setMethodName("echoMessage");
    mdc.setReturnType("java.lang.String");
    ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
    pdc1.setParameterType("java.lang.String");
    mdc.addParameterDescriptionComposite(pdc1);
    dbc.addMethodDescriptionComposite(mdc);
    dbc.setWebServiceAnnot(webServiceAnnot);
    dbc.setClassName(BindingNSImpl.class.getName());
    dbc.setWsdlDefinition(wsdlDefn);
    dbc.setwsdlURL(wsdlURL);
    HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
    dbcMap.put(dbc.getClassName(), dbc);
    List<ServiceDescription> serviceDescList = DescriptionFactory.createServiceDescriptionFromDBCMap(dbcMap);
    ServiceDescription sd = serviceDescList.get(0);
    EndpointInterfaceDescription eid = new EndpointInterfaceDescriptionImpl(dbc, new EndpointDescriptionImpl(null, new QName(targetNamespace, "EchoMessagePort"), (ServiceDescriptionImpl) sd));
    assertEquals(new QName(targetNamespace, "echoMessage"), OperationDescriptionImpl.determineOperationQName(eid, mdc));
}
Also used : HashMap(java.util.HashMap) ServiceDescription(org.apache.axis2.jaxws.description.ServiceDescription) QName(javax.xml.namespace.QName) 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) EndpointInterfaceDescription(org.apache.axis2.jaxws.description.EndpointInterfaceDescription)

Example 2 with MethodDescriptionComposite

use of org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite in project axis-axis2-java-core by apache.

the class ServiceDescriptionImplValidationTests method testInvalidDBC1.

// The tests below progressively setup an identical DBC, gradually setting more values until
// the last one does not cause a validation error.
// FAILURE #1: No WebMethod annotation set on the SEI
public void testInvalidDBC1() {
    DescriptionBuilderComposite seiComposite = new DescriptionBuilderComposite();
    seiComposite.setClassName("org.apache.axis2.jaxws.description.impl.MySEI");
    MethodDescriptionComposite seiMDC = new MethodDescriptionComposite();
    seiMDC.setMethodName("seiMethod");
    seiComposite.addMethodDescriptionComposite(seiMDC);
    DescriptionBuilderComposite superImplComposite = new DescriptionBuilderComposite();
    superImplComposite.setClassName("org.apache.axis2.jaxws.description.impl.MySuperImpl");
    MethodDescriptionComposite superImplMDC = new MethodDescriptionComposite();
    superImplMDC.setMethodName("seiMethod");
    superImplComposite.addMethodDescriptionComposite(superImplMDC);
    DescriptionBuilderComposite implComposite = new DescriptionBuilderComposite();
    implComposite.setClassName("org.apache.axis2.jaxws.description.impl.MyImpl");
    MethodDescriptionComposite implMDC = new MethodDescriptionComposite();
    implMDC.setMethodName("notSeiMethod");
    implComposite.addMethodDescriptionComposite(implMDC);
    WebServiceAnnot webServiceAnnot = WebServiceAnnot.createWebServiceAnnotImpl();
    webServiceAnnot.setName(null);
    webServiceAnnot.setEndpointInterface("org.apache.axis2.jaxws.description.impl.MySEI");
    implComposite.setWebServiceAnnot(webServiceAnnot);
    implComposite.setIsInterface(false);
    implComposite.setSuperClassName("org.apache.axis2.jaxws.description.impl.MySuperImpl");
    HashMap<String, DescriptionBuilderComposite> dbcList = new HashMap<String, DescriptionBuilderComposite>();
    dbcList.put(seiComposite.getClassName(), seiComposite);
    dbcList.put(implComposite.getClassName(), implComposite);
    dbcList.put(superImplComposite.getClassName(), superImplComposite);
    try {
        ServiceDescriptionImpl serviceDescImpl = new ServiceDescriptionImpl(dbcList, implComposite);
        fail("Did not catch expected exception");
    } catch (WebServiceException ex) {
    // Expected path
    } catch (Exception ex) {
        fail("Unexpected exception received " + ex.toString());
    }
}
Also used : DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) WebServiceAnnot(org.apache.axis2.jaxws.description.builder.WebServiceAnnot) MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite) WebServiceException(javax.xml.ws.WebServiceException)

Example 3 with MethodDescriptionComposite

use of org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite in project axis-axis2-java-core by apache.

the class ServiceDescriptionImpl method addSuperClassMethods.

/**
 * Adds any methods declared in superclasses to the List.  The hierachy starting with the DBC
 * will be walked up recursively, adding methods from each parent DBC encountered.
 * <p/>
 * Note that this can be used for either classes or interfaces.
 *
 * @param methodList The current collection of methods, including overloaded ones
 * @param dbc The composite to be checked for methods to be added to the collection
 */
private void addSuperClassMethods(List<MethodDescriptionComposite> methodList, DescriptionBuilderComposite dbc) {
    DescriptionBuilderComposite superDBC = dbcMap.get(dbc.getSuperClassName());
    if (superDBC != null) {
        Iterator<MethodDescriptionComposite> mIter = superDBC.getMethodDescriptionsList().iterator();
        while (mIter.hasNext()) {
            MethodDescriptionComposite mdc = mIter.next();
            methodList.add(mdc);
        }
        addSuperClassMethods(methodList, superDBC);
    }
}
Also used : DescriptionBuilderComposite(org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite) MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite)

Example 4 with MethodDescriptionComposite

use of org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite in project axis-axis2-java-core by apache.

the class ServiceDescriptionImpl method validateImplementation.

private void validateImplementation(DescriptionBuilderComposite seic) {
    /*
         *  Verify that an impl class implements all the methods of the SEI. We have to verify this 
         *  because an impl class is not required to actually use the 'implements' clause. So, if 
         *  it doesn't, the Java compiler won't catch it. Don't need to worry about chaining 
         *  because only one EndpointInterface can be specified, and the SEI cannot specify an 
         *  EndpointInterface, so the Java compiler will take care of everything else.
         *  
         *  Note, however, that we do need to take overloaded methods into a consideration.  The
         *  same method name can be specified for multiple methods, but they can have different
         *  parameters.  Note that methods which differ only in the return type or the exceptions
         *  thrown are not overloaded (and therefore would cause a compile error).
         */
    List<MethodDescriptionComposite> implMethods = composite.getMethodDescriptionsList();
    // Add methods declared in the implementation's superclass
    addSuperClassMethods(implMethods, composite);
    List<MethodDescriptionComposite> seiMethods = seic.getMethodDescriptionsList();
    // Add any methods declared in superinterfaces of the SEI
    addSuperClassMethods(seiMethods, seic);
    // Make sure all the methods in the SEI (including any inherited from superinterfaces) are
    // implemented by the bean (including inherited methods on the bean), taking into
    // account overloaded methods.
    Iterator<MethodDescriptionComposite> verifySEIIterator = seiMethods.iterator();
    while (verifySEIIterator.hasNext()) {
        MethodDescriptionComposite seiMDC = verifySEIIterator.next();
        // Make sure the implementation implements this SEI method.  Since we have to account
        // for method overloading, we look for ALL methods with the same name in the
        // implementation, then from that collection of methods, we look for one that has the
        // same parameters.  If we find one with the same parameters, then we check the return
        // and exceptions.  Note that in Java, overloaded methods are ones that have the same
        // name but different parameters; a difference in the return type or thrown exceptions
        // does not constitute overloading and is a compile error.
        Iterator<MethodDescriptionComposite> implMDCIterator = implMethods.iterator();
        boolean methodImplFound = false;
        while (implMDCIterator.hasNext()) {
            MethodDescriptionComposite implMDC = implMDCIterator.next();
            if (seiMDC.getMethodName().equals(implMDC.getMethodName())) {
                // The method names match, so now check the parameters
                try {
                    validateMethodParameters(seiMDC, implMDC, seic.getClassName());
                    methodImplFound = true;
                } catch (Exception ex) {
                // The parameters didn't match, so we'll check the next
                // implemntation method on the next iteration of the inner loop.
                }
                // found the implementation for this sei method.
                if (methodImplFound) {
                    validateMethodExceptions(seiMDC, implMDC, seic.getClassName());
                    validateMethodReturnValue(seiMDC, implMDC, seic.getClassName());
                    break;
                }
            }
        }
        if (!methodImplFound) {
            // exception.
            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("validateImplErr", composite.getClassName(), seiMDC.getMethodName(), seic.getClassName()));
        }
    }
}
Also used : MethodDescriptionComposite(org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite) FileNotFoundException(java.io.FileNotFoundException) ConnectException(java.net.ConnectException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) WSDLException(javax.wsdl.WSDLException) WebServiceException(javax.xml.ws.WebServiceException)

Example 5 with MethodDescriptionComposite

use of org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite 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)

Aggregations

MethodDescriptionComposite (org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite)41 DescriptionBuilderComposite (org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite)25 ParameterDescriptionComposite (org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite)19 WebServiceAnnot (org.apache.axis2.jaxws.description.builder.WebServiceAnnot)17 HashMap (java.util.HashMap)16 Definition (javax.wsdl.Definition)13 URL (java.net.URL)12 ArrayList (java.util.ArrayList)10 WebServiceException (javax.xml.ws.WebServiceException)7 AxisService (org.apache.axis2.description.AxisService)6 WebMethodAnnot (org.apache.axis2.jaxws.description.builder.WebMethodAnnot)4 Parameter (org.apache.axis2.description.Parameter)3 Method (java.lang.reflect.Method)2 WebMethod (javax.jws.WebMethod)2 QName (javax.xml.namespace.QName)2 AxisFault (org.apache.axis2.AxisFault)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2 EndpointDescription (org.apache.axis2.jaxws.description.EndpointDescription)2 ServiceDescription (org.apache.axis2.jaxws.description.ServiceDescription)2 WebParamAnnot (org.apache.axis2.jaxws.description.builder.WebParamAnnot)2