本文整理汇总了Java中javax.ws.rs.core.Response.getHeaderString方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getHeaderString方法的具体用法?Java Response.getHeaderString怎么用?Java Response.getHeaderString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response
的用法示例。
在下文中一共展示了Response.getHeaderString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLoginJwtValidity
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* Tests the JWT we get back from the auth service is valid. We test the JWT to make sure it was
* signed correctly.
*
* <p>We do not validate other things, like the issued at time, expired time, etc.
*
* <p>The test case has access to the keystore that the server should have used to sign the JWT.
*/
@Test
public void testLoginJwtValidity() throws Exception {
// Get the JWT from the auth service.
Response response = processRequest(authServiceURL, "GET", null, null);
assertEquals(
"HTTP response code should have been " + Status.OK.getStatusCode() + ".",
Status.OK.getStatusCode(),
response.getStatus());
String authHeader = response.getHeaderString("Authorization");
// Open the keystore that the server should have used to sign the JWT.
KeyStore ks = KeyStore.getInstance("JCEKS");
InputStream ksStream = this.getClass().getResourceAsStream("/keystore.jceks");
char[] password = new String("secret").toCharArray();
ks.load(ksStream, password);
java.security.cert.Certificate cert = ks.getCertificate("default");
PublicKey publicKey = cert.getPublicKey();
// Make sure it's valid. Use the server's public key to check.
new JWTVerifier().validateJWT(authHeader, publicKey);
}
示例2: testOptionsLdprs
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testOptionsLdprs() {
when(mockResource.getInteractionModel()).thenReturn(LDP.RDFSource);
final OptionsHandler optionsHandler = new OptionsHandler(mockRequest, mockResourceService, null);
final Response res = optionsHandler.ldpOptions(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
assertNull(res.getHeaderString(ACCEPT_POST));
assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
final String allow = res.getHeaderString(ALLOW);
assertTrue(allow.contains(GET));
assertTrue(allow.contains(HEAD));
assertTrue(allow.contains(OPTIONS));
assertTrue(allow.contains(PUT));
assertTrue(allow.contains(DELETE));
assertTrue(allow.contains(PATCH));
assertFalse(allow.contains(POST));
}
示例3: testOptionsLdpc
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testOptionsLdpc() {
when(mockResource.getInteractionModel()).thenReturn(LDP.IndirectContainer);
final OptionsHandler optionsHandler = new OptionsHandler(mockRequest, mockResourceService, baseUrl);
final Response res = optionsHandler.ldpOptions(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
final String acceptPost = res.getHeaderString(ACCEPT_POST);
assertNotNull(acceptPost);
assertTrue(acceptPost.contains(APPLICATION_LD_JSON));
assertTrue(acceptPost.contains(APPLICATION_N_TRIPLES));
assertTrue(acceptPost.contains(TEXT_TURTLE.split(";")[0]));
assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
final String allow = res.getHeaderString(ALLOW);
assertNotNull(allow);
assertTrue(allow.contains(GET));
assertTrue(allow.contains(HEAD));
assertTrue(allow.contains(OPTIONS));
assertTrue(allow.contains(PUT));
assertTrue(allow.contains(DELETE));
assertTrue(allow.contains(PATCH));
assertTrue(allow.contains(POST));
}
示例4: setup
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Before
public void setup() throws MalformedURLException {
client = ClientBuilder.newClient();
client.register(PostNotFoundExceptionMapper.class);
client.register(CommentNotFoundExceptionMapper.class);
final WebTarget targetAuth = client.target(URI.create(new URL(base, "api/auth/login").toExternalForm()));
final Response resAuthGetAll = targetAuth.request()
.accept(MediaType.APPLICATION_JSON)
.post(form(new Form("username", "user").param("password", "password")));
assertEquals(200, resAuthGetAll.getStatus());
String token = resAuthGetAll.getHeaderString(HttpHeaders.AUTHORIZATION);
client.register(new JwtTokenAuthentication(token.substring(Constants.AUTHORIZATION_PREFIX.length())));
}
示例5: getRegionData
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public RegionDataParams getRegionData() throws IOException {
WebTarget webTarget = restClient.target(SERVER_PATH + "regiondata");
Invocation.Builder invocationBuilder =
webTarget.request();
invocationBuilder.header("clientId", clientId);
Response response = invocationBuilder.get();
String noTransfer = response.getHeaderString("nothingToTransfer");
if ("nothingToTransfer".equals(noTransfer)) {
return null;
}
int fileId = Integer.valueOf(response.getHeaderString("fileId"));
long offset = Long.valueOf(response.getHeaderString("offset"));
long size = Long.valueOf(response.getHeaderString("size"));
InputStream inputStream = response.readEntity(InputStream.class);
byte[] bytes = IOUtils.toByteArray(inputStream);
return new RegionDataParams(fileId, offset, size, bytes, response);
}
示例6: testMinimalLdprs
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testMinimalLdprs() {
when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(APPLICATION_LD_JSON_TYPE));
when(mockLdpRequest.getPrefer()).thenReturn(Prefer.valueOf("return=minimal"));
final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
mockIoService, mockBinaryService, baseUrl);
final Response res = getHandler.getRepresentation(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertNull(res.getHeaderString(ACCEPT_POST));
assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
assertEquals("return=minimal", res.getHeaderString(PREFERENCE_APPLIED));
assertNull(res.getHeaderString(ACCEPT_RANGES));
assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()));
assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE));
assertEquals(from(time), res.getLastModified());
final String allow = res.getHeaderString(ALLOW);
assertTrue(allow.contains(GET));
assertTrue(allow.contains(HEAD));
assertTrue(allow.contains(OPTIONS));
assertTrue(allow.contains(PUT));
assertTrue(allow.contains(DELETE));
assertTrue(allow.contains(PATCH));
assertFalse(allow.contains(POST));
final EntityTag etag = res.getEntityTag();
assertTrue(etag.isWeak());
assertEquals(md5Hex(time + baseUrl), etag.getValue());
final List<Object> varies = res.getHeaders().get(VARY);
assertFalse(varies.contains(RANGE));
assertFalse(varies.contains(WANT_DIGEST));
assertTrue(varies.contains(ACCEPT_DATETIME));
assertTrue(varies.contains(PREFER));
}
示例7: setup
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Before
public void setup() throws MalformedURLException {
client = ClientBuilder.newClient();
final WebTarget targetAuth = client.target(URI.create(new URL(base, "api/auth/login").toExternalForm()));
final Response resAuthGetAll = targetAuth.request()
.accept(MediaType.APPLICATION_JSON)
.post(form(new Form("username", "user").param("password", "password")));
assertEquals(200, resAuthGetAll.getStatus());
String token = resAuthGetAll.getHeaderString(HttpHeaders.AUTHORIZATION);
client.register(new JwtTokenAuthentication(token.substring(Constants.AUTHORIZATION_PREFIX.length())));
}
示例8: testMD5
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testMD5() throws Exception {
logger.info("start JaxRS Post test");
Client client = newClient();
client.register(ContentMD5Writer.class);
Response response = client.target(url + "myjaxrs/simple/valuesget").request().get();
String md5 = response.getHeaderString(CONTENT_MD5_STRING);
assertEquals("Content-MD5: ", "hcEzFGyuhOARcfBb4bM1sw==", md5);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:12,代码来源:ComponentTestCase.java
示例9: testJaxRSOptionsDeleteTypes
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testJaxRSOptionsDeleteTypes() throws Exception {
logger.info("start JaxRS options delete test");
Client client = newClient();
WebTarget target = client.target(url + "services/receiver/options");
Response response = target.request().options();
String calledMethod = response.getHeaderString("calledMethod");
double value = response.readEntity(Double.class);
assertEquals("options implemented: ", 88.99, value, 0.0);
client.close();
assertEquals("The filter registerCall is called only for @Logged services", OPTIONS, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/delete");
response = target.request().delete();
calledMethod = response.getHeaderString("calledMethod");
value = response.readEntity(Double.class);
assertEquals("delete implemented: ", 99.66, value, 0.0);
client.close();
assertEquals("The filter registerCall is called only for @Logged services", DELETE, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/header");
Builder builder = target.request().header("my_new_header", "Hi all");
response = builder.get();
calledMethod = response.getHeaderString("calledMethod");
String valueStr = response.readEntity(String.class);
assertEquals("head implemented: ", "Hi all", valueStr);
client.close();
assertNotEquals("The filter registerCall is called only for @Logged services", HEAD, calledMethod);
client = newClient();
target = client.target(url + "services/receiver/headerWithContext");
builder = target.request(TEXT_PLAIN).header("my_new_header", "Hi allll");
response = builder.get();
calledMethod = response.getHeaderString("calledMethod");
valueStr = response.readEntity(String.class);
assertEquals("head implemented: ", "Hi allll", valueStr);
client.close();
assertNotEquals("The filter registerCall is called only for @Logged services", HEAD, calledMethod);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:40,代码来源:OtherTestCase.java
示例10: should_return_unauthorized_headers_without_authorization_header
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
@Ignore // missing MVC template injection
public void should_return_unauthorized_headers_without_authorization_header() {
Response response = target(path).request().get();
int status = response.getStatus();
String wwwHeader = response.getHeaderString(HttpHeaders.WWW_AUTHENTICATE);
assertEquals(UNAUTHORIZED.getStatusCode(), status);
assertEquals("Basic realm=\"Mon application\"", wwwHeader);
}
示例11: timeoutWith42
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void timeoutWith42() {
JsonObject input = Json.createObjectBuilder().
add("a", 40).
add("b", 2).
build();
Response response = this.tut.
request(MediaType.APPLICATION_JSON).
post(json(input));
assertThat(response.getStatus(), is(503));
String reason = response.getHeaderString("reason");
assertThat(reason, containsString("lazy"));
}
示例12: testCreateUser
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/** Tests the create user function. */
@Test
public void testCreateUser() throws Exception {
// Test1: Add user.
String loginAuthHeader =
"Bearer "
+ new JWTVerifier()
.createJWT("unauthenticated", new HashSet<String>(Arrays.asList("login")));
User user1 =
new User(
null, "Isaac", "Newton", "inewton", "@inewton", "inewtonWishListLink", "mypassword");
Response response = processRequest(userServiceURL, "POST", user1.getJson(), loginAuthHeader);
assertEquals(
"HTTP response code should have been " + Status.OK.getStatusCode() + ".",
Status.OK.getStatusCode(),
response.getStatus());
String authHeader = response.getHeaderString("Authorization");
new JWTVerifier().validateJWT(authHeader);
JsonObject responseJson = toJsonObj(response.readEntity(String.class));
String dbId = responseJson.getString(KEY_USER_ID);
user1.setId(dbId);
// Validate user.
BasicDBObject dbUser =
(BasicDBObject) database.getCollection("users").findOne(new ObjectId(dbId));
assertTrue("User inewton was NOT found in database.", dbUser != null);
assertTrue("User inewton does not contain expected data.", user1.isEqual(dbUser));
// Test2: Try adding another user with the same userName. This should fail.
User user2 =
new User(
null,
"Ivan",
"Newton",
"inewton",
"@ivannewton",
"ivannewtonWishListLink",
"myPassword");
response = processRequest(userServiceURL, "POST", user2.getJson(), loginAuthHeader);
assertEquals(
"HTTP response code should have been " + Status.BAD_REQUEST.getStatusCode() + ".",
Status.BAD_REQUEST.getStatusCode(),
response.getStatus());
}
示例13: testGetVersionedLdprs
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testGetVersionedLdprs() {
when(mockResource.isMemento()).thenReturn(true);
when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(TEXT_TURTLE_TYPE));
final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
mockIoService, mockBinaryService, null);
final Response res = getHandler.getRepresentation(mockResource).build();
assertEquals(OK, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertNull(res.getHeaderString(ACCEPT_POST));
assertNull(res.getHeaderString(ACCEPT_PATCH));
assertNull(res.getHeaderString(PREFERENCE_APPLIED));
assertNull(res.getHeaderString(ACCEPT_RANGES));
assertTrue(TEXT_TURTLE_TYPE.isCompatible(res.getMediaType()));
assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE));
assertEquals(from(time), res.getLastModified());
assertEquals(ofInstant(time, UTC).format(RFC_1123_DATE_TIME), res.getHeaderString(MEMENTO_DATETIME));
final String allow = res.getHeaderString(ALLOW);
assertTrue(allow.contains(GET));
assertTrue(allow.contains(HEAD));
assertTrue(allow.contains(OPTIONS));
assertFalse(allow.contains(PUT));
assertFalse(allow.contains(DELETE));
assertFalse(allow.contains(PATCH));
assertFalse(allow.contains(POST));
final EntityTag etag = res.getEntityTag();
assertTrue(etag.isWeak());
assertEquals(md5Hex(time + baseUrl), etag.getValue());
final List<Object> varies = res.getHeaders().get(VARY);
assertFalse(varies.contains(RANGE));
assertFalse(varies.contains(WANT_DIGEST));
assertFalse(varies.contains(ACCEPT_DATETIME));
assertTrue(varies.contains(PREFER));
}
示例14: testGetLdpc
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Test
public void testGetLdpc() {
when(mockResource.getInteractionModel()).thenReturn(LDP.Container);
when(mockHeaders.getAcceptableMediaTypes()).thenReturn(singletonList(
MediaType.valueOf(APPLICATION_LD_JSON + "; profile=\"" + compacted.getIRIString() + "\"")));
final GetHandler getHandler = new GetHandler(mockLdpRequest, mockResourceService,
mockIoService, mockBinaryService, null);
final Response res = getHandler.getRepresentation(mockResource).build();
assertEquals(OK, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertEquals(APPLICATION_SPARQL_UPDATE, res.getHeaderString(ACCEPT_PATCH));
assertNull(res.getHeaderString(PREFERENCE_APPLIED));
assertNull(res.getHeaderString(ACCEPT_RANGES));
assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()));
assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE));
assertEquals(from(time), res.getLastModified());
assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("describes")));
assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("describedby")));
assertFalse(res.getLinks().stream().anyMatch(link -> link.getRel().equals("canonical")));
final String acceptPost = res.getHeaderString(ACCEPT_POST);
assertNotNull(acceptPost);
assertTrue(acceptPost.contains("text/turtle"));
assertTrue(acceptPost.contains(APPLICATION_LD_JSON));
assertTrue(acceptPost.contains(APPLICATION_N_TRIPLES));
final String allow = res.getHeaderString(ALLOW);
assertTrue(allow.contains(GET));
assertTrue(allow.contains(HEAD));
assertTrue(allow.contains(OPTIONS));
assertTrue(allow.contains(PUT));
assertTrue(allow.contains(DELETE));
assertTrue(allow.contains(PATCH));
assertTrue(allow.contains(POST));
final EntityTag etag = res.getEntityTag();
assertTrue(etag.isWeak());
assertEquals(md5Hex(time + baseUrl), etag.getValue());
final List<Object> varies = res.getHeaders().get(VARY);
assertFalse(varies.contains(RANGE));
assertFalse(varies.contains(WANT_DIGEST));
assertTrue(varies.contains(ACCEPT_DATETIME));
assertTrue(varies.contains(PREFER));
}
示例15: createModel
import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
* createModel - create a task within the current model
* @param model - the model to be created
* @throws OEClientException - an error has occurred contacting the server
*/
public void createModel(Model model) throws OEClientException {
logger.info("createModel entry: {}", model.getLabel());
String url = getApiURL() + "/sys/sys:Model/rdf:instance";
logger.info("createModel URL: {}", url);
Invocation.Builder invocationBuilder = getInvocationBuilder(url);
JsonObject modelObject = new JsonObject();
JsonArray modelTypeList = new JsonArray();
modelTypeList.add("sys:Model");
modelObject.put("@type", modelTypeList);
JsonObject labelObject = new JsonObject();
labelObject.put("@value", model.getLabel().getValue());
labelObject.put("@language", model.getLabel().getLanguageCode());
modelObject.put("rdfs:label", labelObject);
JsonArray defaultNamespaceList = new JsonArray();
defaultNamespaceList.add(model.getDefaultNamespace());
modelObject.put("swa:defaultNamespace", defaultNamespaceList);
modelObject.put("rdfs:comment", model.getComment());
String modelPayload = modelObject.toString();
Date startDate = new Date();
logger.info("createModel making call : {} {}", modelPayload, startDate.getTime());
Response response = invocationBuilder.post(Entity.entity(modelPayload, "application/ld+json"));
logger.info("createModel call complete: {}", startDate.getTime());
/*
* Possible response codes are: - 201 in case of success - 409 in case
* of constraint violation (if e. g. concept scheme already exists)
*/
int status = response.getStatus();
logger.info("createModel response status: {}", status);
if (status != 201) {
throw new OEClientException("Status: %d return creating model at URL: %s. \n%s", status, url, response.readEntity(String.class));
}
String modelUri = response.getHeaderString("X-Location-Uri");
logger.info("model URI: {}", modelUri);
model.setUri(modelUri);
if (logger.isDebugEnabled()) {
logger.debug("createModel response: {}", status);
}
}