Search in sources :

Example 1 with WebParam

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

the class SoapJaxbDataFormat method createContentFromObject.

/**
     * Create body content from a non Exception object. If the inputObject is a
     * BeanInvocation the following should be considered: The first parameter
     * will be used for the SOAP body. BeanInvocations with more than one
     * parameter are not supported. So the interface should be in doc lit bare
     * style.
     * 
     * @param inputObject
     *            object to be put into the SOAP body
     * @param soapAction
     *            for name resolution
     * @param headerElements
     *            in/out parameter used to capture header content if present
     *            
     * @return JAXBElement for the body content
     */
protected List<Object> createContentFromObject(final Object inputObject, String soapAction, List<Object> headerElements) {
    List<Object> bodyParts = new ArrayList<Object>();
    List<Object> headerParts = new ArrayList<Object>();
    if (inputObject instanceof BeanInvocation) {
        BeanInvocation bi = (BeanInvocation) inputObject;
        Annotation[][] annotations = bi.getMethod().getParameterAnnotations();
        List<WebParam> webParams = new ArrayList<WebParam>();
        for (Annotation[] singleParameterAnnotations : annotations) {
            for (Annotation annotation : singleParameterAnnotations) {
                if (annotation instanceof WebParam) {
                    webParams.add((WebParam) annotation);
                }
            }
        }
        if (webParams.size() > 0) {
            if (webParams.size() == bi.getArgs().length) {
                int index = -1;
                for (Object o : bi.getArgs()) {
                    if (webParams.get(++index).header()) {
                        headerParts.add(o);
                    } else {
                        bodyParts.add(o);
                    }
                }
            } else {
                throw new RuntimeCamelException("The number of bean invocation parameters does not " + "match the number of parameters annotated with @WebParam for the method [ " + bi.getMethod().getName() + "].");
            }
        } else {
            // try to map all objects for the body
            for (Object o : bi.getArgs()) {
                bodyParts.add(o);
            }
        }
    } else {
        bodyParts.add(inputObject);
    }
    List<Object> bodyElements = new ArrayList<Object>();
    for (Object bodyObj : bodyParts) {
        QName name = elementNameStrategy.findQNameForSoapActionOrType(soapAction, bodyObj.getClass());
        if (name == null) {
            LOG.warn("Could not find QName for class " + bodyObj.getClass().getName());
            continue;
        } else {
            bodyElements.add(getElement(bodyObj, name));
        }
    }
    for (Object headerObj : headerParts) {
        QName name = elementNameStrategy.findQNameForSoapActionOrType(soapAction, headerObj.getClass());
        if (name == null) {
            LOG.warn("Could not find QName for class " + headerObj.getClass().getName());
            continue;
        } else {
            JAXBElement<?> headerElem = getElement(headerObj, name);
            if (null != headerElem) {
                headerElements.add(headerElem);
            }
        }
    }
    return bodyElements;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Annotation(java.lang.annotation.Annotation) WebParam(javax.jws.WebParam) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 2 with WebParam

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

the class ServiceInterfaceStrategy method getInInfo.

private List<TypeInfo> getInInfo(Method method) {
    List<TypeInfo> typeInfos = new ArrayList<TypeInfo>();
    RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class);
    // parameter types are returned in declaration order
    Class<?>[] types = method.getParameterTypes();
    if (types.length == 0) {
        return typeInfos;
    }
    if (requestWrapper != null && requestWrapper.className() != null) {
        typeInfos.add(new TypeInfo(requestWrapper.className(), new QName(requestWrapper.targetNamespace(), requestWrapper.localName())));
        return typeInfos;
    }
    // annotations are returned in declaration order
    Annotation[][] annotations = method.getParameterAnnotations();
    List<WebParam> webParams = new ArrayList<WebParam>();
    for (Annotation[] singleParameterAnnotations : annotations) {
        for (Annotation annotation : singleParameterAnnotations) {
            if (annotation instanceof WebParam) {
                webParams.add((WebParam) annotation);
            }
        }
    }
    if (webParams.size() != types.length) {
        throw new IllegalArgumentException("The number of @WebParam annotations for Method " + method.getName() + " does not match the number of parameters. This is not supported.");
    }
    Iterator<WebParam> webParamIter = webParams.iterator();
    int paramCounter = -1;
    while (webParamIter.hasNext()) {
        WebParam webParam = webParamIter.next();
        typeInfos.add(new TypeInfo(types[++paramCounter].getName(), new QName(webParam.targetNamespace(), webParam.name())));
    }
    return typeInfos;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) WebParam(javax.jws.WebParam) RequestWrapper(javax.xml.ws.RequestWrapper)

