本文整理汇总了Java中org.eclipse.jetty.client.api.Request.header方法的典型用法代码示例。如果您正苦于以下问题:Java Request.header方法的具体用法?Java Request.header怎么用?Java Request.header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.client.api.Request
的用法示例。
在下文中一共展示了Request.header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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("; "))));
}
}
示例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;
}
示例4: 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;
}
示例5: 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);
}
});
}
示例6: doHttpRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Override
protected void doHttpRequest(Request request, ClientResponseCallback callback) {
// set access token for all requests
setAccessToken(request);
// set default charset
request.header(HttpHeader.ACCEPT_CHARSET, StringUtil.__UTF8);
// TODO check if this is really needed or not, since SF response content type seems fixed
// check if the default accept content type must be used
if (!request.getHeaders().contains(HttpHeader.ACCEPT)) {
final String contentType = getContentType(DEFAULT_ACCEPT_TYPE);
request.header(HttpHeader.ACCEPT, contentType);
// request content type and charset is set by the request entity
}
super.doHttpRequest(request, callback);
}
示例7: 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));
}
示例8: 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;
}
示例9: setRequestHeaders
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
private void setRequestHeaders(Request request, JSONObject requestHeadersJson) {
@SuppressWarnings("unchecked")
Iterator<String> headersIterator = requestHeadersJson.keys();
// Convert JSONObject of headers into Header ArrayList
while (headersIterator.hasNext()) {
String headerName = headersIterator.next();
String headerValue;
try {
headerValue = requestHeadersJson.getString(headerName);
logger.debug("Jetty set header {} = {}", headerName, headerValue);
if (!headerName.equalsIgnoreCase("Content-Length")) {
request.header(headerName, headerValue);
}
} catch (JSONException e) {
logger.error("Error processing request headers: {}", e.getMessage());
}
}
}
示例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());
}
示例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());
}
示例12: 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());
}
示例13: customizeProxyRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
@Override
protected void customizeProxyRequest(Request proxyRequest, HttpServletRequest request) {
proxyRequest.onRequestContent(new RequestContentListener(request));
// Hop-by-Hop ヘッダーを除去します
proxyRequest.header(HttpHeader.VIA, null);
proxyRequest.header(HttpHeader.X_FORWARDED_FOR, null);
proxyRequest.header(HttpHeader.X_FORWARDED_PROTO, null);
proxyRequest.header(HttpHeader.X_FORWARDED_HOST, null);
proxyRequest.header(HttpHeader.X_FORWARDED_SERVER, null);
proxyRequest.header("Origin", null);
String queryString = ((org.eclipse.jetty.server.Request) request).getQueryString();
fixQueryString(proxyRequest, queryString);
super.customizeProxyRequest(proxyRequest, request);
}
示例14: newRequest
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
public Request newRequest(HttpClient httpClient) {
Request request = httpClient.newRequest(uri);
request.content(contentProvider).method(method);
for (String key : headers.keySet()) {
if (! "User-Agent".equals(key)) {
request.header(key, headers.get(key));
}
}
return request;
}
示例15: get
import org.eclipse.jetty.client.api.Request; //导入方法依赖的package包/类
private ContentResponse get(ApiURL url, Object... params)
throws InterruptedException, ExecutionException, TimeoutException {
Request request = httpClient.newRequest(url.buildUrl(params)).method(HttpMethod.GET).agent(ApiURL.USER_AGENT);
if (url.getReferer() != null) {
request.header(HttpHeader.REFERER, url.getReferer());
}
return request.send();
}