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:org.fcrepo.indexer.integration.IndexerGroupIT.java

private void doIndexerGroupUpdateTest(final String uri) throws Exception {
    final HttpPut createRequest = new HttpPut(uri);
    final String objectRdf = "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ."
            + "@prefix indexing:<http://fedora.info/definitions/v4/indexing#>." + "<" + uri
            + ">  rdf:type  <http://fedora.info/definitions/v4/indexing#indexable> ;"
            + "indexing:hasIndexingTransformation \"default\".";

    createRequest.setEntity(new StringEntity(objectRdf));
    createRequest.addHeader("Content-Type", contentTypeN3Alt1);

    final HttpResponse response = client.execute(createRequest);
    assertEquals(201, response.getStatusLine().getStatusCode());
    LOGGER.debug("Created object at: {}", uri);

    final Long start = currentTimeMillis();
    synchronized (testIndexer) {
        while (!testIndexer.receivedUpdate(uri) && (currentTimeMillis() - start < TIMEOUT)) {
            LOGGER.debug("Waiting for next notification from TestIndexer...");
            testIndexer.wait(1000);// ww  w . ja v a2  s.  c  o m
        }
    }
    assertTrue("Test indexer should have received an update message for " + uri + "!",
            testIndexer.receivedUpdate(uri));
    LOGGER.debug("Received update at test indexer for identifier: {}", uri);

}

From source file:org.gradle.internal.resource.transport.http.AlwaysRedirectRedirectStrategy.java

public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context)
        throws ProtocolException {
    URI uri = this.getLocationURI(request, response, context);
    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
        return new HttpHead(uri);
    } else if (method.equalsIgnoreCase(HttpPost.METHOD_NAME)) {
        return this.copyEntity(new HttpPost(uri), request);
    } else if (method.equalsIgnoreCase(HttpPut.METHOD_NAME)) {
        return this.copyEntity(new HttpPut(uri), request);
    } else if (method.equalsIgnoreCase(HttpDelete.METHOD_NAME)) {
        return new HttpDelete(uri);
    } else if (method.equalsIgnoreCase(HttpTrace.METHOD_NAME)) {
        return new HttpTrace(uri);
    } else if (method.equalsIgnoreCase(HttpOptions.METHOD_NAME)) {
        return new HttpOptions(uri);
    } else if (method.equalsIgnoreCase(HttpPatch.METHOD_NAME)) {
        return this.copyEntity(new HttpPatch(uri), request);
    } else {/*  w  w w .  j  ava  2s  .c om*/
        return new HttpGet(uri);
    }
}

From source file:org.metaeffekt.dcc.agent.DeploymentBasedEndpointUriBuilder.java

