Example usage for org.apache.http.client.methods HttpPatch toString

List of usage examples for org.apache.http.client.methods HttpPatch toString

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPatch toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackCore.java

public synchronized HttpResponse updateStack(String stackName, String stackUuid, String template)
        throws IOException {

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpResponseFactory factory = new DefaultHttpResponseFactory();
    HttpPatch updateStack = null;
    HttpResponse response = null;/*from   w  ww. j  a v a2  s.  c o  m*/

    String jsonTemplate = JavaStackUtils.convertYamlToJson(template);
    JSONObject modifiedObject = new JSONObject();
    modifiedObject.put("stack_name", stackName);
    modifiedObject.put("template", new JSONObject(jsonTemplate));

    if (this.isAuthenticated) {
        Logger.debug("");
        StringBuilder buildUrl = new StringBuilder();
        buildUrl.append("http://");
        buildUrl.append(this.endpoint);
        buildUrl.append(":");
        buildUrl.append(Constants.HEAT_PORT.toString());
        buildUrl.append(String.format("/%s/%s/stacks/%s/%s", Constants.HEAT_VERSION.toString(), tenant_id,
                stackName, stackUuid));

        // Logger.debug(buildUrl.toString());
        updateStack = new HttpPatch(buildUrl.toString());
        updateStack.setEntity(new StringEntity(modifiedObject.toString(), ContentType.APPLICATION_JSON));
        // Logger.debug(this.token_id);
        updateStack.addHeader(Constants.AUTHTOKEN_HEADER.toString(), this.token_id);

        Logger.debug("Request: " + updateStack.toString());
        Logger.debug("Request body: " + modifiedObject.toString());

        response = httpClient.execute(updateStack);
        int statusCode = response.getStatusLine().getStatusCode();
        String responsePhrase = response.getStatusLine().getReasonPhrase();

        Logger.debug("Response: " + response.toString());
        Logger.debug("Response body:");

        if (statusCode != 202) {
            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String line = null;

            while ((line = in.readLine()) != null)
                Logger.debug(line);
        }

        return (statusCode == 202) ? response
                : factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, statusCode,
                        responsePhrase + ". Create Failed with Status: " + statusCode), null);
    } else {
        throw new IOException("You must Authenticate before issuing this request, please re-authenticate. ");
    }
}