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


Java Request.content方法代碼示例

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


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

示例1: createBatch

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Override
public void createBatch(InputStream batchStream, String jobId, ContentType contentTypeEnum, 
    final BatchInfoResponseCallback callback) {
    final Request post = getRequest(HttpMethod.POST, batchUrl(jobId, null));
    post.content(new InputStreamContentProvider(batchStream));
    post.header(HttpHeader.CONTENT_TYPE, getContentType(contentTypeEnum) + ";charset=" + StringUtil.__UTF8);

    // make the call and parse the result
    doHttpRequest(post, new ClientResponseCallback() {
        @Override
        public void onResponse(InputStream response, SalesforceException ex) {
            BatchInfo value = null;
            try {
                value = unmarshalResponse(response, post, BatchInfo.class);
            } catch (SalesforceException e) {
                ex = e;
            }
            callback.onResponse(value, ex);
        }
    });
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:DefaultBulkApiClient.java

示例2: executeRequest

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
protected ResponseEntity<String> executeRequest(URI url, HttpMethod method, HttpHeaders headers, String body) {
	Request httpRequest = this.httpClient.newRequest(url).method(method);
	addHttpHeaders(httpRequest, headers);
	if (body != null) {
		httpRequest.content(new StringContentProvider(body));
	}
	ContentResponse response;
	try {
		response = httpRequest.send();
	}
	catch (Exception ex) {
		throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
	}
	HttpStatus status = HttpStatus.valueOf(response.getStatus());
	HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
	return (response.getContent() != null ?
		new ResponseEntity<String>(response.getContentAsString(), responseHeaders, status) :
		new ResponseEntity<String>(responseHeaders, status));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:JettyXhrTransport.java

示例3: sendMessageToHyVarRec

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
protected String sendMessageToHyVarRec(String message, URI uri) throws UnresolvedAddressException, ExecutionException, InterruptedException, TimeoutException {
	HttpClient hyvarrecClient = new HttpClient();
	try {
		hyvarrecClient.start();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return null;
	}
	URI hyvarrecUri = uri;
	Request hyvarrecRequest = hyvarrecClient.POST(hyvarrecUri);
	hyvarrecRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
	hyvarrecRequest.content(new StringContentProvider(message), "application/json");
	ContentResponse hyvarrecResponse;
	String hyvarrecAnswerString = "";
	hyvarrecResponse = hyvarrecRequest.send();
	hyvarrecAnswerString = hyvarrecResponse.getContentAsString();

	// Only for Debug
	System.err.println("HyVarRec Answer: "+hyvarrecAnswerString);
	
	return hyvarrecAnswerString;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:24,代碼來源:DwAnalysesClient.java

示例4: upsertSObject

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Override
public void upsertSObject(String sObjectName, String fieldName, String fieldValue, InputStream sObject,
                          ResponseCallback callback) {
    final Request patch = getRequest("PATCH",
            sobjectsExternalIdUrl(sObjectName, fieldName, fieldValue));

    // requires authorization token
    setAccessToken(patch);

    // input stream as entity content
    patch.content(new InputStreamContentProvider(sObject));
    // TODO will the encoding always be UTF-8??
    patch.header(HttpHeader.CONTENT_TYPE, PayloadFormat.JSON.equals(format) ? APPLICATION_JSON_UTF8 : APPLICATION_XML_UTF8);

    doHttpRequest(patch, new DelegatingClientCallback(callback));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:DefaultRestClient.java

示例5: restPostRequest

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
private String restPostRequest(String endpoint, String content) {
  try {
    LOGGER.debug("Sending POST request to: " + config.getRsServerUrl() + endpoint);
    httpClient.start();
    Request request = httpClient.newRequest(config.getRsServerUrl() + endpoint);
    request = request.method(HttpMethod.POST);
    request = request.content(new StringContentProvider(content, "UTF-8"));
    ContentResponse response = request.send();
    httpClient.stop();
    LOGGER.debug("Got response: " + response.getContentAsString());
    return response.getContentAsString();
  } catch (Exception e) {
    LOGGER.error(null, e);
    return "";
  }
}
 
開發者ID:Braveno,項目名稱:cosigner,代碼行數:17,代碼來源:AdminConnector.java

示例6: bloomFilterPersist

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@SqlType(StandardTypes.BOOLEAN)
@Nullable
@SqlNullable
public static Boolean bloomFilterPersist(@SqlNullable @SqlType(BloomFilterType.TYPE) Slice bloomFilterSlice, @SqlType(StandardTypes.VARCHAR) Slice urlSlice) throws Exception
{
    // Nothing todo
    if (urlSlice == null) {
        return true;
    }
    BloomFilter bf = getOrLoadBloomFilter(bloomFilterSlice);

    // Persist
    // we do not try catch here to make sure that errors are communicated clearly to the client
    // and typical retry logic continues to work
    String url = new String(urlSlice.getBytes());
    if (!HTTP_CLIENT.isStarted()) {
        log.warn("Http client was not started, trying to start");
        HTTP_CLIENT.start();
    }
    Request post = HTTP_CLIENT.POST(url);
    post.content(new StringContentProvider(new String(bf.toBase64())));
    post.method("PUT");
    post.send();
    log.info("Persisted " + bf.toString() + " " + url);
    return true;
}
 
開發者ID:RobinUS2,項目名稱:presto-bloomfilter,代碼行數:27,代碼來源:BloomFilterPersistScalarFunction.java

示例7: sendReceive

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
/**
 * Send the SOAP message using Jetty HTTP client. Jetty is used in preference to
 * HttpURLConnection which can result in the HNAP interface becoming unresponsive.
 *
 * @param action - SOAP Action to send
 * @param timeout - Connection timeout in milliseconds
 * @return The result
 * @throws IOException
 * @throws SOAPException
 * @throws SAXException
 * @throws ExecutionException
 * @throws TimeoutException
 * @throws InterruptedException
 */
protected Document sendReceive(final SOAPMessage action, final int timeout) throws IOException, SOAPException,
        SAXException, InterruptedException, TimeoutException, ExecutionException {

    Document result;

    final Request request = httpClient.POST(uri);
    request.timeout(timeout, TimeUnit.MILLISECONDS);

    final Iterator<?> it = action.getMimeHeaders().getAllHeaders();
    while (it.hasNext()) {
        final MimeHeader header = (MimeHeader) it.next();
        request.header(header.getName(), header.getValue());
    }

    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        action.writeTo(os);
        request.content(new BytesContentProvider(os.toByteArray()));
        final ContentResponse response = request.send();
        try (final ByteArrayInputStream is = new ByteArrayInputStream(response.getContent())) {
            result = parser.parse(is);
        }
    }

    return result;
}
 
開發者ID:openhab,項目名稱:openhab2-addons,代碼行數:40,代碼來源:DLinkHNAPCommunication.java

示例8: testSubscriptionDoesntExist

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testSubscriptionDoesntExist() throws Exception {
    String subscription = producer.generateSubscriptionKey();
    String requestUrl = producer.generateHashedURLFromKey("subscription", subscription);

    HttpClient client = new HttpClient();
    client.setFollowRedirects(false);
    client.start();

    Request request = client.newRequest(requestUrl);
    request.method(HttpMethod.POST);
    request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_unsubscribe.xml")));

    ContentResponse response = request.send();
    assertEquals("Response was wrong for url http://" + requestUrl, 500, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:17,代碼來源:SimpleSubscriptionManagerTest.java

示例9: testRenew

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testRenew() throws Exception {

    String subscription = producer.generateSubscriptionKey();
    String requestUrl = producer.generateHashedURLFromKey("subscription", subscription);

    manager.addSubscriber(subscription, System.currentTimeMillis());

    HttpClient client = new HttpClient();
    client.setFollowRedirects(false);
    client.start();

    Request request = client.newRequest(requestUrl);
    request.method(HttpMethod.POST);
    request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_renew.xml")));

    ContentResponse response = request.send();
    assertEquals("Response status was wrong", 200, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:20,代碼來源:SimpleSubscriptionManagerTest.java

示例10: testSimpleServer

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testSimpleServer() throws Exception {

    // Start the client
    SslContextFactory sslFactory = new SslContextFactory();

    HttpClient client = new HttpClient(sslFactory);
    client.setFollowRedirects(true);
    client.start();

    // Send response
    Request request = client.newRequest("http://localhost:8080/");
    request.method(HttpMethod.POST);
    request.header(HttpHeader.CONTENT_TYPE, "application");
    request.header(HttpHeader.CONTENT_LENGTH, "200");
    request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_html_content.html")),
                                                                       "text/html;charset/utf-8");
    ContentResponse response = request.send();
    assertEquals("Response on bad request was not 500", 500, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:21,代碼來源:ApplicationServerTest.java

示例11: testSendingXML

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testSendingXML() throws Exception {

    // Start the client
    SslContextFactory sslFactory = new SslContextFactory();

    HttpClient client = new HttpClient(sslFactory);
    client.setFollowRedirects(true);
    client.start();

    // Send response
    Request request = client.newRequest("http://localhost:8080/");
    request.method(HttpMethod.POST);
    request.header(HttpHeader.CONTENT_TYPE, "application");
    request.header(HttpHeader.CONTENT_LENGTH, "200");
    request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_xml.xml")),
            "application/soap+xml;charset/utf-8");

    ContentResponse response = request.send();
    assertEquals("Response on bad request was not 500", 500, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:22,代碼來源:ApplicationServerTest.java

示例12: testSendingSoap

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testSendingSoap() throws Exception {
    SoapForwardingHub soapForwardingHub = new SoapForwardingHub();

    // Start the client
    SslContextFactory sslFactory = new SslContextFactory();

    HttpClient client = new HttpClient(sslFactory);
    client.setFollowRedirects(true);
    client.start();

    Object object = XMLParser.parse(getClass().getResourceAsStream("/server_test_soap.xml"));
    Envelope env = (Envelope)((JAXBElement)((InternalMessage) object).getMessage()).getValue();
    Header head = env.getHeader();
    Body body = env.getBody();

    // Send response
    Request request = client.newRequest("http://localhost:8080/");
    request.method(HttpMethod.POST);
    request.content(new InputStreamContentProvider(getClass().getResourceAsStream("/server_test_soap.xml")),
            "application/soap+xml;charset/utf-8");

    ContentResponse response = request.send();
    assertEquals("Expected not found", 404, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:26,代碼來源:ApplicationServerTest.java

示例13: testSubscribe

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Test
public void testSubscribe() throws Exception {

    // Start the client
    SslContextFactory sslFactory = new SslContextFactory();

    HttpClient client = new HttpClient(sslFactory);
    client.setFollowRedirects(true);
    client.start();

    // Send response
    InputStream file = getClass().getResourceAsStream("/server_test_subscribe.xml");

    Request request = client.newRequest("http://localhost:8080/");
    request.method(HttpMethod.POST);
    request.header(HttpHeader.CONTENT_TYPE, "application");
    request.header(HttpHeader.CONTENT_LENGTH, "200");
    request.content(new InputStreamContentProvider(file),
            "application/soap+xml;charset/utf-8");

    ContentResponse response = request.send();
    assertEquals("Expected not found", 404, response.getStatus());
}
 
開發者ID:tOgg1,項目名稱:WS-Nu,代碼行數:24,代碼來源:ApplicationServerTest.java

示例14: sendRequest

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
protected String sendRequest(String path, String data, HttpMethod method) throws Exception {
    String url = getServiceUrl(path);
    Request request = httpClient.newRequest(url).method(method).
            header(HttpHeader.CONTENT_TYPE, "application/json");
    if (data != null) {
        request.content(new StringContentProvider(data));
    }
    ContentResponse response = request.send();
    return response.getContentAsString();
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:11,代碼來源:HttpCommandProxy.java

示例15: post

import org.eclipse.jetty.client.api.Request; //導入方法依賴的package包/類
@Override
public <T> Response<T> post(String uri, HttpFields headers, String body, MediaType bodyMediaType, Class<T> expectedModel) throws Exception {
  Request request = newRequest(uri);
  request.method(HttpMethod.POST);
  request.content(new StringContentProvider(body, mediaTypeToCharset(bodyMediaType)));

  headers = appendDefaultPostHeaders(headers, body, bodyMediaType);
  return execute(request, headers, expectedModel);
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:10,代碼來源:WebClientImpl.java


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