Java Code Examples for javax.jws.WebMethod#operationName()

The following examples show how to use javax.jws.WebMethod#operationName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public QName getRequestWrapperName(OperationInfo op, Method method) {
    Method m = getDeclaredMethod(method);
    RequestWrapper rw = m.getAnnotation(RequestWrapper.class);
    String nm = null;
    String lp = null;
    if (rw != null) {
        nm = rw.targetNamespace();
        lp = rw.localName();
    }
    WebMethod meth = m.getAnnotation(WebMethod.class);
    if (meth != null && StringUtils.isEmpty(lp)) {
        lp = meth.operationName();
    }
    if (StringUtils.isEmpty(nm)) {
        nm = op.getName().getNamespaceURI();
    }
    if (!StringUtils.isEmpty(nm) && !StringUtils.isEmpty(lp)) {
        return new QName(nm, lp);
    }
    return null;
}
 
Example 2
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public QName getResponseWrapperName(OperationInfo op, Method method) {
    Method m = getDeclaredMethod(method);
    ResponseWrapper rw = m.getAnnotation(ResponseWrapper.class);
    String nm = null;
    String lp = null;
    if (rw != null) {
        nm = rw.targetNamespace();
        lp = rw.localName();
    }
    WebMethod meth = m.getAnnotation(WebMethod.class);
    if (meth != null && StringUtils.isEmpty(lp)) {
        lp = meth.operationName();
        if (!StringUtils.isEmpty(lp)) {
            lp += "Response";
        }
    }
    if (StringUtils.isEmpty(nm)) {
        nm = op.getName().getNamespaceURI();
    }
    if (!StringUtils.isEmpty(nm) && !StringUtils.isEmpty(lp)) {
        return new QName(nm, lp);
    }
    return null;
}
 
Example 3
Source File: CodeGenTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testVoidInOutMethod() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/interoptestdoclit.wsdl"));
    env.remove(ToolConstants.CFG_VALIDATE_WSDL);
    processor.setContext(env);
    processor.execute();

    assertNotNull(output);

    File org = new File(output, "org");
    assertTrue(org.exists());
    File soapinterop = new File(org, "soapinterop");
    assertTrue(soapinterop.exists());
    File wsdlinterop = new File(soapinterop, "wsdlinteroptestdoclit");
    assertTrue(wsdlinterop.exists());
    File xsd = new File(soapinterop, "xsd");
    assertTrue(xsd.exists());
    File[] files = wsdlinterop.listFiles();
    assertEquals(3, files.length);
    files = xsd.listFiles();
    assertEquals(4, files.length);

    Class<?> clz = classLoader
        .loadClass("org.soapinterop.wsdlinteroptestdoclit.WSDLInteropTestDocLitPortType");

    Method method = clz.getMethod("echoVoid", new Class[] {});
    WebMethod webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
    if (webMethodAnno.operationName() != null
        && !"".equals(webMethodAnno.operationName())) {
        assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "echoVoid",
                 webMethodAnno.operationName());
    }
}
 
Example 4
Source File: JaxWsServiceConfiguration.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public QName getOperationName(InterfaceInfo intf, Method method) {
    method = getDeclaredMethod(method);

    WebMethod wm = method.getAnnotation(WebMethod.class);
    if (wm != null) {
        String name = wm.operationName();
        if (name.length() == 0) {
            name = method.getName();
        }

        return new QName(intf.getName().getNamespaceURI(), name);
    }
    return new QName(intf.getName().getNamespaceURI(), method.getName());
}
 
Example 5
Source File: CodeGenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 6
Source File: CodeGenTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@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());

}