Example usage for org.apache.http.client.methods HttpPut HttpPut

List of usage examples for org.apache.http.client.methods HttpPut HttpPut

Introduction

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

Prototype

public HttpPut(final String uri) 

Source Link

Usage

From source file:com.arrow.acn.client.api.SoftwareReleaseTransApi.java

public StatusModel succeeded(String hid) {
    String method = "succeeded";
    try {/*from   w ww . ja  v  a  2 s.  c  o m*/
        URI uri = buildUri(String.format(SUCCEEDED_URL, hid));
        StatusModel result = execute(new HttpPut(uri), StatusModel.class);
        log(method, result);
        return result;
    } catch (Throwable e) {
        logError(method, e);
        throw new AcnClientException(method, e);
    }
}

From source file:com.handsome.frame.android.volley.stack.HttpClientStack.java

/**
 * Creates the appropriate subclass of HttpUriRequest for passed in request.
 *///from ww w. j av  a2s. co  m
private static HttpUriRequest createHttpRequest(Request<?> request) throws AuthFailureError {
    switch (request.getMethod()) {
    case Request.Method.GET:
        return new HttpGet(request.getUrl());
    case Request.Method.DELETE:
        return new HttpDelete(request.getUrl());
    case Request.Method.POST: {
        HttpPost postRequest = new HttpPost(request.getUrl());
        postRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(postRequest, request);
        return postRequest;
    }
    case Request.Method.PUT: {
        HttpPut putRequest = new HttpPut(request.getUrl());
        putRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(putRequest, request);
        return putRequest;
    }
    case Request.Method.HEAD:
        return new HttpHead(request.getUrl());
    case Request.Method.OPTIONS:
        return new HttpOptions(request.getUrl());
    case Request.Method.TRACE:
        return new HttpTrace(request.getUrl());
    case Request.Method.PATCH: {
        HttpPatch patchRequest = new HttpPatch(request.getUrl());
        patchRequest.addHeader(HTTP.CONTENT_TYPE, request.getBodyContentType());
        setEntityIfNonEmptyBody(patchRequest, request);
        return patchRequest;
    }
    default:
        throw new IllegalStateException("Unknown request method.");
    }
}

From source file:org.opendaylight.alto.manager.AltoManager.java

protected boolean httpPut(String url, String data) throws IOException {
    HttpPut httpPut = new HttpPut(url);
    httpPut.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
    httpPut.setEntity(new StringEntity(data));
    logHttpRequest("HTTP PUT:", url, data);
    HttpResponse response = httpClient.execute(httpPut);
    return handleResponse(response);
}

From source file:de.dentrassi.pm.jenkins.UploaderV2.java

@Override
public void upload(final File file, final String filename) throws IOException {
    final URI uri = makeUrl(filename);
    final HttpPut httppost = new HttpPut(uri);

    final InputStream stream = new FileInputStream(file);
    try {/* ww  w  .  j  av  a2s  .  co  m*/
        httppost.setEntity(new InputStreamEntity(stream, file.length()));

        final HttpResponse response = this.client.execute(httppost);
        final HttpEntity resEntity = response.getEntity();

        if (resEntity != null) {
            switch (response.getStatusLine().getStatusCode()) {
            case 200:
                addUploadedArtifacts(filename, resEntity);
                break;
            default:
                addUploadFailure(filename, response);
                break;
            }
        }
    } finally {
        stream.close();
    }
}

From source file:com.wso2.raspberrypi.apicalls.HttpClient.java

public HttpResponse doPut(String url, String token, final String payload, String contentType)
        throws IOException {
    HttpUriRequest request = new HttpPut(url);
    addSecurityHeaders(request, token);//from   ww w  . j  a  v  a2  s.  co m

    HttpEntityEnclosingRequest entityEncReq = (HttpEntityEnclosingRequest) request;
    EntityTemplate ent = new EntityTemplate(new ContentProducer() {
        public void writeTo(OutputStream outputStream) throws IOException {
            outputStream.write(payload.getBytes());
            outputStream.flush();
        }
    });
    ent.setContentType(contentType);
    entityEncReq.setEntity(ent);
    return client.execute(request);
}

From source file:project.cs.lisa.application.http.NetInfPublish.java

/**
 * Sends the NetInf PUBLISH request to the local node using HTTP.
 * @param   voids   Nothing./*w  w  w .j  a va 2 s .co  m*/
 * @return          JSON response to the NetInf request sent as HTTP
 *                  or null if the request failed.
 */