public HttpUriRequest buildHttpUriRequest(Commands command, Id<DeploymentId> deploymentId, HttpEntity payload) {

    StringBuilder sb = new StringBuilder("/");
    sb.append(PATH_ROOT).append("/");
    sb.append(deploymentId).append("/");
    sb.append(command);//from   w w w  .j a v a 2 s.c  om
    String path = sb.toString();

    URIBuilder uriBuilder = createUriBuilder();
    uriBuilder.setPath(path);
    URI uri;
    try {
        uri = uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    HttpRequestBase request;

    if (HTTP_PUT.equals(determineHttpMethod(command))) {
        request = new HttpPut(uri);
        if (payload != null) {
            ((HttpPut) request).setEntity(payload);
        }
    } else {
        request = new HttpGet(uri);
    }

    if (requestConfig != null) {
        request.setConfig(requestConfig);
    }
    return request;

}

From source file:net.gcolin.httpquery.HttpHandlerImpl.java

@Override
public Request put(String uri, byte[] data) {
    HttpPut put = new HttpPut(uri);
    put.setEntity(new ByteArrayEntity(data));
    return new RequestImpl(put);
}

From source file:org.deviceconnect.android.profile.restful.test.NormalDeviceOrientationProfileTestCase.java

/**
 * ondeviceorientation???./* w  w  w  .j av a  2 s  . c om*/
 * <pre>
 * ?HTTP
 * Method: PUT
 * Path: /deviceorientation/ondeviceorientation?deviceId=xxxx&sessionKey=xxxx
 * </pre>
 * <pre>
 * ??
 * result?0???????
 * ??????
 * </pre>
 */
public void testPutOnDeviceOrientation() {
    StringBuilder builder = new StringBuilder();
    builder.append(DCONNECT_MANAGER_URI);
    builder.append("/" + DeviceOrientationProfileConstants.PROFILE_NAME);
    builder.append("/" + DeviceOrientationProfileConstants.ATTRIBUTE_ON_DEVICE_ORIENTATION);
    builder.append("?");
    builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
    builder.append("&");
    builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
    builder.append("&");
    builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
    try {
        HttpUriRequest request = new HttpPut(builder.toString());
        JSONObject root = sendRequest(request);
        Assert.assertNotNull("root is null.", root);
        assertResultOK(root);

        JSONObject event = waitForEvent();
        JSONObject orientation = event.getJSONObject(DeviceOrientationProfileConstants.PARAM_ORIENTATION);
        Assert.assertNotNull(orientation);
        JSONObject a1 = orientation.getJSONObject(DeviceOrientationProfileConstants.PARAM_ACCELERATION);
        Assert.assertNotNull(a1);
        Assert.assertEquals(0.0, a1.getDouble(DeviceOrientationProfileConstants.PARAM_X));
        Assert.assertEquals(0.0, a1.getDouble(DeviceOrientationProfileConstants.PARAM_Y));
        Assert.assertEquals(0.0, a1.getDouble(DeviceOrientationProfileConstants.PARAM_Z));
        JSONObject a2 = orientation
                .getJSONObject(DeviceOrientationProfileConstants.PARAM_ACCELERATION_INCLUDING_GRAVITY);
        Assert.assertNotNull(a2);
        Assert.assertEquals(0.0, a2.getDouble(DeviceOrientationProfileConstants.PARAM_X));
        Assert.assertEquals(0.0, a2.getDouble(DeviceOrientationProfileConstants.PARAM_Y));
        Assert.assertEquals(0.0, a2.getDouble(DeviceOrientationProfileConstants.PARAM_Z));
        JSONObject r = orientation.getJSONObject(DeviceOrientationProfileConstants.PARAM_ROTATION_RATE);
        Assert.assertNotNull(r);
        Assert.assertEquals(0.0, r.getDouble(DeviceOrientationProfileConstants.PARAM_ALPHA));
        Assert.assertEquals(0.0, r.getDouble(DeviceOrientationProfileConstants.PARAM_BETA));
        Assert.assertEquals(0.0, r.getDouble(DeviceOrientationProfileConstants.PARAM_GAMMA));
        Assert.assertEquals(0.0, orientation.getDouble(DeviceOrientationProfileConstants.PARAM_INTERVAL));
    } catch (JSONException e) {
        fail("Exception in JSONObject." + e.getMessage());
    }
}

From source file:org.megam.api.http.TransportMachinery.java

public static TransportResponse put(TransportTools nuts) throws ClientProtocolException, IOException {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPut httpput = new HttpPut(nuts.urlString());

    if (nuts.headers() != null) {
        for (Map.Entry<String, String> headerEntry : nuts.headers().entrySet()) {
            httpput.addHeader(headerEntry.getKey(), headerEntry.getValue());
        }/*from   w  w  w.  jav  a 2 s .c  o m*/
    }

    if (nuts.pairs() != null && (nuts.contentType() == null)) {
        httpput.setEntity(new UrlEncodedFormEntity(nuts.pairs()));
    }

    if (nuts.contentType() != null) {
        httpput.setEntity(new StringEntity(nuts.contentString(), nuts.contentType()));
    }

    TransportResponse transportResp = null;
    try {
        HttpResponse httpResp = httpclient.execute(httpput);
        transportResp = new TransportResponse(httpResp.getStatusLine(), httpResp.getEntity(),
                httpResp.getLocale());
    } finally {
        httpput.releaseConnection();
    }
    return transportResp;

}

From source file:com.agile_coder.poker.client.android.MessageSender.java

public void submitEstimate(String estimate) throws IOException, IllegalStateException {
    HttpClient client = new DefaultHttpClient();
    String message = host + "/poker/" + user + "/" + estimate;
    HttpPut put = new HttpPut(message);
    HttpResponse resp = client.execute(put);
    if (resp.getStatusLine().getStatusCode() != 204) {
        throw new IllegalStateException();
    }/* w ww . j av  a2s.c  o m*/
}

From source file:de.taimos.camel_cosm.CosmProducer.java

@Override
public void process(Exchange exchange) throws Exception {
    String key = this.endpoint.getApiKey();

    final String keyHeader = exchange.getIn().getHeader("CosmKey", String.class);
    if (keyHeader != null) {
        key = keyHeader;//w  ww  . jav a2  s.c  o m
    }

    if (key == null) {
        throw new RuntimeCamelException("No ApiKey present!");
    }

    final HttpClient httpclient = new DefaultHttpClient();
    final HttpPut put = new HttpPut(this.url);
    put.setHeader("X-PachubeApiKey", key);
    put.setEntity(new StringEntity(exchange.getIn().getBody(String.class)));

    final HttpResponse response = httpclient.execute(put);
    final int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode >= 400) {
        throw new RuntimeCamelException("Error: " + response.getStatusLine().getReasonPhrase());
    }
    CosmProducer.LOG.info(response.toString());
}

From source file:at.ac.tuwien.dsg.cloudlyra.utils.RestfulWSClient.java

public void callPutMethod(String xmlString) {

    try {//from w ww  .j a v  a 2 s  .c  o  m

        //HttpGet method = new HttpGet(url);
        StringEntity inputKeyspace = new StringEntity(xmlString);

        Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Connection .. " + url);

        HttpPut request = new HttpPut(url);
        request.addHeader("content-type", "application/xml; charset=utf-8");
        request.addHeader("Accept", "application/xml, multipart/related");
        request.setEntity(inputKeyspace);

        HttpResponse methodResponse = this.getHttpClient().execute(request);

        int statusCode = methodResponse.getStatusLine().getStatusCode();

        Logger.getLogger(RestfulWSClient.class.getName()).log(Level.INFO, "Status Code: " + statusCode);
        BufferedReader rd = new BufferedReader(new InputStreamReader(methodResponse.getEntity().getContent()));

        StringBuilder result = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }

        // System.out.println("Response String: " + result.toString());
    } catch (Exception ex) {

    }

}

From source file:tech.beshu.ror.utils.integration.ElasticsearchTweetsInitializer.java

private void createMessage(RestClient client, String endpoint, String id, String user, String message) {
    try {//from ww w .j  av  a 2  s .c om
        HttpPut httpPut = new HttpPut(client.from(endpoint + id));
        httpPut.setHeader("Content-Type", "application/json");
        httpPut.setEntity(new StringEntity("{\n" + "\"user\" : \"" + user + "\",\n" + "\"post_date\" : \""
                + LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "\",\n" + "\"message\" : \""
                + message + "\"\n" + "}"));
        EntityUtils.consume(client.execute(httpPut).getEntity());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Creating message failed", e);
    }
}