Example 3 with WebParam

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

the class JaxWsServiceConfiguration method getParameterName.

private QName getParameterName(OperationInfo op, Method method, int paramNumber, int curSize, String prefix, boolean input) {
    int partIndex = getPartIndex(method, paramNumber, input);
    method = getDeclaredMethod(method);
    WebParam param = getWebParam(method, paramNumber);
    String tns = null;
    String local = null;
    if (param != null) {
        tns = param.targetNamespace();
        local = param.name();
    }
    if (tns == null || tns.length() == 0) {
        QName wrappername = null;
        if (input) {
            wrappername = getRequestWrapperName(op, method);
        } else {
            wrappername = getResponseWrapperName(op, method);
        }
        if (wrappername != null) {
            tns = wrappername.getNamespaceURI();
        }
    }
    if (tns == null || tns.length() == 0) {
        tns = op.getName().getNamespaceURI();
    }
    if (local == null || local.length() == 0) {
        if (Boolean.TRUE.equals(isRPC(method)) || !Boolean.FALSE.equals(isWrapped(method))) {
            local = getDefaultLocalName(op, method, paramNumber, partIndex, prefix);
        } else {
            local = getOperationName(op.getInterface(), method).getLocalPart();
            if (!input) {
                local += "Response";
            }
        }
    }
    return new QName(tns, local);
}
Also used : WebParam(javax.jws.WebParam) QName(javax.xml.namespace.QName)

Example 4 with WebParam

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

the class CodeGenTest method testHeaderFromAnotherMessage3.

@Test
public void testHeaderFromAnotherMessage3() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/pizza.wsdl"));
    env.put(ToolConstants.CFG_EXTRA_SOAPHEADER, "FALSE");
    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(1, annotations.length);
            for (int i = 0; i < 1; 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())) {
                    fail("If the exsh turned off, should not generate this parameter");
                } 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 5 with WebParam

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

the class CodeGenTest method testHolderHeader.

@Test
public void testHolderHeader() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_holder.wsdl"));
    // testing multiple parts in body
    env.remove(ToolConstants.CFG_VALIDATE_WSDL);
    processor.setContext(env);
    processor.execute();
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_holder.Greeter");
    assertEquals(2, clz.getMethods().length);
    Class<?> para = classLoader.loadClass("org.apache.cxf.w2j.hello_world_holder.types.GreetMe");
    Method method = clz.getMethod("sayHi", new Class[] { Holder.class, para });
    assertEquals("GreetMeResponse", method.getReturnType().getSimpleName());
    SOAPBinding soapBindingAnno = AnnotationUtil.getPrivClassAnnotation(clz, SOAPBinding.class);
    if (soapBindingAnno == null) {
        soapBindingAnno = method.getAnnotation(SOAPBinding.class);
    }
    assertNotNull(soapBindingAnno);
    assertEquals("BARE", soapBindingAnno.parameterStyle().name());
    assertEquals("LITERAL", soapBindingAnno.use().name());
    assertEquals("DOCUMENT", soapBindingAnno.style().name());
    WebParam webParamAnno = AnnotationUtil.getWebParam(method, "greetMe");
    assertEquals(true, webParamAnno.header());
    webParamAnno = AnnotationUtil.getWebParam(method, "sayHi");
    assertEquals("INOUT", webParamAnno.mode().name());
    method = clz.getMethod("testInOut", Holder.class, Integer.TYPE);
}
Also used : WebParam(javax.jws.WebParam) Holder(javax.xml.ws.Holder) SOAPBinding(javax.jws.soap.SOAPBinding) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) 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