本文整理汇总了Java中javax.ws.rs.client.Invocation.Builder.header方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.header方法的具体用法?Java Builder.header怎么用?Java Builder.header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.client.Invocation.Builder
的用法示例。
在下文中一共展示了Builder.header方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
public static Response processRequest(
String url, String method, String payload, String authHeader) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Builder builder = target.request();
builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
if (authHeader != null) {
builder.header(HttpHeaders.AUTHORIZATION, authHeader);
}
return (payload != null)
? builder.build(method, Entity.json(payload)).invoke()
: builder.build(method).invoke();
}
示例2: prepareRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
private Builder prepareRequest(Request request) {
WebTarget webTarget = _client.target(request.getUri());
Map<String, String> queryParams = request.getQueryParams();
if (queryParams != null) {
for (Entry<String, String> param : queryParams.entrySet()) {
webTarget = webTarget.queryParam(param.getKey(), param.getValue());
}
}
Map<String, Object> pathTemplateParams = request.getPathTemplateParams();
if (pathTemplateParams != null) {
webTarget = webTarget.resolveTemplates(pathTemplateParams);
}
Builder builder = webTarget.request();
for (Cookie currCookie : request.getCookies()) {
builder = builder.cookie(currCookie);
}
for (Entry<String, Object> currEntry : request.getHeaders().entrySet()) {
builder = builder.header(currEntry.getKey(), currEntry.getValue());
}
return builder;
}
示例3: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
public Response processRequest(String url, String method, String payload, String authHeader) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Builder builder = target.request();
builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
if (authHeader != null) {
builder.header(HttpHeaders.AUTHORIZATION, authHeader);
}
return (payload != null)
? builder.build(method, Entity.json(payload)).invoke()
: builder.build(method).invoke();
}
示例4: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
public Response processRequest(String url, String method, String payload)
throws GeneralSecurityException, IOException {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Builder builder = target.request();
builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
builder.header(
HttpHeaders.AUTHORIZATION,
"Bearer "
+ new JWTVerifier()
.createJWT("fred", new HashSet<String>(Arrays.asList("orchestrator"))));
return (payload != null)
? builder.build(method, Entity.json(payload)).invoke()
: builder.build(method).invoke();
}
示例5: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
private Response processRequest(String url, String method, String payload, String authHeader) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Builder builder = target.request();
builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
if (authHeader != null) {
builder.header(HttpHeaders.AUTHORIZATION, authHeader);
}
return (payload != null)
? builder.build(method, Entity.json(payload)).invoke()
: builder.build(method).invoke();
}
示例6: processRequest
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
public static Response processRequest(
String url, String method, String payload, String authHeader) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Builder builder = target.request();
if (payload != null) {
builder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
}
if (authHeader != null) {
builder.header(HttpHeaders.AUTHORIZATION, authHeader);
}
return (payload != null)
? builder.build(method, Entity.json(payload)).invoke()
: builder.build(method).invoke();
}
示例7: getBuilder
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
private Builder getBuilder(String path) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(openFireAddress).path(path);
Builder request = target.request(MediaType.APPLICATION_XML);
request.header("Authorization", openFireToken);
return request;
}
示例8: request
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
public Builder request(final WebTarget target) throws PulsarAdminException {
try {
Builder builder = target.request(MediaType.APPLICATION_JSON);
// Add headers for authentication if any
if (auth != null && auth.getAuthData().hasDataForHttp()) {
for (Map.Entry<String, String> header : auth.getAuthData().getHttpHeaders()) {
builder.header(header.getKey(), header.getValue());
}
}
return builder;
} catch (Throwable t) {
throw new GettingAuthenticationDataException(t);
}
}
示例9: addHeaders
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
private void addHeaders(HttpServletRequest request, Builder requestBuilder) {
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = headerNames.nextElement();
requestBuilder.header(key, request.getHeader(key));
}
}
示例10: will_fail_on_init
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void will_fail_on_init(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA_LOWERCASE, XHubDigest.SHA1, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
resp.close();
}
示例11: a_post_with_expected_signature_passes_the_filter
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void a_post_with_expected_signature_passes_the_filter(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA_LOWERCASE, XHubDigest.SHA1, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.ACCEPTED.getStatusCode()));
resp.close();
}
示例12: a_post_with_signature_with_wrong_password_fails
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void a_post_with_signature_with_wrong_password_fails(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "modified-password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA_LOWERCASE, XHubDigest.SHA1, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
resp.close();
}
示例13: a_post_with_signature_with_wrong_converter_fails
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void a_post_with_signature_with_wrong_converter_fails(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA, XHubDigest.SHA1, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.INTERNAL_SERVER_ERROR.getStatusCode()));
resp.close();
}
示例14: a_post_with_signature_with_SH256_digest_succeed
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void a_post_with_signature_with_SH256_digest_succeed(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA_LOWERCASE, XHubDigest.SHA256, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.ACCEPTED.getStatusCode()));
resp.close();
}
示例15: a_post_with_signature_with_SHA512_digest_succeed
import javax.ws.rs.client.Invocation.Builder; //导入方法依赖的package包/类
@Test
public void a_post_with_signature_with_SHA512_digest_succeed(@ArquillianResteasyResource("resources/webhook") WebTarget target) {
String data = "This our important content to be sent";
String secret = "password4tests";
final Builder request = target.request(MediaType.TEXT_PLAIN);
request.header("X-Hub-Signature", XHub.generateHeaderXHubToken(XHubConverter.HEXA_LOWERCASE, XHubDigest.SHA512, secret, data.getBytes()));
Response resp = request.post(Entity.text(data));
assertThat(resp, notNullValue());
assertThat(resp.getStatus(), is(Status.ACCEPTED.getStatusCode()));
resp.close();
}