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

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

Introduction

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

Prototype

String METHOD_NAME

To view the source code for org.apache.http.client.methods HttpPut METHOD_NAME.

Click Source Link

Usage

From source file:org.elasticsearch.client.RequestConverters.java

static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
    String endpoint = new EndpointBuilder().addPathPartAsIs("_template")
            .addPathPart(putIndexTemplateRequest.name()).build();
    Request request = new Request(HttpPut.METHOD_NAME, endpoint);
    Params params = new Params(request);
    params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
    if (putIndexTemplateRequest.create()) {
        params.putParam("create", Boolean.TRUE.toString());
    }//from   w ww. j av a  2  s .c  om
    if (Strings.hasText(putIndexTemplateRequest.cause())) {
        params.putParam("cause", putIndexTemplateRequest.cause());
    }
    request.setEntity(createEntity(putIndexTemplateRequest, REQUEST_BODY_CONTENT_TYPE));
    return request;
}

From source file:org.dcm4che3.tool.unvscp.UnvSCP.java

private static void configurePushMethod(UnvSCP main, CommandLine cl) throws ParseException {
    String method = null;/*from   www. j  a  v  a2s .  co m*/
    if (cl.hasOption("push-http-method") && !"".equals(method = cl.getOptionValue("push-http-method"))) {
        if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) {
            UnvWebClient.setUploadingFilesHttpMethod(HttpPost.METHOD_NAME);
        } else if (HttpPut.METHOD_NAME.equalsIgnoreCase(method)) {
            UnvWebClient.setUploadingFilesHttpMethod(HttpPut.METHOD_NAME);
        } else {
            throw new ParseException(
                    "--push-http-method accepts only POST|PUT. Method \"" + method + "\" is not supported.");
        }
    } else {
        UnvWebClient.setUploadingFilesHttpMethod(HttpPut.METHOD_NAME);
    }

    LOG.info("Using http method \"{}\" for uploading files", UnvWebClient.getUploadingFilesHttpMethod());
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java

