本文整理汇总了Java中com.sun.jersey.core.header.InBoundHeaders类的典型用法代码示例。如果您正苦于以下问题:Java InBoundHeaders类的具体用法?Java InBoundHeaders怎么用?Java InBoundHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InBoundHeaders类属于com.sun.jersey.core.header包,在下文中一共展示了InBoundHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRequestHeader
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
/**
* リクエストヘッダーの値をチェックする.
* 現在は、Acceptヘッダーのみ(US-ASCII文字以外かどうか)をチェックする
* @param request フィルター前リクエスト
*/
private void checkRequestHeader(ContainerRequest request) {
// ヘッダーのキー名に全角文字が含まれる場合は、その文字を含めたキー名となるため、実際にはこの指定は無視される。
// Jersey1.10では、Acceptヘッダーのキー名と値にUS-ASCII文字以外が含まれる場合に異常終了するため以下を対処
// (Acceptを含む他のヘッダーにも同様の処理が行われるが、上記理由により動作上は問題ないと判断)
// -キー名に含まれる場合は、その指定を無効(Accept:*/*)とする(Jerseryで組み込み済み)。
// -値に含まれる場合は、400エラーとする。
InBoundHeaders newHeaders = new InBoundHeaders();
MultivaluedMap<String, String> headers = request.getRequestHeaders();
for (String header : headers.keySet()) {
if (header.contains(org.apache.http.HttpHeaders.ACCEPT)
&& !acceptHeaderValueRegex.matcher(header).matches()) {
continue;
} else {
newHeaders.put(header, request.getRequestHeader(header));
}
}
request.setHeaders(newHeaders);
String acceptValue = request.getHeaderValue(org.apache.http.HttpHeaders.ACCEPT);
if (acceptValue != null && !acceptHeaderValueRegex.matcher(acceptValue).matches()) {
PersoniumCoreException exception = PersoniumCoreException.OData.BAD_REQUEST_HEADER_VALUE.params(
org.apache.http.HttpHeaders.ACCEPT, acceptValue);
throw exception;
}
}
示例2: filter
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Override
public ContainerRequest filter(ContainerRequest request) {
MultivaluedMap<String, String> headers = request.getRequestHeaders();
if (headers.containsKey(HttpHeaders.ACCEPT_LANGUAGE)) {
List<String> acceptLanguageValues = headers.remove(HttpHeaders.ACCEPT_LANGUAGE);
for (int i = 0; i < acceptLanguageValues.size(); i++) {
final String acceptLanguageValue = acceptLanguageValues.get(i);
// replace es-419 (invalid) with es_ES (valid, hopefully good enough.)
if (acceptLanguageValue.contains(ES_419)) {
acceptLanguageValues.set(i, acceptLanguageValue.replace(ES_419, ES_ES));
}
}
headers.put(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguageValues);
request.setHeaders((InBoundHeaders) headers);
}
return request;
}
示例3: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
DeleteSchedule cc = new DeleteSchedule(666);
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(TEST_JSON.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(666), c.getId());
assertEquals("testSchedule", c.getName());
assertEquals("some neat description", c.getDescription());
assertEquals(Xplenty.ScheduleStatus.enabled, c.getStatus());
}
示例4: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c).replace("{", "one");
DeleteSchedule cc = new DeleteSchedule(666);
try {
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.RemoveSchedule.name + ": error parsing response object", e.getMessage());
}
}
示例5: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
CloneSchedule cc = new CloneSchedule(666);
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(TEST_JSON.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(666), c.getId());
assertEquals("testSchedule", c.getName());
assertEquals("some neat description", c.getDescription());
assertEquals(Xplenty.ScheduleStatus.enabled, c.getStatus());
}
示例6: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c).replace("{", "one");
CloneSchedule cc = new CloneSchedule(666);
try {
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.CloneSchedule.name + ": error parsing response object", e.getMessage());
}
}
示例7: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws UnsupportedEncodingException, ParseException, JsonProcessingException {
Date now = new Date();
String json = new ObjectMapper().writeValueAsString(ClusterTest.createMockCluster(now));
Cluster c = ci.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(3), c.getId());
assertEquals("my cluster", c.getName());
assertEquals("description", c.getDescription());
assertEquals(ClusterStatus.available, c.getStatus());
assertEquals(new Long(1), c.getOwnerId());
assertEquals(new Integer(2), c.getNodes());
assertEquals(ClusterType.production, c.getType());
assertEquals(new Long(0), c.getRunningJobsCount());
assertTrue(Math.abs(now.getTime() - c.getCreatedAt().getTime()) < 1000); //fractions of second are not serialized
assertTrue(Math.abs(now.getTime() - c.getUpdatedAt().getTime()) < 1000);
assertTrue(Math.abs(now.getTime() - c.getAvailableSince().getTime()) < 1000);
assertTrue(Math.abs(now.getTime() - c.getTerminatedAt().getTime()) < 1000);
assertEquals("https://www.xplenty.com/api/" + Xplenty.Resource.Cluster.format(Long.toString(3)), c.getUrl());
}
示例8: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c);
CreateSchedule cc = new CreateSchedule(c);
c = cc.getResponse(new ClientResponse(Status.CREATED.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(TEST_JSON.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(666), c.getId());
assertEquals("testSchedule", c.getName());
assertEquals("some neat description", c.getDescription());
assertEquals(Xplenty.ScheduleStatus.enabled, c.getStatus());
}
示例9: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c).replace("{", "one");
CreateSchedule cc = new CreateSchedule(c);
try {
c = cc.getResponse(new ClientResponse(Status.CREATED.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.CreateSchedule.name + ": error parsing response object", e.getMessage());
}
}
示例10: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
RunJob lc = new RunJob(JobTest.createMockJob(new Date()));
Job j = JobTest.createMockJob(new Date());
String json = new ObjectMapper().writeValueAsString(j).replace("7", "seven");
try {
j = lc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
fail();
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.RunJob.name + ": error parsing response object", e.getMessage());
}
}
示例11: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c);
UpdateSchedule cc = new UpdateSchedule(c);
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(TEST_JSON.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(666), c.getId());
assertEquals("testSchedule", c.getName());
assertEquals("some neat description", c.getDescription());
assertEquals(Xplenty.ScheduleStatus.enabled, c.getStatus());
}
示例12: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c).replace("{", "one");
UpdateSchedule cc = new UpdateSchedule(c);
try {
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.UpdateSchedule.name + ": error parsing response object", e.getMessage());
}
}
示例13: testValidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testValidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
ScheduleInfo cc = new ScheduleInfo(666);
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(TEST_JSON.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertNotNull(c);
assertEquals(new Long(666), c.getId());
assertEquals("testSchedule", c.getName());
assertEquals("some neat description", c.getDescription());
assertEquals(Xplenty.ScheduleStatus.enabled, c.getStatus());
}
示例14: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
Date now = new Date();
Schedule c = ScheduleTest.createMockSchedule(now);
String json = new ObjectMapper().writeValueAsString(c).replace("{", "one");
ScheduleInfo cc = new ScheduleInfo(666);
try {
c = cc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.Schedule.name + ": error parsing response object", e.getMessage());
}
}
示例15: testInvalidResponseHandling
import com.sun.jersey.core.header.InBoundHeaders; //导入依赖的package包/类
@Test
public void testInvalidResponseHandling() throws JsonProcessingException, UnsupportedEncodingException {
TerminateCluster tc = new TerminateCluster(1L);
Cluster c = ClusterTest.createMockCluster(new Date());
String json = new ObjectMapper().writeValueAsString(c).replace("2", "two");
try {
c = tc.getResponse(new ClientResponse(Status.OK.getStatusCode(),
new InBoundHeaders(),
new ByteArrayInputStream(json.getBytes("UTF-8")),
Client.create().getMessageBodyWorkers()));
assertTrue(false);
} catch (XplentyAPIException e) {
assertEquals(Xplenty.Resource.TerminateCluster.name + ": error parsing response object", e.getMessage());
}
}