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

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

Introduction

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

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

From source file:org.sonatype.nexus.testsuite.deploy.nxcm970.ContinuousDeployer.java

public void run() {
    final HttpPut method = new HttpPut(targetUrl);
    method.setEntity(new InputStreamEntity(new EndlessBlockingInputStream(this), -1));

    try {//w w w.  ja  v a 2 s .co m
        result = httpClient.execute(method).getStatusLine().getStatusCode();
    } catch (Exception e) {
        result = -2;
        e.printStackTrace();
    }
}

From source file:org.sonatype.nexus.repositories.metadata.Hc4RawTransport.java

@Override
public void writeRawData(final String path, final byte[] bytes) throws IOException {
    final HttpPut put = new HttpPut(createUrlWithPath(path));
    put.setEntity(new ByteArrayEntity(bytes, ContentType.APPLICATION_XML));
    final HttpResponse response = httpClient.execute(put);
    try {/*w w  w.j av a 2s  .  c  om*/
        if (response.getStatusLine().getStatusCode() > 299) {
            throw new IOException("The response was not successful: " + response.getStatusLine());
        }
    } finally {
        EntityUtils.consume(response.getEntity());
    }
}

From source file:com.urbancode.ud.client.SystemClient.java

public void setSystemConfiguration(Map<String, String> properties) throws JSONException, IOException {
    String uri = url + "/cli/systemConfiguration";

    JSONObject jsonToSend = new JSONObject();
    for (String key : properties.keySet()) {
        jsonToSend.put(key, properties.get(key));
    }//from  w  ww.j a v a2  s. c o m

    HttpPut method = new HttpPut(uri);
    method.setEntity(getStringEntity(jsonToSend));
    invokeMethod(method);
}

From source file:io.logspace.agent.hq.HqClient.java

public void uploadEvents(Collection<Event> events) throws IOException {
    String eventsUrl = this.baseUrl + "/api/events";
    HttpPut httpPut = new HttpPut(eventsUrl);
    httpPut.setEntity(toJsonEntity(events));
    httpPut.addHeader("logspace.space-token", this.spaceToken);

    this.logger.info("Uploading {} event(s) using space-token '{}' to {}", events.size(), this.spaceToken,
            eventsUrl);/*from  w  w w  .ja v  a2 s . c  om*/
    this.httpClient.execute(httpPut, new UploadEventsResponseHandler());
}

From source file:com.messagemedia.restapi.client.v1.internal.RestRequest.java

/**
 * Builds an apache http request//from w w  w  .j av  a  2  s . co m
 *
 * @return the apache http request
 */
HttpUriRequest getHttpRequest() {
    HttpUriRequest request;
    switch (method) {
    case GET:
        request = new HttpGet(url);
        break;
    case DELETE:
        request = new HttpDelete(url);
        break;
    case HEAD:
        request = new HttpHead(url);
        break;
    case POST:
        HttpPost post = new HttpPost(url);
        post.setEntity(new ByteArrayEntity(body));
        request = post;
        break;
    case PUT:
        HttpPut put = new HttpPut(url);
        put.setEntity(new ByteArrayEntity(body));
        request = put;
        break;
    case PATCH:
        HttpPatch patch = new HttpPatch(url);
        patch.setEntity(new ByteArrayEntity(body));
        request = patch;
        break;
    default:
        throw new RuntimeException("Method not supported");
    }

    addHeaders(request);

    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:net.gcolin.httpquery.HttpHandlerImpl.java

@Override
public Request put(String uri, InputStream inStream) {
    HttpPut put = new HttpPut(uri);
    put.setEntity(new InputStreamEntity(inStream, -1));
    return new RequestImpl(put);
}

From source file:com.urbancode.ud.client.PropertyClient.java

public JSONArray updatePropDefs(String propSheetDefPath, JSONArray propDefs, boolean deleteExtraProps)
        throws IOException, JSONException {
    JSONArray result = null;//ww  w .  j  a  va 2 s  .com

    String uri = url + "/property/propSheetDef/" + encodePath(propSheetDefPath) + ".-1/propDefs/update/"
            + String.valueOf(deleteExtraProps);
    HttpPut method = new HttpPut(uri);
    method.setEntity(getStringEntity(propDefs));
    HttpResponse response = invokeMethod(method);
    String body = getBody(response);
    result = new JSONArray(body);

    return result;
}

From source file:org.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet.java

/**
 * Private constructor.//w ww. j a  va2  s . co  m
 *
 * @param id the dataset id.
 * @param name the dataset name.
 * @param dataSetContent the new dataset content.
 */
private CreateOrUpdateDataSet(String id, String name, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + id + "/raw/");
            if (!StringUtils.isEmpty(name)) {
                uriBuilder.addParameter("name", name);
            }
            final HttpPut put = new HttpPut(uriBuilder.build()); // $NON-NLS-1$ //$NON-NLS-2$
            put.setEntity(new InputStreamEntity(dataSetContent));
            return put;
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:org.sonatype.nexus.testsuite.repo.nexus4548.Nexus4548RepoTargetPermissionMatchesPathInRepoIT.java

private HttpResponse put(final String gavPath, final int code) throws Exception {
    HttpPut putMethod = new HttpPut(getNexusTestRepoUrl() + gavPath);
    putMethod.setEntity(new FileEntity(getTestFile("pom-a.pom"), "text/xml"));

    final HttpResponse response = RequestFacade.executeHTTPClientMethod(putMethod);
    assertThat(response.getStatusLine().getStatusCode(), Matchers.is(code));
    return response;
}