0

I'm doing an assignment where I have to use a web service using apache axis (Using eclips Mars) to make a desktop application in Java. It has to use an existing dynamic web project I already created. Web project was to add/remove companies and employee details in a (Oracle) database in a web interface. It worked as required. But when the web service was created, It doesn't allow me to create a web client. It gives this error:

IWAB0399E Error in generating Java from WSDL:
java.io.IOException: ERROR: Missing <soap:fault> element inFault "IOException"
in operation "IOException", in binding getCompanies

Apparently, it wont allow me to return HashMaps from methods I created. (When I changed my whole project without returning Hashmaps, I can create the client) But I need to get HashMaps. Are there any way to get HashMaps from the web service I created ???

I've refereed This question in SO. But I have no idea what's the accepted answer was saying.

EDIT:

OK. Now I know that I can't use HashMaps in web services as they can't be marshal and unmarshal. Then I found This question which I tried. But the problem still stands. (I guess I didn't used the answer mentioned above correctly.) As a beginner in this field, I actually don't get how to wrap (Or serialize) Hashmap and retrieve it back. Can someone show an example ?

Community
  • 1
  • 1
ThisaruG
  • 3,222
  • 7
  • 38
  • 60

1 Answers1

1

You can try to wrap your HashMap in a class and create a custom adapter using it with @XmlJavaTypeAdapter to allow JAXB to make the object serialisation correctly.

public class Response {
  @XmlJavaTypeAdapter(MapAdapter.class)    

  HashMap<Integer, Student> students;

  public HashMap<Integer, Student> getStudents() {
    return students;
  }

  public void setStudents(HashMap<Integer, Student> map) {
    this.students = map;
  }
}

Then just use this class as a return value of your web method.

See more:

Doc API Example

Community
  • 1
  • 1
antoniodvr
  • 1,259
  • 1
  • 14
  • 15
  • When I use this, It gives me this error: `Class cannot be resolved to a type` – ThisaruG Nov 13 '15 at 08:20
  • You have to create that class. It will contains how the hash map will be serialized. – antoniodvr Nov 13 '15 at 08:22
  • Just search for `jaxb custom adapter` in order to understand what you have to do – antoniodvr Nov 13 '15 at 08:33
  • I still not understood this correctly I guess. I got [this answer](http://stackoverflow.com/questions/11329388/jaxb-mapping-for-a-map) And I implemented those classes. But still it gives me the same error. – ThisaruG Nov 13 '15 at 10:25