本文整理汇总了Java中org.apache.http.HttpHeaders类的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders类的具体用法?Java HttpHeaders怎么用?Java HttpHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpHeaders类属于org.apache.http包,在下文中一共展示了HttpHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertThat
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* MOVEで移動元がユーザスキーマで上位リソースであるコレクションが存在しない場合に404エラーとなること.
*/
@Test
public final void MOVEで移動元がユーザスキーマで上位リソースであるコレクションが存在しない場合に404エラーとなること() {
final String destination = UrlUtils.box(CELL_NAME, BOX_NAME, FILE_NAME);
try {
// Fileの移動
String url = UrlUtils.entityType(CELL_NAME, BOX_NAME, "dummyCollection", "entity");
PersoniumRequest req = PersoniumRequest.move(url);
req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
req.header(HttpHeaders.DESTINATION, destination);
// リクエスト実行
PersoniumResponse response = AbstractCase.request(req);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_NOT_FOUND);
} finally {
DavResourceUtils.deleteWebDavFile(CELL_NAME, TOKEN, BOX_NAME, FILE_NAME);
}
}
示例2: JSONObject
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* Cellの更新のNameが__の場合に400が返却されること.
*/
@SuppressWarnings("unchecked")
@Test
public final void Cellの更新のNameが__の場合に400が返却されること() {
// Cellを更新
// リクエストヘッダをセット
HashMap<String, String> headers = new HashMap<String, String>();
headers.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
headers.put(HttpHeaders.IF_MATCH, "*");
// リクエストボディを生成
JSONObject requestBody = new JSONObject();
requestBody.put("Name", "__");
res = updateCell(headers, requestBody);
// Cell更新のレスポンスチェック
assertEquals(HttpStatus.SC_BAD_REQUEST, res.getStatusCode());
assertEquals(MediaType.APPLICATION_JSON, res.getResponseHeaders(HttpHeaders.CONTENT_TYPE)[0].getValue());
this.checkErrorResponse(res.bodyAsJson(), "PR400-OD-0006");
}
示例3: setup
import org.apache.http.HttpHeaders; //导入依赖的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())));
}
示例4: request
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* BOX新規登録時にNameを1文字指定して場合_201になることを確認.
*/
@Test
public void BOX新規登録時にNameを1文字指定して場合_201になることを確認() {
PersoniumRequest req = PersoniumRequest.post(UrlUtils.cellCtl(CELL_NAME, ENTITY_TYPE_BOX));
String boxName = "1";
String[] key = {"Name", "Schema" };
String[] value = {boxName, TEST_BOX_SCHEMA };
req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody(key, value);
try {
PersoniumResponse res = request(req);
// 201になることを確認
assertEquals(HttpStatus.SC_CREATED, res.getStatusCode());
} finally {
deleteBoxRequest(boxName).returns();
}
}
示例5: File
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* relation_jsonの必須項目がない場合に異常終了すること.
*/
@Test
public final void relation_jsonの必須項目がない場合に異常終了すること() {
String reqCell = Setup.TEST_CELL1;
String reqPath = INSTALL_TARGET;
TResponse res = null;
File barFile = new File(RESOURCE_PATH + BAR_FILE_RELATION_NONAME);
byte[] body = BarInstallTestUtils.readBarFile(barFile);
Map<String, String> headers = new LinkedHashMap<String, String>();
headers.put(HttpHeaders.CONTENT_TYPE, REQ_CONTENT_TYPE);
headers.put(HttpHeaders.CONTENT_LENGTH, String.valueOf(body.length));
res = BarInstallTestUtils.request(REQUEST_NORM_FILE, reqCell, reqPath, headers, body);
res.statusCode(HttpStatus.SC_ACCEPTED);
String location = res.getHeader(HttpHeaders.LOCATION);
String expected = UrlUtils.cellRoot(reqCell) + reqPath;
assertEquals(expected, location);
BarInstallTestUtils.assertBarInstallStatus(location, SCHEMA_URL, ProgressInfo.STATUS.FAILED);
}
示例6: restPut
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* URLを指定してPUTを行う汎用メンバ.
* @param url リクエスト先のURL
* @param data リクエストデータ
* @return レスポンスオブジェクト
*/
public final PersoniumResponse restPut(final String url, final String data) {
PersoniumRestAdapter rest = new PersoniumRestAdapter();
PersoniumResponse res = null;
// リクエストヘッダをセット
HashMap<String, String> requestheaders = new HashMap<String, String>();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
try {
// リクエスト
res = rest.put(url, requestheaders, new ByteArrayInputStream(data.getBytes()));
} catch (Exception e) {
fail(e.getMessage());
}
return res;
}
示例7: request
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* ComplexTypePropertyTypeのEdmDoubleでDefaultValueが負のDouble最大値を下回る場合_BadRequestが返却されること.
*/
@Test
public final void ComplexTypePropertyTypeのEdmDoubleでDefaultValueが負のDouble最大値を下回る場合_BadRequestが返却されること() {
// リクエストパラメータ設定
PersoniumRequest req = PersoniumRequest.post(ComplexTypePropertyUtils.CTP_REQUEST_URL);
req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_NAME_KEY, CT_PROPERTY_NAME);
req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_COMPLEXTYPE_NAME_KEY, COMPLEX_TYPE_NAME);
req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_TYPE_KEY,
EdmSimpleType.DOUBLE.getFullyQualifiedTypeName());
req.addJsonBody(ComplexTypePropertyUtils.CT_PROPERTY_DEFAULT_VALUE_KEY, -2.229e-308);
// リクエスト実行
PersoniumResponse response = request(req);
// レスポンスチェック
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
checkErrorResponse(
response.bodyAsJson(),
PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.getCode(),
PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(
ComplexTypePropertyUtils.CT_PROPERTY_DEFAULT_VALUE_KEY)
.getMessage());
}
示例8: request
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* PropertyのTypeが不正な値の場合_BadRequestが返却されること.
*/
@Test
public final void PropertyのTypeが不正な値の場合_BadRequestが返却されること() {
// リクエストパラメータ設定
PersoniumRequest req = PersoniumRequest.post(PropertyUtils.REQUEST_URL);
req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
req.addJsonBody(PropertyUtils.PROPERTY_NAME_KEY, propName);
req.addJsonBody(PropertyUtils.PROPERTY_ENTITYTYPE_NAME_KEY, PROPERTY_ENTITYTYPE_NAME);
req.addJsonBody(PropertyUtils.PROPERTY_TYPE_KEY, "Edm.Datetime");
req.addJsonBody(PropertyUtils.PROPERTY_NULLABLE_KEY, null);
req.addJsonBody(PropertyUtils.PROPERTY_DEFAULT_VALUE_KEY, null);
req.addJsonBody(PropertyUtils.PROPERTY_COLLECTION_KIND_KEY, null);
req.addJsonBody(PropertyUtils.PROPERTY_IS_KEY_KEY, null);
req.addJsonBody(PropertyUtils.PROPERTY_UNIQUE_KEY_KEY, null);
// リクエスト実行
PersoniumResponse response = request(req);
// レスポンスチェック
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
checkErrorResponse(response.bodyAsJson(),
PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.getCode(),
PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR.params(
PropertyUtils.PROPERTY_TYPE_KEY).getMessage());
}
示例9: buildHttpRequest
import org.apache.http.HttpHeaders; //导入依赖的package包/类
private HttpRequest buildHttpRequest(UserRequestTest userRequest) throws JsonProcessingException {
String json = new ObjectMapper().writeValueAsString(userRequest);
Map<String, String> headers = new HashMap<>();
headers.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
headers.put(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType());
HttpRequest request = new HttpRequest();
request.setHeaders(headers);
request.setHttpMethod("POST");
request.setResource("users");
request.setPath("/users");
request.setBody(json);
return request;
}
示例10: assertThat
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* WebDAVコレクションのMOVEでDestinationヘッダの値がリクエストURLと同じ場合に403エラーとなること.
*/
@Test
public final void WebDAVコレクションのMOVEでDestinationヘッダの値がリクエストURLと同じ場合に403エラーとなること() {
final String srcCol = "srcCol";
final String destCol = srcCol;
final String destUrl = UrlUtils.box(CELL_NAME, BOX_NAME, destCol);
try {
// 事前準備
DavResourceUtils.createWebDavCollection(TOKEN, HttpStatus.SC_CREATED, CELL_NAME, BOX_NAME, srcCol);
// 移動
String url = UrlUtils.box(CELL_NAME, BOX_NAME, srcCol);
PersoniumRequest req = PersoniumRequest.move(url);
req.header(HttpHeaders.AUTHORIZATION, AbstractCase.BEARER_MASTER_TOKEN);
req.header(HttpHeaders.DESTINATION, destUrl);
PersoniumResponse response = AbstractCase.request(req);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_FORBIDDEN);
PersoniumCoreException expectedException =
PersoniumCoreException.Dav.DESTINATION_EQUALS_SOURCE_URL.params(destUrl);
ODataCommon.checkErrorResponseBody(response, expectedException.getCode(), expectedException.getMessage());
} finally {
DavResourceUtils.deleteCollection(CELL_NAME, BOX_NAME, srcCol, TOKEN, -1);
}
}
示例11: create
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* Propertyを登録する.
* @param token トークン
* @param cell セル名
* @param box ボックス名
* @param collection コレクション名
* @param entityTypeName EntityType名
* @param propertyName Property名
* @param type PropertyのType項目
* @param nullable PropertyのNullable項目
* @param defaultValue PropertyのDefaultValue項目
* @param collectionKind PropertyのcollectionKind項目
* @param isKey PropertyのisKey項目
* @param uniqueKey PropertyのUniqueKey項目
* @param code 期待するレスポンスコード
* @return レスポンス
*/
public static PersoniumResponse create(
String token, String cell, String box, String collection,
String entityTypeName, String propertyName,
String type, boolean nullable, Object defaultValue, String collectionKind,
boolean isKey, String uniqueKey, int code) {
String url = UrlUtils.property(cell, box, collection, null, null);
PersoniumRequest req = PersoniumRequest.post(url);
req.header(HttpHeaders.AUTHORIZATION, token);
req.addJsonBody(PROPERTY_NAME_KEY, propertyName);
req.addJsonBody(PROPERTY_ENTITYTYPE_NAME_KEY, entityTypeName);
req.addJsonBody(PROPERTY_TYPE_KEY, type);
req.addJsonBody(PROPERTY_NULLABLE_KEY, nullable);
req.addJsonBody(PROPERTY_DEFAULT_VALUE_KEY, defaultValue);
req.addJsonBody(PROPERTY_COLLECTION_KIND_KEY, collectionKind);
req.addJsonBody(PROPERTY_IS_KEY_KEY, isKey);
req.addJsonBody(PROPERTY_UNIQUE_KEY_KEY, uniqueKey);
// リクエスト実行
PersoniumResponse response = AbstractCase.request(req);
if (code != -1) {
assertEquals(code, response.getStatusCode());
}
return response;
}
示例12: addHeadersToRequest
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* Configures the headers in the specified Apache HTTP request.
*/
private void addHeadersToRequest(HttpRequestBase httpRequest, SdkHttpFullRequest request) {
httpRequest.addHeader(HttpHeaders.HOST, getHostHeaderValue(request));
// Copy over any other headers already in our request
request.headers().entrySet().stream()
/*
* HttpClient4 fills in the Content-Length header and complains if
* it's already present, so we skip it here. We also skip the Host
* header to avoid sending it twice, which will interfere with some
* signing schemes.
*/
.filter(e -> !IGNORE_HEADERS.contains(e.getKey()))
.forEach(e -> e.getValue().forEach(h -> httpRequest.addHeader(e.getKey(), h)));
/* Set content type and encoding */
if (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null ||
httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE).length == 0) {
httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,
"application/x-www-form-urlencoded; " +
"charset=" + lowerCase(DEFAULT_ENCODING));
}
}
示例13: request
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* ComplexTypePropertyが存在しないとき_一覧取得で0件になること.
*/
@Test
public final void ComplexTypePropertyが存在しないとき_一覧取得で0件になること() {
String ctplocationUrl = UrlUtils.complexTypeProperty(Setup.TEST_CELL1, Setup.TEST_BOX1, Setup.TEST_ODATA, null,
null);
// ComplexTypeProperty取得
PersoniumRequest req = PersoniumRequest.get(ctplocationUrl);
req.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
PersoniumResponse resGet = request(req);
// レスポンスチェック
assertEquals(HttpStatus.SC_OK, resGet.getStatusCode());
checkResponseBodyList(resGet.bodyAsJson(), null, ComplexTypePropertyUtils.NAMESPACE, null);
}
示例14:
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* WebDAVコレクションのMOVEで存在するBoxを指定した場合に400エラーとなること.
*/
@Test
public final void WebDAVコレクションのMOVEで存在するBoxを指定した場合に400エラーとなること() {
final String srcColName = "davColforMOVE";
final String destUrl = UrlUtils.box(CELL_NAME, BOX_NAME);
try {
// 事前準備
DavResourceUtils.createWebDavCollection(TOKEN, HttpStatus.SC_CREATED, CELL_NAME, BOX_NAME, srcColName);
// 移動
TResponse response = DavResourceUtils.moveWebDav(TOKEN, CELL_NAME, BOX_NAME + "/" + srcColName, destUrl,
HttpStatus.SC_BAD_REQUEST);
PersoniumCoreException expectedException = PersoniumCoreException.Dav.INVALID_REQUEST_HEADER.params(
HttpHeaders.DESTINATION, destUrl);
ODataCommon.checkErrorResponseBody(response, expectedException.getCode(), expectedException.getMessage());
} finally {
DavResourceUtils.deleteCollection(CELL_NAME, BOX_NAME, srcColName, TOKEN, -1);
}
}
示例15: createCell
import org.apache.http.HttpHeaders; //导入依赖的package包/类
/**
* Cell作成.
* @param cellName Cell名
* @return Cell作成時のレスポンスオブジェクト
*/
@SuppressWarnings("unchecked")
public final PersoniumResponse createCell(final String cellName) {
PersoniumRestAdapter rest = new PersoniumRestAdapter();
PersoniumResponse res = null;
// リクエストヘッダをセット
HashMap<String, String> requestheaders = new HashMap<String, String>();
requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN);
// リクエストボディを生成
JSONObject requestBody = new JSONObject();
requestBody.put("Name", cellName);
String data = requestBody.toJSONString();
// リクエスト
try {
res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME), data, requestheaders);
} catch (Exception e) {
fail(e.getMessage());
}
return res;
}