0

I am dynamically consuming a webservice by JAX-WS API. Instantiating service class and invoking by web service by reflection API.

Though the expected and actual argument is same its getting "Argument type mismatch" Exception.

Quick help is appreciated.

Class<?>[] paramTypes = serviceClassMethod.getParameterTypes();
System.out.println("Expected Param Class : "+paramTypes[0].getName());
System.out.println("Actual Param Class : "+reqVals[0].getClass());
System.out.println("Expected number : "+paramTypes.length);
System.out.println("Actual number : "+reqVals.length);
Object wsResponse = serviceClassMethod.invoke(service, reqVals);
System.out.println("Invocation successful...");

Output:

Expected Param Class : com.bla.bla.ws.User
Actual Param Class : class com.bla.bla.ws.User
Expected number : 1
Actual number : 1
4
  • Might be a classloading issue. The JRE treats the same class loaded by different classloaders as different class. How do you create your parameter object? Commented Nov 20, 2014 at 11:20
  • 1
    In addition to my previous comment, you can test this using paramTypes[0].equals(reqVals[0].getClass()). If this is not true, you most likely have the mentioned problem. Commented Nov 20, 2014 at 11:30
  • Thanks, yes that was a classloader issue. Commented Nov 20, 2014 at 13:35
  • Allright, glad it worked. I'll post it as an answer so you can accept it. Commented Nov 20, 2014 at 13:38

1 Answer 1

2

This sounds like a classloading issue. The JRE treats the same class loaded by different classloaders as different class. It depends on how you create your parameter object. You can test this using:

paramTypes[0].equals(reqVals[0].getClass())

If this is not true, you are using two different classes.

A solution would be to ensure your parameter object is created with the correct class using paramTypes[0].newInstance();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.