Search in sources :

Example 1 with ResponseWrapper

use of javax.xml.ws.ResponseWrapper in project camel by apache.

the class ServiceInterfaceStrategy method getOutInfo.

private TypeInfo getOutInfo(Method method) {
    ResponseWrapper respWrap = method.getAnnotation(ResponseWrapper.class);
    if (respWrap != null && respWrap.className() != null) {
        return new TypeInfo(respWrap.className(), new QName(respWrap.targetNamespace(), respWrap.localName()));
    }
    Class<?> returnType = method.getReturnType();
    if (Void.TYPE.equals(returnType)) {
        return new TypeInfo(null, null);
    } else {
        Class<?> type = method.getReturnType();
        WebResult webResult = method.getAnnotation(WebResult.class);
        if (webResult != null) {
            return new TypeInfo(type.getName(), new QName(webResult.targetNamespace(), webResult.name()));
        } else {
            throw new IllegalArgumentException("Result type of method " + method.getName() + " is not annotated with WebParam. This is not yet supported");
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ResponseWrapper(javax.xml.ws.ResponseWrapper) WebResult(javax.jws.WebResult)

Example 2 with ResponseWrapper

use of javax.xml.ws.ResponseWrapper in project cxf by apache.

the class JaxWsServiceConfiguration method getResponseWrapperClassName.

@Override
public String getResponseWrapperClassName(Method selected) {
    Method m = getDeclaredMethod(selected);
    ResponseWrapper rw = m.getAnnotation(ResponseWrapper.class);
    String clsName = "";
    if (rw != null) {
        clsName = rw.className();
    }
    if (clsName.length() > 0) {
        return clsName;
    }
    return null;
}
Also used : ResponseWrapper(javax.xml.ws.ResponseWrapper) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod)

Example 3 with ResponseWrapper

use of javax.xml.ws.ResponseWrapper in project cxf by apache.

the class JaxWsServiceConfiguration method getResponseWrapper.

@Override
public Class<?> getResponseWrapper(Method selected) {
    if (this.responseMethodClassNotFoundCache.contains(selected)) {
        return null;
    }
    Class<?> cachedClass = responseMethodClassCache.get(selected);
    if (cachedClass != null) {
        return cachedClass;
    }
    Method m = getDeclaredMethod(selected);
    ResponseWrapper rw = m.getAnnotation(ResponseWrapper.class);
    final String clsName;
    if (rw == null) {
        clsName = getPackageName(selected) + ".jaxws." + StringUtils.capitalize(selected.getName()) + "Response";
    } else {
        clsName = rw.className();
    }
    if (!clsName.isEmpty()) {
        cachedClass = responseMethodClassCache.get(clsName);
        if (cachedClass != null) {
            responseMethodClassCache.put(selected, cachedClass);
            return cachedClass;
        }
        try {
            Class<?> r = ClassLoaderUtils.loadClass(clsName, implInfo.getEndpointClass());
            responseMethodClassCache.put(clsName, r);
            responseMethodClassCache.put(selected, r);
            if (r.equals(m.getReturnType())) {
                LOG.log(Level.WARNING, "INVALID_RESPONSE_WRAPPER", new Object[] { clsName, m.getReturnType().getName() });
            }
            return r;
        } catch (ClassNotFoundException e) {
        // do nothing, we will mock a schema for wrapper bean later on
        }
    }
    responseMethodClassNotFoundCache.add(selected);
    return null;
}
Also used : ResponseWrapper(javax.xml.ws.ResponseWrapper) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod)

Example 4 with ResponseWrapper

use of javax.xml.ws.ResponseWrapper 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 5 with ResponseWrapper

use of javax.xml.ws.ResponseWrapper in project cxf by apache.

the class CodeGenTest method testHelloWorld.

@Test
public void testHelloWorld() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.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_soap_http");
    assertTrue(helloworldsoaphttp.exists());
    File types = new File(helloworldsoaphttp, "types");
    assertTrue(types.exists());
    File[] files = helloworldsoaphttp.listFiles();
    assertEquals(9, files.length);
    files = types.listFiles();
    assertEquals(17, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_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_soap_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("greetMe", new Class[] { String.class });
    assertEquals("String", method.getReturnType().getSimpleName());
    WebParam webParamAnn = AnnotationUtil.getWebParam(method, "requestType");
    // if is wrapped, tns should be empty
    assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http/types", webParamAnn.targetNamespace());
    // assertEquals("", webParamAnn.targetNamespace());
    method = clz.getMethod("greetMeOneWay", new Class[] { String.class });
    Oneway oneWayAnn = AnnotationUtil.getPrivMethodAnnotation(method, Oneway.class);
    assertNotNull("OneWay Annotation is not generated", oneWayAnn);
    assertEquals("void", method.getReturnType().getSimpleName());
    method = clz.getMethod("greetMeSometime", new Class[] { String.class });
    assertEquals("String", method.getReturnType().getSimpleName());
    method = clz.getMethod("testDocLitFault", new Class[] { java.lang.String.class });
    assertEquals("void", method.getReturnType().getSimpleName());
    assertEquals("Exception class is not generated ", 2, method.getExceptionTypes().length);
    method = clz.getMethod("testDocLitBare", new Class[] { java.lang.String.class });
    webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class);
    assertEquals("out", webResultAnno.partName());
    SOAPBinding soapBindingAnno = AnnotationUtil.getPrivMethodAnnotation(method, SOAPBinding.class);
    assertNotNull(soapBindingAnno);
    assertEquals(SOAPBinding.ParameterStyle.BARE, soapBindingAnno.parameterStyle());
    assertEquals("BareDocumentResponse", method.getReturnType().getSimpleName());
}
Also used : WebService(javax.jws.WebService) Oneway(javax.jws.Oneway) ResponseWrapper(javax.xml.ws.ResponseWrapper) SOAPBinding(javax.jws.soap.SOAPBinding) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) WebMethod(javax.jws.WebMethod) WebParam(javax.jws.WebParam) RequestWrapper(javax.xml.ws.RequestWrapper) ObjectStreamClass(java.io.ObjectStreamClass) WebResult(javax.jws.WebResult) File(java.io.File) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Aggregations

ResponseWrapper (javax.xml.ws.ResponseWrapper)7 Method (java.lang.reflect.Method)5 WebMethod (javax.jws.WebMethod)5 WebResult (javax.jws.WebResult)4 File (java.io.File)2 ObjectStreamClass (java.io.ObjectStreamClass)2 WebParam (javax.jws.WebParam)2 WebService (javax.jws.WebService)2 QName (javax.xml.namespace.QName)2 RequestWrapper (javax.xml.ws.RequestWrapper)2 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)2 Test (org.junit.Test)2 Oneway (javax.jws.Oneway)1 SOAPBinding (javax.jws.soap.SOAPBinding)1