...
Code Block | ||
---|---|---|
| ||
private String sendPostRequest(String param, String operation, String appKey, String ssoToken, String URL, ResponseHandler<String> reqHandler) throws APINGException { String jsonRequest = param; ..…. …… resp = httpClient.execute(post, reqHandler); } catch (UnsupportedEncodingException e1) { //Do something } catch(HttpResponseException ex){ ResponseError container = JsonConverter.convertFromJson(ex.getMessage(), new TypeToken<ResponseError>() {}.getType()); APINGException apingException=container.getDetail().getAPINGException(); if(apingException==null){ apingException= new APINGException(); apingException.setErrorCode(container.getFaultcode()); apingException.setErrorDetails(container.getFaultstring()); } throw apingException; } catch (ClientProtocolException e) { //Do something } catch (IOException ioE){ //Do something } return resp; } |
3. Notice that the error handling code from sendPostRequest uses a new class: ResponseError, which we are using to deserialize the error response
Code Block | ||
---|---|---|
| ||
public class ResponseError {
private Detail detail;
private String faultcode;
private String faultstring;
public String getFaultstring() {
return faultstring;
}
public void setFaultstring(String faultstring)
{
this.faultstring =
faultstring;
}
public String getFaultcode() {
return faultcode;
}
public void setFaultcode(String faultcode) {
this.faultcode =
faultcode;
}
public Detail getDetail() {
return detail;
}
public void setDetail(Detail detail) {
this.detail = detail;
}
}
public class Detail {
private APINGException APINGException;
public APINGException getAPINGException() {
return APINGException;
}
public void setAPINGException(APINGException
aPINGException) {
APINGException =
aPINGException;
}
|
...