本文整理汇总了Java中org.eclipse.jetty.client.api.Request.send方法的典型用法代码示例。如果您正苦于以下问题:Java Request.send方法的具体用法?Java Request.send怎么用?Java Request.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.api.Request
的用法示例。
在下文中一共展示了Request.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRetry
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Test
public void testRetry() throws Exception {
SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
String accessToken = sf.getSession().getAccessToken();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
Request logoutGet = httpClient.newRequest(uri)
.method(HttpMethod.GET)
.timeout(1, TimeUnit.MINUTES);
ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
JobInfo jobInfo = new JobInfo();
jobInfo.setOperation(OperationEnum.INSERT);
jobInfo.setContentType(ContentType.CSV);
jobInfo.setObject(Merchandise__c.class.getSimpleName());
createJob(jobInfo);
}
示例2: getTransactions
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
public Map<String, Transaction> getTransactions(String accountId, int offset, int transactionsPerRequest, boolean ignoreException)
{
Map<String, Transaction> transactionLookup = null;
try
{
InputStreamResponseListener listener = new InputStreamResponseListener();
Request request = httpClient.POST(BURST_API_URL)
.param("requestType", "getAccountTransactions")
.param("firstIndex", String.valueOf(offset))
.param("lastIndex", String.valueOf(offset + transactionsPerRequest))
.param("account", accountId);
request.send(listener);
Response response = listener.get(BurstcoinFaucetProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS);
transactionLookup = handleGetTransactionsResponse(listener, response, ignoreException);
}
catch(Exception e)
{
LOG.warn("Error: Failed to 'getAccountTransactions' for accountId '" + accountId + "' : " + e.getMessage());
}
return transactionLookup;
}
示例3: 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));
}
示例4: rawRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
protected String rawRequest(String url, Map<String, String> params) throws InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
Request req = httpClient.newRequest(new String(url.getBytes("UTF-8"), "UTF-8"))
.header(HttpHeader.CONTENT_ENCODING, "UTF-8")
.method(HttpMethod.GET)
.header(HttpHeader.ACCEPT_ENCODING, "UTF-8");
req = req.param("app_token", APIKeys.getAPPKey());
if (params != null) {
for (String key : params.keySet()) {
req = req.param(key, params.get(key));
}
}
Main.log.info("GET {}, {}, {}", req, req.getQuery(), req.getParams());
ContentResponse resp = req.send();
if (resp.getStatus() != HttpStatus.OK_200) {
throw new HttpRequestException(
"Request ended with non-OK status: "
+ HttpStatus.getMessage(resp.getStatus()),
resp.getRequest()
);
}
return resp.getContentAsString();
}
示例5: 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;
}
示例6: testRetry
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Test
public void testRetry() throws Exception {
SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
String accessToken = sf.getSession().getAccessToken();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
Request logoutGet = httpClient.newRequest(uri)
.method(HttpMethod.GET)
.timeout(1, TimeUnit.MINUTES);
ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
doTestGetGlobalObjects("");
}
示例7: 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 "";
}
}
示例8: 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;
}
示例9: fromUrl
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
public static BloomFilter fromUrl(String url) throws Exception
{
log.info("Loading bloom filter from " + url);
Request request = BloomFilterScalarFunctions.HTTP_CLIENT.newRequest(url);
request.method("GET");
InputStreamResponseListener listener = new InputStreamResponseListener();
request.send(listener);
// Wait for the response headers to arrive
Response response = listener.get(10, TimeUnit.SECONDS);
// Look at the response
if (response.getStatus() == 200) {
// Use try-with-resources to close input stream.
try (InputStream responseContent = listener.getInputStream()) {
byte[] bytes = ByteStreams.toByteArray(responseContent);
return newInstance(bytes);
}
}
log.warn("Non-200 response status " + response.getStatus());
return null;
}
示例10: 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;
}
示例11: 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());
}
示例12: 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());
}
示例13: 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());
}
示例14: 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());
}
示例15: 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());
}