AnsweredAssumed Answered

How to consume Activiti-rest 5.22 services with Restlet Client Api?

Question asked by jahehehinnou on Oct 16, 2017

Hello, I'm deploy Activiti-rest 5.22 in my servlet container and when I test  with google postman  the result is correct, But in my java code I have null for response

this is my java code.

 

 

import java.io.IOException;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.Client;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.ChallengeResponse;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.slf4j.Logger;

 

public class ActivitiClient {

private Logger logger = org.slf4j.LoggerFactory.getLogger(ActivitiClient.class);

private static final String REST_URI = "http://localhost:8080/actviti-rest/service";

private static String path ="/repository/deployments/";

private static ClientResource getClientResource(String uri,String user, String secret) throws IOException{
Client client = new Client(new Context(), Protocol.HTTP);
ClientResource clientResource = new ClientResource(uri);
clientResource.setChallengeResponse(ChallengeScheme.HTTP_BASIC, user, secret);
clientResource.setNext(client);
return clientResource;
}


public static void main(String args[])throws IOException, JSONException{
String user = "kermit";
String secret = "kermit";
String uri = REST_URI + path;
ClientResource resource = getClientResource(uri, user, secret);
resource.accept(MediaType.APPLICATION_JSON);
resource.setAttribute("Accept", MediaType.APPLICATION_JSON);

System.err.println("Statut  is "+resource.getStatus());

Representation response = resource.getResponseEntity();

 

System.err.println("Response  is "+response );


//JSONObject object = new JSONObject(response.getText());

}

 

}

 

Results :

Statut is OK (200) - The request has succeeded
Response is  null

Outcomes