Search in sources :

Example 6 with WebParam

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

the class CodeGenTest method testHeaderFromAnotherMessage1.

@Test
public void testHeaderFromAnotherMessage1() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/pizza.wsdl"));
    env.put(ToolConstants.CFG_EXTRA_SOAPHEADER, "TRUE");
    env.remove(ToolConstants.CFG_VALIDATE_WSDL);
    processor.setContext(env);
    processor.execute();
    assertNotNull(output);
    Class<?> clz = classLoader.loadClass("com.mypizzaco.pizza.PizzaPortType");
    Method[] meths = clz.getMethods();
    for (Method m : meths) {
        if ("orderPizzaBroken".equals(m.getName())) {
            Annotation[][] annotations = m.getParameterAnnotations();
            assertEquals(2, annotations.length);
            for (int i = 0; i < 2; i++) {
                assertTrue(annotations[i][0] instanceof WebParam);
                WebParam parm = (WebParam) annotations[i][0];
                if ("OrderPizza".equals(parm.name())) {
                    assertEquals("http://mypizzaco.com/pizza/types", parm.targetNamespace());
                    assertEquals("OrderPizza", parm.name());
                    assertTrue(!parm.header());
                } else if ("CallerIDHeader".equals(parm.name())) {
                    assertEquals("http://mypizzaco.com/pizza/types", parm.targetNamespace());
                    assertEquals("callerID", parm.partName());
                    assertEquals("CallerIDHeader", parm.name());
                    assertTrue(parm.header());
                } else {
                    fail("No WebParam found!");
                }
            }
        }
        if ("orderPizza".equals(m.getName())) {
            Annotation[][] annotations = m.getParameterAnnotations();
            assertEquals(2, annotations.length);
            for (int i = 0; i < 2; i++) {
                assertTrue(annotations[i][0] instanceof WebParam);
                WebParam parm = (WebParam) annotations[i][0];
                if ("OrderPizza".equals(parm.name())) {
                    assertEquals("http://mypizzaco.com/pizza/types", parm.targetNamespace());
                    assertEquals("OrderPizza", parm.name());
                    assertTrue(!parm.header());
                } else if ("CallerIDHeader".equals(parm.name())) {
                    assertEquals("http://mypizzaco.com/pizza/types", parm.targetNamespace());
                    assertEquals("callerID", parm.partName());
                    assertEquals("CallerIDHeader", parm.name());
                    assertTrue(parm.header());
                } else {
                    fail("No WebParam found!");
                }
            }
        }
    }
}
Also used : WebParam(javax.jws.WebParam) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 7 with WebParam

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

the class CodeGenTest method testRPCHeader.

@Test
public void testRPCHeader() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/soapheader_rpc.wsdl"));
    // headers must be element, but validation
    env.remove(ToolConstants.CFG_VALIDATE_WSDL);
    // doesn't fully process the entire soap:binding information to
    // to figure out which parts are headers and which are body for rpc/lit
    processor.setContext(env);
    processor.execute();
    Class<?> cls = classLoader.loadClass("org.apache.header_test.rpc.TestRPCHeaderPort");
    Method[] meths = cls.getMethods();
    for (Method m : meths) {
        if ("testHeader1".equals(m.getName())) {
            Annotation[][] annotations = m.getParameterAnnotations();
            assertEquals(2, annotations.length);
            assertEquals(1, annotations[1].length);
            assertTrue(annotations[1][0] instanceof WebParam);
            WebParam parm = (WebParam) annotations[1][0];
            assertEquals("http://apache.org/header_test/rpc/types", parm.targetNamespace());
            assertEquals("inHeader", parm.partName());
            assertEquals("headerMessage", parm.name());
            assertTrue(parm.header());
        }
    }
    for (Method m : meths) {
        if ("testInOutHeader".equals(m.getName())) {
            Annotation[][] annotations = m.getParameterAnnotations();
            assertEquals(2, annotations.length);
            assertEquals(1, annotations[1].length);
            assertTrue(annotations[1][0] instanceof WebParam);
            WebParam parm = (WebParam) annotations[1][0];
            assertEquals("http://apache.org/header_test/rpc/types", parm.targetNamespace());
            assertEquals("inOutHeader", parm.partName());
            assertEquals("headerMessage", parm.name());
            assertTrue(parm.header());
        }
    }
}
Also used : WebParam(javax.jws.WebParam) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 8 with WebParam

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

the class CodeGenTest method testCXF1950.

@Test
public void testCXF1950() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/helloworld-noservice-header.wsdl"));
    processor.setContext(env);
    processor.execute();
    File seif = new File(output, "org/apache/cxf/helloworld/HelloWorldServiceImpl.java");
    assertTrue(seif.exists());
    Class<?> sei = classLoader.loadClass("org.apache.cxf.helloworld.HelloWorldServiceImpl");
    Method[] m = sei.getDeclaredMethods();
    assertEquals(1, m.length);
    assertTrue(m[0].getParameterAnnotations()[1][0] instanceof WebParam);
    WebParam wp = (WebParam) m[0].getParameterAnnotations()[1][0];
    assertTrue(wp.header());
}
Also used : WebParam(javax.jws.WebParam) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) File(java.io.File) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 9 with WebParam

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

the class CodeGenTest method testHeaderFromAnotherMessage4.

@Test
public void testHeaderFromAnotherMessage4() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/pizza_wrapped.wsdl"));
    env.put(ToolConstants.CFG_EXTRA_SOAPHEADER, "TRUE");
    processor.setContext(env);
    processor.execute();
    assertNotNull(output);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.pizza_wrapped.Pizza");
    Method[] meths = clz.getMethods();
    for (Method m : meths) {
        if ("orderPizza".equals(m.getName())) {
            Annotation[][] annotations = m.getParameterAnnotations();
            assertEquals(2, annotations.length);
            for (int i = 0; i < 2; i++) {
                assertTrue(annotations[i][0] instanceof WebParam);
                WebParam parm = (WebParam) annotations[i][0];
                if ("Toppings".equals(parm.name())) {
                    assertEquals("http://cxf.apache.org/pizza_wrapped/types", parm.targetNamespace());
                    assertTrue(!parm.header());
                } else if ("CallerIDHeader".equals(parm.name())) {
                    assertEquals("http://cxf.apache.org/pizza_wrapped/types", parm.targetNamespace());
                    assertTrue(parm.header());
                } else {
                    fail("No WebParam found!");
                }
            }
        }
    }
}
Also used : WebParam(javax.jws.WebParam) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 10 with WebParam

use of javax.jws.WebParam 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)

Aggregations

WebParam (javax.jws.WebParam)28 Test (org.junit.Test)15 Method (java.lang.reflect.Method)14 WebMethod (javax.jws.WebMethod)12 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)12 Annotation (java.lang.annotation.Annotation)7 File (java.io.File)5 WebResult (javax.jws.WebResult)5 ArrayList (java.util.ArrayList)4 QName (javax.xml.namespace.QName)4 SOAPBinding (javax.jws.soap.SOAPBinding)3 ObjectStreamClass (java.io.ObjectStreamClass)2 Type (java.lang.reflect.Type)2 Holder (javax.xml.ws.Holder)2 RequestWrapper (javax.xml.ws.RequestWrapper)2 ResponseWrapper (javax.xml.ws.ResponseWrapper)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 JavaField (org.apache.cxf.tools.common.model.JavaField)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Oneway (javax.jws.Oneway)1