troubleshooting Question

How to return error messages from a web service?

Avatar of killdurst
killdurst asked on
Web Languages and StandardsJava
12 Comments3 Solutions3354 ViewsLast Modified:
Hi, I have a web service that returns a "DisciplinaryRecord" object back to the user. See "Request XML" below for the request xml. When the user requests for a valid "gameId", they will get a response. See "Good Response" below. But if the user enters an invalid "gameId", they will get a bad response. See "Bad Response" below. See "GetDisciplinaryRecords Method" below for the method I have written in my java class file.

How do I modify these, so that if there are no records found, the response will return an error message like, "No records found."? Something like the following perhaps?

<return>
      <message>No records found.</message>
</return>


Thanks.
Request XML:
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.dbms.fas.jjcs.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:GetDisciplinaryRecords>
         <gameId>?</gameId>
      </ws:GetDisciplinaryRecords>
   </soapenv:Body>
</soapenv:Envelope>
 
--------------------
 
Good Response:
 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:GetDisciplinaryRecordsResponse xmlns:ns2="http://ws.dbms.fas.jjcs.com/">
         <return>
            <club>ARION WOMEN FC</club>
            <jerseyNo>38</jerseyNo>
            <playerId>64</playerId>
            <playerName>REGINA TAN</playerName>
            <position>1</position>
            <redCards>0</redCards>
            <teamId>11</teamId>
            <yellowCards>1</yellowCards>
         </return>
      </ns2:GetDisciplinaryRecordsResponse>
   </S:Body>
</S:Envelope>
 
--------------------
 
Bad Response:
 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:GetDisciplinaryRecordsResponse xmlns:ns2="http://ws.dbms.fas.jjcs.com/"/>
   </S:Body>
</S:Envelope>
 
--------------------
 
GetDisciplinaryRecords Method:
 
@WebMethod(operationName = "GetDisciplinaryRecords")
public List<DisciplinaryRecord> GetDisciplinaryRecords(@WebParam(name = "gameId") int gameId)
{
	List<DisciplinaryRecord> disciplinaryRecords = null;
	try
	{
	    disciplinaryRecords = new GameDAO().getDisciplinaryRecords(gameId);
	}
	catch(Exception e)
	{
	    e.printStackTrace();
	}
	return disciplinaryRecords;
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros