1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public static Retour SOAPGet(String SOAP_ACTION, String METHOD_NAME, ArrayList<PropertyInfo> listPropertyInfo) {
Retour result;
SoapObject request = new SoapObject(Constantes.NAMESPACE, METHOD_NAME);
for (PropertyInfo prop : listPropertyInfo) {
request.addProperty(prop);
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
if (httpTransport == null) {
httpTransport = new HttpTransportSE(Constantes.WSDL_URL);
httpTransport.debug = true;
}
try {
if (connection == null) {
connection = httpTransport.getServiceConnection();
if (envelope.version == SoapSerializationEnvelope.VER12) {
connection.setRequestProperty("Content-Type", "application/soap+xml");
} else {
connection.setRequestProperty("Content-Type", "text/xml");
}
}
httpTransport.call(SOAP_ACTION, envelope);
if (envelope.bodyIn != null) {
try {
if (envelope.bodyIn instanceof SoapObject) { // SoapObject = SUCCESS
Gson gson = new GsonBuilder().create();
result = gson.fromJson(envelope.getResponse().toString(), Retour.class);
} else {
result = new Retour(9, METHOD_NAME + ", envelope.bodyIn n'est pas un SoapObject", "");
}
} catch (SoapFault | JsonSyntaxException e) {
result = new Retour(9, METHOD_NAME + ", SoapFault ou JsonSyntaxException, ", e.getMessage());
Log.e(TAG, METHOD_NAME + ", SoapFault ou JsonSyntaxException, " + e.getMessage());
}
} else {
result = new Retour(9, METHOD_NAME + ", envelope.bodyIn est null", "");
Log.e(TAG, METHOD_NAME + ", envelope.bodyIn est null");
}
} catch (HttpResponseException e) {
result = new Retour(9, METHOD_NAME + " HttpResponseException", e.getMessage());
Log.e(TAG, METHOD_NAME + ", HttpResponseException " + e.getMessage());
} catch (IOException e) {
result = new Retour(9, METHOD_NAME + ", IOException", e.getMessage());
Log.e(TAG, METHOD_NAME + ", IOException " + e.getMessage());
} catch (XmlPullParserException e) {
result = new Retour(9, METHOD_NAME + ", XmlPullParserException", e.getMessage());
Log.e(TAG, METHOD_NAME + ", XmlPullParserException " + e.getMessage());
} catch (Exception e) {
result = new Retour(9, METHOD_NAME + ", Exception", e.getMessage());
Log.e(TAG, METHOD_NAME + ", Exception " + e.getMessage());
}
if (connection != null) {
try {
connection.disconnect();
} catch (IOException ex) {
Log.e(TAG, METHOD_NAME + ", IOException " + ex.getMessage());
}
}
return result;
} |
Partager