mercredi 11 mars 2015

@WebParam on a parameter of interface method - how to get name?

I try to get the name "best_user" of the annotation @WebParam on a method parameter User user in an interface method. Because it is an interface, the following code does not give me access to the annotation:



String methodName = "doSomething";

Class<?> clazz = Class.forName(packageName + "." + "UserService");

Method serviceMethod = null;

for (Method method: clazz.getMethods())
{
if (method.getName().equals(methodName))
{
serviceMethod = method;
break;
}
}

Class<?>[] parameterTypes = serviceMethod.getParameterTypes();
WebParam webParam = parameterTypes[0].getAnnotation(WebParam.class); //webParam is null
String parameterName = webParam.name();


However the web service framework is able to get this data. How can I do it as well?


Interface:



@WebService(name = "UserService", targetNamespace = "my.targetNamespace")
public interface UserService {
@WebMethod
public String doSomething
(
@WebParam(name = "best_user")
User user
)
}





Aucun commentaire:

Enregistrer un commentaire