Search in sources :

Example 16 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class CodeGenTest method testHelloWorldSoap12.

@Test
public void testHelloWorldSoap12() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_soap12.wsdl"));
    processor.setContext(env);
    processor.execute();
    assertNotNull(output);
    File org = new File(output, "org");
    assertTrue(org.exists());
    File apache = new File(org, "apache");
    assertTrue(apache.exists());
    File cxf = new File(apache, "cxf");
    assertTrue(cxf.exists());
    File w2j = new File(cxf, "w2j");
    assertTrue(w2j.exists());
    File helloworldsoaphttp = new File(w2j, "hello_world_soap12_http");
    assertTrue(helloworldsoaphttp.exists());
    File types = new File(helloworldsoaphttp, "types");
    assertTrue(types.exists());
    File[] files = helloworldsoaphttp.listFiles();
    assertEquals(5, files.length);
    files = types.listFiles();
    assertEquals(7, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap12_http.Greeter");
    assertTrue("class " + clz.getName() + " modifier is not public", Modifier.isPublic(clz.getModifiers()));
    assertTrue("class " + clz.getName() + " modifier is interface", Modifier.isInterface(clz.getModifiers()));
    WebService webServiceAnn = AnnotationUtil.getPrivClassAnnotation(clz, WebService.class);
    assertEquals("Greeter", webServiceAnn.name());
    Method method = clz.getMethod("sayHi", new Class[] {});
    WebMethod webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
    if (webMethodAnno.operationName() != null && !"".equals(webMethodAnno.operationName())) {
        assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "sayHi", webMethodAnno.operationName());
    }
    RequestWrapper requestWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, RequestWrapper.class);
    assertEquals("org.apache.cxf.w2j.hello_world_soap12_http.types.SayHi", requestWrapperAnn.className());
    ResponseWrapper resposneWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, ResponseWrapper.class);
    assertEquals("sayHiResponse", resposneWrapperAnn.localName());
    WebResult webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class);
    assertEquals("responseType", webResultAnno.name());
    method = clz.getMethod("pingMe", new Class[] {});
    webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
    if (webMethodAnno.operationName() != null && !"".equals(webMethodAnno.operationName())) {
        assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "pingMe", webMethodAnno.operationName());
    }
    Class<?>[] exceptionCls = method.getExceptionTypes();
    assertEquals(1, exceptionCls.length);
    assertEquals("org.apache.cxf.w2j.hello_world_soap12_http.PingMeFault", exceptionCls[0].getName());
}
Also used : WebMethod(javax.jws.WebMethod) WebService(javax.jws.WebService) RequestWrapper(javax.xml.ws.RequestWrapper) ResponseWrapper(javax.xml.ws.ResponseWrapper) ObjectStreamClass(java.io.ObjectStreamClass) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult) File(java.io.File) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 17 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class CodeGenTest method testAsyncMethodNoService.

@Test
public void testAsyncMethodNoService() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_async_noservice.wsdl"));
    // no binding so all the tests that check bindings fail
    env.remove(ToolConstants.CFG_VALIDATE_WSDL);
    processor.setContext(env);
    processor.execute();
    assertNotNull(output);
    File org = new File(output, "org");
    assertTrue(org.exists());
    File apache = new File(org, "apache");
    assertTrue(apache.exists());
    File cxf = new File(apache, "cxf");
    assertTrue(cxf.exists());
    File w2j = new File(cxf, "w2j");
    assertTrue(w2j.exists());
    File async = new File(w2j, "hello_world_async_soap_http");
    assertTrue(async.exists());
    File[] files = async.listFiles();
    assertEquals(Arrays.asList(files).toString(), 9, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_async_soap_http.GreeterAsync");
    Method method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
    WebMethod webMethodAnno1 = AnnotationUtil.getPrivMethodAnnotation(method1, WebMethod.class);
    assertEquals(method1.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", webMethodAnno1.operationName());
    java.lang.reflect.Method method2 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class });
    WebMethod webMethodAnno2 = AnnotationUtil.getPrivMethodAnnotation(method2, WebMethod.class);
    assertEquals(method2.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", webMethodAnno2.operationName());
    method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
    try {
        method1 = clz.getMethod("testIntAsync", new Class[] { Integer.TYPE, javax.xml.ws.AsyncHandler.class });
        fail("Should not have generated testIntAsync");
    } catch (NoSuchMethodException ex) {
    // ignore
    }
    clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_async_soap_http.GreeterDAsync");
    method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
    clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_async_soap_http.GreeterCAsync");
    try {
        method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
        fail("Should not have generated greetMeSometimeAsync");
    } catch (NoSuchMethodException ex) {
    // ignore
    }
    method1 = clz.getMethod("testIntAsync", new Class[] { Integer.TYPE, javax.xml.ws.AsyncHandler.class });
    clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_async_soap_http.GreeterBAsync");
    try {
        method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
        fail("Should not have generated greetMeSometimeAsync");
    } catch (NoSuchMethodException ex) {
    // ignore
    }
    method1 = clz.getMethod("testIntAsync", new Class[] { Integer.TYPE, javax.xml.ws.AsyncHandler.class });
}
Also used : Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) WebMethod(javax.jws.WebMethod) ObjectStreamClass(java.io.ObjectStreamClass) File(java.io.File) Method(java.lang.reflect.Method) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 18 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class FrontendFactory method isJAXWSAnnotationExists.

