本文整理匯總了Java中org.eclipse.jetty.client.api.Request類的典型用法代碼示例。如果您正苦於以下問題:Java Request類的具體用法?Java Request怎麽用?Java Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Request類屬於org.eclipse.jetty.client.api包,在下文中一共展示了Request類的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: newRequest
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Override
public Request newRequest(String uri) {
Request retval = mock(Request.class);
try {
if (requestsTimeout || (isFirstRequestTimeout && requests.isEmpty())) {
when(retval.send()).thenThrow(new TimeoutException());
} else {
when(retval.send()).thenReturn(httpResponse);
}
if (requestsFail && featureFlag.equals("true")) {
when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} else if (responseException != null) {
when(httpResponse.getStatus()).thenReturn(responseException.getCategory().getHttpStatus());
} else {
when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_OK);
}
} catch (Exception e) {
e.printStackTrace();
}
when(retval.method(anyString())).thenReturn(retval);
when(retval.content(any(ContentProvider.class))).thenReturn(retval);
when(retval.timeout(anyLong(), any(TimeUnit.class))).thenReturn(retval);
requests.add(uri);
return retval;
}
示例3: setup
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Before
public void setup() throws Exception {
HttpClient httpClient = mock(HttpClient.class);
response = mock(ContentResponse.class);
when(response.getStatus()).thenReturn(200);
when(response.getContentAsString()).thenReturn(healthInfo);
HttpFields headers = new HttpFields();
headers.add(CONSUL_INDEX, "42");
when(response.getHeaders()).thenReturn(headers);
Request request = mock(Request.class);
when(httpClient.newRequest(anyString())).thenReturn(request);
when(request.send()).thenReturn(response);
props = new ServiceProperties();
props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:1234");
worker = new RegistrationMonitorWorker(httpClient, props);
worker.setServiceName("foobar");
}
示例4: postRequest
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
private Request postRequest(ApiURL url, JsonObject r, Timeout timeout) {
Fields fields = new Fields();
fields.add("r", GsonUtil.gson.toJson(r));
Request request = httpClient.newRequest(url.getUrl()).method(HttpMethod.POST).agent(ApiURL.USER_AGENT)
.header("Origin", url.getOrigin()).content(new FormContentProvider(fields));
if (url.getReferer() != null) {
request.header(HttpHeader.REFERER, url.getReferer());
}
if (timeout != null) {
request.timeout(timeout.getTime(), timeout.getUnit());
}
return request;
}
示例5: addProxyHeaders
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Override
protected void addProxyHeaders(final HttpServletRequest clientRequest, final Request proxyRequest) {
super.addProxyHeaders(clientRequest, proxyRequest);
// Forward security identifier if defined
proxyRequest.header("SM_UNIVERSALID", clientRequest.getUserPrincipal() == null
? StringUtils.trimToNull(clientRequest.getParameter(apiUserParameter)) : clientRequest.getUserPrincipal().getName());
// Forward original SESSIONID
proxyRequest.header("SM_SESSIONID", clientRequest.getSession(false) == null ? null : clientRequest.getSession(false).getId());
// Forward API key, if defined.
proxyRequest.header(apiKeyHeader, StringUtils.trimToNull(clientRequest.getParameter(apiKeyParameter)));
// Forward all cookies but JSESSIONID.
final String cookies = clientRequest.getHeader(HEADER_COOKIE);
if (cookies != null) {
proxyRequest.header(HEADER_COOKIE, StringUtils.trimToNull(
Arrays.stream(cookies.split("; ")).filter(cookie -> !cookie.split("=")[0].equals(COOKIE_JEE)).collect(Collectors.joining("; "))));
}
}
示例6: addProxyHeadersCookie
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Test
public void addProxyHeadersCookie() {
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
final Request exchange = Mockito.mock(Request.class);
final HttpSession session = Mockito.mock(HttpSession.class);
final Principal principal = Mockito.mock(Principal.class);
Mockito.when(request.getSession(false)).thenReturn(session);
Mockito.when(request.getHeader("cookie")).thenReturn("JSESSIONID=value1; OTHER1=value2; OTHER2=value3");
Mockito.when(session.getId()).thenReturn("J_SESSIONID");
Mockito.when(request.getUserPrincipal()).thenReturn(principal);
Mockito.when(principal.getName()).thenReturn("junit");
servlet.addProxyHeaders(request, exchange);
Mockito.verify(exchange, Mockito.times(1)).header("SM_UNIVERSALID", "junit");
Mockito.verify(exchange, Mockito.times(1)).header("SM_SESSIONID", "J_SESSIONID");
Mockito.verify(exchange, Mockito.times(1)).header("cookie", "OTHER1=value2; OTHER2=value3");
}
示例7: 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;
}
示例8: 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));
}
示例9: 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();
}
示例10: 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;
}
示例11: setHeaderAndQueryInfo
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
private static Request setHeaderAndQueryInfo(Request request, ResponseInfo responseInfo) {
Map<String, String> requestHeaders = responseInfo.getHeaders();
for ( String headerKey : requestHeaders.keySet() ) {
request.header(headerKey, requestHeaders.get(headerKey));
}
request.method(request.getMethod());
request.accept(responseInfo.getRequestAccept());
Map<String, String> requestQueryParams = responseInfo.getQueryStringMap();
for ( String queryKey : requestQueryParams.keySet() ) {
request.param(queryKey, requestQueryParams.get(queryKey));
}
return request;
}
示例12: testGenerateX509CertificateInvalidStatus
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Test
public void testGenerateX509CertificateInvalidStatus() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(400);
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
示例13: testGenerateX509CertificateResponseNull
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Test
public void testGenerateX509CertificateResponseNull() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn(null);
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
示例14: testGenerateX509CertificateResponseEmpty
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Test
public void testGenerateX509CertificateResponseEmpty() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn("");
assertNull(certSigner.generateX509Certificate("csr", null, 0));
}
示例15: testGenerateX509Certificate
import org.eclipse.jetty.client.api.Request; //導入依賴的package包/類
@Test
public void testGenerateX509Certificate() throws Exception {
HttpClient httpClient = Mockito.mock(HttpClient.class);
HttpCertSignerFactory certFactory = new HttpCertSignerFactory();
HttpCertSigner certSigner = (HttpCertSigner) certFactory.create();
certSigner.setHttpClient(httpClient);
Request request = Mockito.mock(Request.class);
Mockito.when(httpClient.POST("https://localhost:443/certsign/v2/x509")).thenReturn(request);
ContentResponse response = Mockito.mock(ContentResponse.class);
Mockito.when(request.send()).thenReturn(response);
Mockito.when(response.getStatus()).thenReturn(201);
Mockito.when(response.getContentAsString()).thenReturn("{\"pem\": \"pem-value\"}");
String pem = certSigner.generateX509Certificate("csr", null, 0);
assertEquals(pem, "pem-value");
}