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;
}
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;
}
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);
}
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!");
}
}
}
}
}
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);
}
Aggregations