Search in sources :

Example 1 with JsonDeserializer

use of cz.metacentrum.perun.rpc.deserializer.JsonDeserializer in project perun by CESNET.

the class ExtSourcePerun method call.

private Deserializer call(String managerName, String methodName, String query) throws PerunException {
    //Prepare sending message
    HttpResponse response;
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    // just like cookie-policy: ignore cookies
    httpClientBuilder.disableCookieManagement();
    HttpClient httpClient = httpClientBuilder.build();
    String commandUrl = perunUrl + format + "/" + managerName + "/" + methodName;
    if (query != null)
        commandUrl += "?" + query;
    HttpGet get = new HttpGet(commandUrl);
    get.setHeader("Content-Type", "application/json");
    get.setHeader("charset", "utf-8");
    get.setHeader("Connection", "Close");
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
    get.addHeader(BasicScheme.authenticate(credentials, "utf-8", false));
    //post.setParams(params);
    InputStream rpcServerAnswer = null;
    try {
        response = httpClient.execute(get);
        rpcServerAnswer = response.getEntity().getContent();
    } catch (IOException ex) {
        this.processIOException(ex);
    }
    JsonDeserializer des = null;
    try {
        des = new JsonDeserializer(rpcServerAnswer);
    } catch (IOException ex) {
        this.processIOException(ex);
    }
    return des;
}
Also used : InputStream(java.io.InputStream) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) IOException(java.io.IOException) JsonDeserializer(cz.metacentrum.perun.rpc.deserializer.JsonDeserializer) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

JsonDeserializer (cz.metacentrum.perun.rpc.deserializer.JsonDeserializer)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpResponse (org.apache.http.HttpResponse)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 HttpClient (org.apache.http.client.HttpClient)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)1