private String createHttpMethod(final Random rndGen) {
    switch (rndGen.nextInt(10)) {
    case 0://w  w w .j a  v  a  2  s. com
    case 1:
    case 2:
        return HttpPost.METHOD_NAME;
    case 3:
    case 4:
    case 5:
    case 6:
        return HttpGet.METHOD_NAME;
    case 7:
        return HttpPut.METHOD_NAME;
    case 8:
        return HttpDelete.METHOD_NAME;
    default:
        return PATCH_METHOD_NAME;
    }
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

private static void resizeTest(ResizeType resizeType,
        CheckedFunction<ResizeRequest, Request, IOException> function) throws IOException {
    String[] indices = randomIndicesNames(2, 2);
    ResizeRequest resizeRequest = new ResizeRequest(indices[0], indices[1]);
    resizeRequest.setResizeType(resizeType);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(resizeRequest, expectedParams);
    setRandomTimeout(resizeRequest::timeout, resizeRequest.timeout(), expectedParams);

    if (randomBoolean()) {
        CreateIndexRequest createIndexRequest = new CreateIndexRequest(randomAlphaOfLengthBetween(3, 10));
        if (randomBoolean()) {
            createIndexRequest.settings(randomIndexSettings());
        }//from w  w  w.  j a v  a 2  s. c om
        if (randomBoolean()) {
            randomAliases(createIndexRequest);
        }
        resizeRequest.setTargetIndex(createIndexRequest);
    }
    setRandomWaitForActiveShards(resizeRequest::setWaitForActiveShards, expectedParams);

    Request request = function.apply(resizeRequest);
    assertEquals(HttpPut.METHOD_NAME, request.getMethod());
    String expectedEndpoint = "/" + resizeRequest.getSourceIndex() + "/_"
            + resizeType.name().toLowerCase(Locale.ROOT) + "/" + resizeRequest.getTargetIndexRequest().index();
    assertEquals(expectedEndpoint, request.getEndpoint());
    assertEquals(expectedParams, request.getParameters());
    assertToXContentBody(resizeRequest, request.getEntity());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testClusterPutSettings() throws IOException {
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(request, expectedParams);
    setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);

    Request expectedRequest = RequestConverters.clusterPutSettings(request);
    assertEquals("/_cluster/settings", expectedRequest.getEndpoint());
    assertEquals(HttpPut.METHOD_NAME, expectedRequest.getMethod());
    assertEquals(expectedParams, expectedRequest.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testPutPipeline() throws IOException {
    String pipelineId = "some_pipeline_id";
    PutPipelineRequest request = new PutPipelineRequest("some_pipeline_id",
            new BytesArray("{}".getBytes(StandardCharsets.UTF_8)), XContentType.JSON);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(request, expectedParams);
    setRandomTimeout(request::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);

    Request expectedRequest = RequestConverters.putPipeline(request);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add("_ingest/pipeline");
    endpoint.add(pipelineId);/* w ww . j  av  a2s .  c o  m*/
    assertEquals(endpoint.toString(), expectedRequest.getEndpoint());
    assertEquals(HttpPut.METHOD_NAME, expectedRequest.getMethod());
    assertEquals(expectedParams, expectedRequest.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testIndexPutSettings() throws IOException {
    String[] indices = randomBoolean() ? null : randomIndicesNames(0, 2);
    UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indices);
    Map<String, String> expectedParams = new HashMap<>();
    setRandomMasterTimeout(updateSettingsRequest, expectedParams);
    setRandomTimeout(updateSettingsRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
    setRandomIndicesOptions(updateSettingsRequest::indicesOptions, updateSettingsRequest::indicesOptions,
            expectedParams);// w  ww.ja va2s . co m
    if (randomBoolean()) {
        updateSettingsRequest.setPreserveExisting(randomBoolean());
        if (updateSettingsRequest.isPreserveExisting()) {
            expectedParams.put("preserve_existing", "true");
        }
    }

    Request request = RequestConverters.indexPutSettings(updateSettingsRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    if (indices != null && indices.length > 0) {
        endpoint.add(String.join(",", indices));
    }
    endpoint.add("_settings");
    assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
    assertEquals(HttpPut.METHOD_NAME, request.getMethod());
    assertToXContentBody(updateSettingsRequest, request.getEntity());
    assertEquals(expectedParams, request.getParameters());
}

From source file:org.elasticsearch.client.RequestConvertersTests.java

public void testCreateRepository() throws IOException {
    String repository = randomIndicesNames(1, 1)[0];
    String endpoint = "/_snapshot/" + repository;
    Path repositoryLocation = PathUtils.get(".");
    PutRepositoryRequest putRepositoryRequest = new PutRepositoryRequest(repository);
    putRepositoryRequest.type(FsRepository.TYPE);
    putRepositoryRequest.verify(randomBoolean());

    putRepositoryRequest.settings(Settings.builder()
            .put(FsRepository.LOCATION_SETTING.getKey(), repositoryLocation)
            .put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean())
            .put(FsRepository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(100, 1000), ByteSizeUnit.BYTES)
            .build());//from  ww w .  j a v  a2s . c  o m

    Request request = RequestConverters.createRepository(putRepositoryRequest);
    assertThat(endpoint, equalTo(request.getEndpoint()));
    assertThat(HttpPut.METHOD_NAME, equalTo(request.getMethod()));
    assertToXContentBody(putRepositoryRequest, request.getEntity());
}

From source file:net.toxbank.client.resource.InvestigationClient.java

/**
 * Updates an investigation at the given url
 * @param zipFile the new investigation zip file - null indicates that the zip file should remain unchanged
 * @param investigation the investigation object to update
 * @param accessRights the access rights to assign
 * @param ftpFilename name of the file on the ftp server - optional used with ftpData type
 * @return the remote task created//from   w  w w.  j  av a2 s  . c o m
 */
public RemoteTask updateInvestigation(File zipFile, Investigation investigation, List<PolicyRule> accessRights,
        String ftpFilename) throws Exception {
    if (investigation.getResourceURL() == null) {
        throw new IllegalArgumentException("investigation has not been assigned a resource url");
    }
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, utf8);
    if (zipFile != null) {
        entity.addPart(file_param, new FileBody(zipFile, zipFile.getName(), "application/zip", null));
    }
    if (investigation.getDataType() != Investigation.DataType.isaTabData) {
        addMetaData(entity, investigation);
    }
    if (investigation.getDataType() == Investigation.DataType.ftpData) {
        entity.addPart(ftp_file_param, new StringBody(ftpFilename));
    }

    addPolicyRules(entity, accessRights);

    if (investigation.isPublished() != null) {
        entity.addPart(published_param, new StringBody(investigation.isPublished().toString()));
    }
    if (investigation.isSearchable() != null) {
        entity.addPart(searchable_param, new StringBody(investigation.isSearchable().toString()));
    }
    RemoteTask task = new RemoteTask(getHttpClient(), investigation.getResourceURL(), "text/uri-list", entity,
            HttpPut.METHOD_NAME);
    return task;
}

From source file:net.toxbank.client.resource.InvestigationClient.java

/**
 * Sets the published status for an investigation
 * @param investigation the investigation to update - only url is used
 * @param published true iff the investigation should be published
 *//*from  w  ww .  j ava  2  s .  c o  m*/
public RemoteTask publishInvestigation(Investigation investigation, boolean published) throws Exception {
    if (investigation.getResourceURL() == null) {
        throw new IllegalArgumentException("investigation has not been assigned a resource url");
    }
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, null, utf8);
    entity.addPart(published_param, new StringBody(String.valueOf(published)));
    RemoteTask task = new RemoteTask(getHttpClient(), investigation.getResourceURL(), "text/uri-list", entity,
            HttpPut.METHOD_NAME);
    return task;
}