Commit 0ec1eb69 authored by David Koch's avatar David Koch
Browse files

RestRespone added

parent a9fc5c74
......@@ -8,6 +8,7 @@ import java.net.URLConnection;
import com.google.gson.Gson;
import de.uniko.digicom.capitol.api.RestResponse;
import de.uniko.digicom.carsandco.messages.PaymentNotification;
import de.uniko.digicom.carsandco.messages.RepairContract;
......@@ -19,10 +20,11 @@ public class CarsandcoApiClient {
* @param contract The RepairContract Object filled with all the contract data
*/
public void sendContract(RepairContract contract){
public RestResponse sendContract(RepairContract contract){
Gson gson = new Gson();
String newContract = gson.toJson(contract);
RestResponse response = new RestResponse();
try {
......@@ -40,11 +42,15 @@ public class CarsandcoApiClient {
while (in.readLine() != null) {
}
System.out.println("Cars and Co Contract-REST Service Invoked Successfully..");
in.close();
response.setSuccess(true);
response.setMessage("Cars and Co Contract-REST Service Invoked Successfully..");
return response;
} catch (Exception e) {
System.out.println("Error while calling Cars and Co Contract-REST Service");
System.out.println(e);
response.setSuccess(false);
response.setMessage("Error while calling Cars and Co Contract-REST Service: \n" + e.toString());
return response;
}
}
......@@ -52,11 +58,12 @@ public class CarsandcoApiClient {
* This method sends a notification that an invoice is payed to Cars and Co.
* @param note The PaymentNotification Object to send
*/
public void sendPaymentNotification(PaymentNotification note){
public RestResponse sendPaymentNotification(PaymentNotification note){
Gson gson = new Gson();
String paymentNote = gson.toJson(note);
RestResponse response = new RestResponse();
try {
URL url = new URL("http://camunda-carsandco.iwvi.uni-koblenz.de:8080/carsandco/api/contract/payment");
......@@ -73,12 +80,14 @@ public void sendPaymentNotification(PaymentNotification note){
while (in.readLine() != null) {
}
System.out.println("Cars and Co Payment-Notification-REST Service Invoked Successfully..");
in.close();
response.setSuccess(true);
response.setMessage("Cars and Co Contract-REST Service Invoked Successfully..");
return response;
} catch (Exception e) {
System.out.println("Error while calling Cars and Co Payment-Notification-REST Service");
System.out.println(e);
response.setSuccess(false);
response.setMessage("Error while calling Cars and Co Contract-REST Service: \n" + e.toString());
return response;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment