當前位置: 首頁>>代碼示例>>Java>>正文


Java ContentType.APPLICATION_JSON屬性代碼示例

本文整理匯總了Java中org.apache.http.entity.ContentType.APPLICATION_JSON屬性的典型用法代碼示例。如果您正苦於以下問題:Java ContentType.APPLICATION_JSON屬性的具體用法?Java ContentType.APPLICATION_JSON怎麽用?Java ContentType.APPLICATION_JSON使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.http.entity.ContentType的用法示例。


在下文中一共展示了ContentType.APPLICATION_JSON屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateConfig

/**
 * Updates a modules config for the given app
 *
 * @param customerName
 *        the name of the customer
 * @param appName
 *        the name of the app
 * @param moduleName
 *        the name of the module to update config for
 * @param key
 *        config key
 * @param value
 *        value of the config
 * @return request object to check status codes and return values
 */
public Response updateConfig( String customerName, String appName, String moduleName, String key,
	String value )
{
	final HttpPut request = new HttpPut( this.yambasBase + "customers/" + customerName + "/apps/" + appName );
	setAuthorizationHeader( request );
	request.addHeader( "ContentType", "application/json" );
	request.addHeader( "x-apiomat-system", this.system.toString( ) );
	try
	{
		final HttpEntity requestEntity = new StringEntity(
			"{\"configuration\":" + "	{\"" + this.system.toString( ).toLowerCase( ) + "Config\": {\"" +
				moduleName + "\":{\"" + key + "\":\"" + value + "\"}}}, \"applicationName\":\"" + appName + "\"}",
			ContentType.APPLICATION_JSON );
		request.setEntity( requestEntity );

		final HttpResponse response = this.client.execute( request );
		return new Response( response );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:39,代碼來源:AomHttpClient.java

示例2: createObject

/**
 * Creates an object of the given dataModelName and moduleName
 * the appname which is set in this object will be used
 *
 * @param moduleName
 *        the modulenname
 * @param dataModelName
 *        the name of the datamodels
 * @param otherFieldsObject
 *        the other fields to set as JSONObject (the @type field will be added automatically)
 * @return request object to check status codes and return values
 */
public Response createObject( String moduleName, String dataModelName, JSONObject otherFieldsObject )
{
	final HttpPost request = new HttpPost(
		this.yambasBase + "apps/" + this.appName + "/models/" + moduleName + "/" + dataModelName );
	setAuthorizationHeader( request );
	request.addHeader( "ContentType", "application/json" );
	request.addHeader( "x-apiomat-apikey", this.apiKey );
	request.addHeader( "x-apiomat-system", this.system.toString( ) );
	request.addHeader( "x-apiomat-sdkVersion", this.sdkVersion );
	try
	{
		otherFieldsObject.put( "@type", moduleName + '$' + dataModelName );
		final HttpEntity requestEntity =
			new StringEntity( otherFieldsObject.toString( ), ContentType.APPLICATION_JSON );
		request.setEntity( requestEntity );
		final HttpResponse response = this.client.execute( request );
		return new Response( response );
	}
	catch ( final IOException e )
	{
		e.printStackTrace( );
	}
	return null;
}
 
開發者ID:ApinautenGmbH,項目名稱:integration-test-helper,代碼行數:36,代碼來源:AomHttpClient.java

示例3: bulkIndex

@Override
public boolean bulkIndex(List<String> bulkData) {
    StringBuilder bulkRequestBody = new StringBuilder();
    for (String bulkItem : bulkData) {
        bulkRequestBody.append(actionMetaData);
        bulkRequestBody.append(bulkItem);
        bulkRequestBody.append("\n");
    }
    HttpEntity entity = new NStringEntity(bulkRequestBody.toString(), ContentType.APPLICATION_JSON);
    try {
        Response response = client.performRequest("POST", "/geonames/type/_noop_bulk", Collections.emptyMap(), entity);
        return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
    } catch (Exception e) {
        throw new ElasticsearchException(e);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:RestClientBenchmark.java

示例4: bufferLimitTest

private static void bufferLimitTest(HeapBufferedAsyncResponseConsumer consumer, int bufferLimit) throws Exception {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    consumer.onResponseReceived(new BasicHttpResponse(statusLine));

    final AtomicReference<Long> contentLength = new AtomicReference<>();
    HttpEntity entity = new StringEntity("", ContentType.APPLICATION_JSON) {
        @Override
        public long getContentLength() {
            return contentLength.get();
        }
    };
    contentLength.set(randomLong(bufferLimit));
    consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);

    contentLength.set(randomLongBetween(bufferLimit + 1, MAX_TEST_BUFFER_SIZE));
    try {
        consumer.onEntityEnclosed(entity, ContentType.APPLICATION_JSON);
    } catch(ContentTooLongException e) {
        assertEquals("entity content is too long [" + entity.getContentLength() +
                "] for the configured buffer limit [" + bufferLimit + "]", e.getMessage());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:HeapBufferedAsyncResponseConsumerTests.java

示例5: testPositiveCreateQueue

@Test
public void testPositiveCreateQueue() throws IOException {
    String queueName = "testPositiveCreateQueue";
    QueueCreateRequest request = new QueueCreateRequest()
            .name(queueName).durable(false).autoDelete(false);

    HttpPost httpPost = new HttpPost(apiBasePath + "/queues");

    String value = objectMapper.writeValueAsString(request);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED);
    Assert.assertEquals(response.getFirstHeader(HttpHeaders.LOCATION).getValue(),
                        apiBasePath + "/queues/" + queueName,
                        "Incorrect location header");

    String body = responseHandler.handleResponse(response);
    QueueCreateResponse queueCreateResponse = objectMapper.readValue(body, QueueCreateResponse.class);

    Assert.assertFalse(queueCreateResponse.getMessage().isEmpty(), "Response body shouldn't be empty");

}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:25,代碼來源:QueuesRestApiTest.java

示例6: testDeleteQueue

@Test
public void testDeleteQueue() throws IOException {
    String queueName = "testDeleteQueue";

    // Create a queue to delete.
    QueueCreateRequest request = new QueueCreateRequest()
            .name(queueName).durable(false).autoDelete(false);

    HttpPost httpPost = new HttpPost(apiBasePath + "/queues");

    String value = objectMapper.writeValueAsString(request);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED);

    // Delete the queue.
    HttpDelete httpDelete = new HttpDelete(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/" + queueName);
    response = client.execute(httpDelete);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:23,代碼來源:QueuesRestApiTest.java

示例7: createPost

/**
 * Create Post Request with json body
 */
public HttpPost createPost(String uri, String data) {
    HttpPost httpPost = new HttpPost(uri);
    httpPost.setHeader("Content-Type", "application/json");
    HttpEntity entity = new StringEntity(data, ContentType.APPLICATION_JSON);
    httpPost.setEntity(entity);
    return httpPost;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:10,代碼來源:HttpUtils.java

示例8: scrollEntity

static HttpEntity scrollEntity(String scroll) {
    try (XContentBuilder entity = JsonXContent.contentBuilder()) {
        return new StringEntity(entity.startObject()
            .field("scroll_id", scroll)
            .endObject().string(), ContentType.APPLICATION_JSON);
    } catch (IOException e) {
        throw new ElasticsearchException("failed to build scroll entity", e);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:RemoteRequestBuilders.java

示例9: index

void index(String key, String value) {
  try {
    final HttpEntity entity = new NStringEntity(value, ContentType.APPLICATION_JSON);
    final String endpoint = String.format("%s/%s", "/tweets/tweet", key);
    final Response response = restClient.performRequest("PUT", endpoint, Collections.<String, String>emptyMap(), entity);
    if (response.getStatusLine().getStatusCode() != 200
        && response.getStatusLine().getStatusCode() != 201) {
      throw new IllegalStateException(response.getStatusLine().getReasonPhrase());
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:13,代碼來源:ElasticsearchTweetRepository.java

示例10: createIndex

/**
 * Creates an index and adds an alias to it.
 * @param aliasName
 * @param version
 * @param indexConf must be a valid ES config JSON.
 */
public void createIndex(String aliasName, int version, String indexConf) {
    HttpEntity entity = new NStringEntity(indexConf, ContentType.APPLICATION_JSON);
    String indexName = aliasName + INDEX_VERSION_INFIX + version;
    try {
        restClient.performRequest("PUT", indexName, Collections.emptyMap(), entity);
        addAlias(indexName, aliasName);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:16,代碼來源:IndexManager.java

示例11: testDuplicateQueueCreation

@Test
public void testDuplicateQueueCreation() throws IOException {
    QueueCreateRequest request = new QueueCreateRequest()
            .name("testDuplicateQueueCreation").durable(false).autoDelete(false);
    HttpPost httpPost = new HttpPost(apiBasePath + "/queues");

    String value = objectMapper.writeValueAsString(request);
    StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_JSON);
    httpPost.setEntity(stringEntity);

    CloseableHttpResponse response = client.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_CREATED, "Incorrect status code");

    response = client.execute(httpPost);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_BAD_REQUEST, "Incorrect status "
            + "code");

    String body = EntityUtils.toString(response.getEntity());
    Error error = objectMapper.readValue(body, Error.class);
    Assert.assertFalse(error.getMessage().isEmpty(), "Response body shouldn't be empty");
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:21,代碼來源:QueuesRestApiTest.java

示例12: send

@Override
public void send(String body) throws IOException {
	HttpEntity entity = new NStringEntity(body.toString(), ContentType.APPLICATION_JSON);
	Response response = this.restClient.performRequest(HTTP_METHOD, "_bulk", Collections.emptyMap(), entity);
	if (response.getStatusLine().getStatusCode() >= 300) {
		throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
	}
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:8,代碼來源:ElasticBulkSender.java

示例13: toEntity

static <T> StringEntity toEntity(T resource) {
    StringWriter sink = new StringWriter();
    new JsonSinkWriter<>(sink).write(resource);
    String serializedResource = sink.toString();
    return new StringEntity(serializedResource,
                            ContentType.APPLICATION_JSON);  // (*)
}
 
開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:7,代碼來源:JsonEntity.java

示例14: put

public <T> T put(String resource, String body ,Class<T> responseClass, boolean assertSuccess) throws IOException {
	final HttpEntity entity = new NStringEntity(body, ContentType.APPLICATION_JSON);
	final Response response = client.performRequest("PUT", resource, Collections.<String, String>emptyMap(),
			entity);
	if (assertSuccess) {
		assertSuccess(response);
	}
	return mapper.readValue(IOUtils.toString(response.getEntity().getContent(), "UTF-8"), responseClass);
}
 
開發者ID:Top-Q,項目名稱:elasticsearch-client,代碼行數:9,代碼來源:ESRest.java

示例15: createRequestFor

private HttpPost createRequestFor(final DeltaAnalysisRequest payload) throws URISyntaxException {
    final CodeSceneUser user = config.user();

    final Header authorization = new BasicHeader("Authorization", "Basic " + user.asBase64Encoded());

    HttpPost codeSceneRequest = new HttpPost(config.codeSceneUrl().toURI());
    codeSceneRequest.addHeader(authorization);

    StringEntity requestEntity = new StringEntity(
            payload.asJson().toString(),
            ContentType.APPLICATION_JSON);
    codeSceneRequest.setEntity(requestEntity);

    return codeSceneRequest;
}
 
開發者ID:empear-analytics,項目名稱:codescene-jenkins-plugin,代碼行數:15,代碼來源:DeltaAnalysis.java


注:本文中的org.apache.http.entity.ContentType.APPLICATION_JSON屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。