Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JAX-WS: how to create a WebMethod that returns a non-primitive type?

843833Feb 21 2008 — edited Apr 18 2008
I am probably missing something obvious, and I would appreciate it if someone can point me to the right direction.

I have followed the simple Netbeans/JAX-WS calculator tutorial from http://www.netbeans.org/kb/60/websvc/jax-ws.html and it works fine, but now I'd like to return a complex data type, like a HashMap instead of an integer, so I tried this:
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.lang.reflect.*;
import java.util.HashMap;

@WebService()
public class g4WS {

	@WebMethod(operationName = "add")
	public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
		return i+j;
	}

	@WebMethod(operationName = "getHashMap")
	public HashMap<String,String> getHashMap() {
		HashMap<String,String> foobar = new HashMap<String,String>();
		foobar.put("e1", "foo");
		foobar.put("e2", "bar");
		return foobar;
	}
}
The "add" method works fine, but the "getHashMap does not. I've deployed the project with Netbeans 6.0 in Tomcat 6.0 as well as GlassFish V2, with the same result.

When I call the method either with the GlassFish Web Service Tester or with soapUI, I get an empty result set. I guess that the fact that there are no complexType definitions for the HashMap in the generated WSDL has something to do with it as well.

Please excuse my ignorance, I'm pretty new to Web Services, and after almost a day of googling I'm stuck here. I can't {code}{code}find what I'm doing wrong, or that I'm trying something impossible.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2008
Added on Feb 21 2008
11 comments
14,951 views