private boolean isJAXWSAnnotationExists() {
    for (Method method : wsMethods) {
        if (WrapperUtil.isWrapperClassExists(method)) {
            return true;
        }
        WebMethod m = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
        if (m != null) {
            return true;
        }
        WebResult res = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class);
        if (res != null) {
            return true;
        }
    }
    return false;
}
Also used : WebMethod(javax.jws.WebMethod) WebMethod(javax.jws.WebMethod) Method(java.lang.reflect.Method) WebResult(javax.jws.WebResult)

Example 19 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class DOCBareClientServerTest method testAnnotation.

@Test
public void testAnnotation() throws Exception {
    Class<PutLastTradedPricePortType> claz = PutLastTradedPricePortType.class;
    TradePriceData priceData = new TradePriceData();
    Holder<TradePriceData> holder = new Holder<TradePriceData>(priceData);
    Method method = claz.getMethod("sayHi", holder.getClass());
    assertNotNull("Can not find SayHi method in generated class ", method);
    Annotation ann = method.getAnnotation(WebMethod.class);
    WebMethod webMethod = (WebMethod) ann;
    assertEquals(webMethod.operationName(), "SayHi");
    Annotation[][] paraAnns = method.getParameterAnnotations();
    for (Annotation[] paraType : paraAnns) {
        for (Annotation an : paraType) {
            if (an.annotationType() == WebParam.class) {
                WebParam webParam = (WebParam) an;
                assertNotSame("", webParam.targetNamespace());
            }
        }
    }
}
Also used : WebMethod(javax.jws.WebMethod) WebParam(javax.jws.WebParam) Holder(javax.xml.ws.Holder) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) WebMethod(javax.jws.WebMethod) Method(java.lang.reflect.Method) PutLastTradedPricePortType(org.apache.hello_world_doc_lit_bare.PutLastTradedPricePortType) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 20 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class CustomerService method getCustomer.

@WebMethod
@WebResult(name = "customer")
public Customer getCustomer(@WebParam(name = "getCustomer") GetCustomer getCustomer) throws CustomerNotFoundFault {
    Customer c = customers.get(getCustomer.getId());
    if (c == null) {
        CustomerNotFoundDetails details = new CustomerNotFoundDetails();
        details.setId(getCustomer.getId());
        throw new CustomerNotFoundFault(details);
    }
    return c;
}
Also used : Customer(org.apache.cxf.customer.Customer) CustomerNotFoundFault(org.apache.cxf.customer.CustomerNotFoundFault) CustomerNotFoundDetails(org.apache.cxf.customer.CustomerNotFoundDetails) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult)

Aggregations

WebMethod (javax.jws.WebMethod)48 Method (java.lang.reflect.Method)13 WebResult (javax.jws.WebResult)12 Test (org.junit.Test)7 File (java.io.File)6 IOException (java.io.IOException)6 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)6 ActionExecutionException (com.axway.ats.agent.core.exceptions.ActionExecutionException)5 AgentException (com.axway.ats.agent.core.exceptions.AgentException)5 InternalComponentException (com.axway.ats.agent.core.exceptions.InternalComponentException)5 NoCompatibleMethodFoundException (com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException)5 NoSuchActionException (com.axway.ats.agent.core.exceptions.NoSuchActionException)5 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)5 Path (javax.ws.rs.Path)5 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 QName (javax.xml.namespace.QName)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3