@Override
protected String doInBackground(Void... voids) {
    Log.d(TAG, "doInBackground()");

    // Don't publish without locators
    if (mLocators == null || mLocators.size() == 0) {
        return null;
    }

    // Add locators
    for (Locator locator : mLocators) {
        addQuery(locator.getQueryKey(), locator.getQueryValue());
    }

    try {
        // TODO break into several methods
        // FullPut or not?
        HttpUriRequest request;
        if (mFile != null) {
            request = new HttpPost(getUri());
        } else {
            request = new HttpPut(getUri());
        }
        // Execute HTTP request
        return execute(request);
    } catch (NullEntityException e) {
        Log.e(TAG, e.getMessage());
        return null;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        return null;
    }
}

From source file:com.jaeksoft.searchlib.test.legacy.CommonTestCase.java

@SuppressWarnings("deprecation")
public int postFile(File file, String contentType, String api) throws IllegalStateException, IOException {
    String url = SERVER_URL + "/" + api + "?use=" + INDEX_NAME + "&login=" + USER_NAME + "&key=" + API_KEY;
    HttpPut put = new HttpPut(url);
    put.setEntity(new FileEntity(file, contentType));
    DefaultHttpClient httpClient = new DefaultHttpClient();
    return httpClient.execute(put).getStatusLine().getStatusCode();
}

From source file:com.sap.core.odata.fit.basic.RequestContentTypeTest.java

@Test
public void unsupportedContentType() throws Exception {
    HttpPut put = new HttpPut(URI.create(getEndpoint().toString() + "Rooms('1')"));
    put.setHeader(HttpHeaders.CONTENT_TYPE, HttpContentType.TEXT_PLAIN);
    final HttpResponse response = getHttpClient().execute(put);
    assertEquals(HttpStatusCodes.UNSUPPORTED_MEDIA_TYPE.getStatusCode(),
            response.getStatusLine().getStatusCode());
}

From source file:com.ibm.watson.movieapp.dialog.rest.UtilityFunctions.java

/**
 * Makes HTTP PUT request//  w w  w .  j  a  va2  s  . c  o m
 * <p>
 * This makes HTTP PUT requests to the url provided.</p>
 * 
 * @param httpClient the http client used to make the request
 * @param url the url for the request
 * @param requestJson the JSON object containing the parameters for the PUT request
 * @return the JSON object response
 * @throws ClientProtocolException if it is unable to execute the call
 * @throws IOException if it is unable to execute the call
 * @throws IllegalStateException if the input stream could not be parsed correctly
 * @throws HttpException if the HTTP call responded with a status code other than 200 or 201
 */
public static JsonObject httpPut(CloseableHttpClient httpClient, String url, JsonObject requestJson)
        throws ClientProtocolException, IOException, IllegalStateException, HttpException {
    HttpPut httpPut = new HttpPut(url);
    httpPut.addHeader("Content-Type", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    httpPut.addHeader("Accept", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    String inp = requestJson.toString();
    StringEntity input = new StringEntity(inp, ContentType.APPLICATION_JSON);
    httpPut.setEntity(input);
    try (CloseableHttpResponse response = httpClient.execute(httpPut)) {
        return UtilityFunctions.parseHTTPResponse(response, url);
    } catch (ClientProtocolException e) {
        throw e;
    }
}

From source file:org.deviceconnect.android.manager.test.MultipartTest.java

/**
 * PUT????????./*from   w ww.  j  a v  a2s .co  m*/
 */
public void testParsingMutilpartAsRequestParametersMethodPut() {
    URIBuilder builder = TestURIBuilder.createURIBuilder();
    builder.setProfile(DeviceOrientationProfileConstants.PROFILE_NAME);
    builder.setAttribute(DeviceOrientationProfileConstants.ATTRIBUTE_ON_DEVICE_ORIENTATION);
    try {
        MultipartEntity entity = new MultipartEntity();
        entity.addPart(DConnectProfileConstants.PARAM_DEVICE_ID, new StringBody(getDeviceId()));
        entity.addPart(DConnectProfileConstants.PARAM_SESSION_KEY, new StringBody(getClientId()));
        entity.addPart(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, new StringBody(getAccessToken()));
        HttpPut request = new HttpPut(builder.toString());
        request.setEntity(entity);
        JSONObject response = sendRequest(request);
        assertResultOK(response);
    } catch (UnsupportedEncodingException e) {
        fail(e.getMessage());
    } catch (JSONException e) {
        fail(e.getMessage());
    }
}