當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:22,代碼來源:MoveFileTest.java

示例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");
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:26,代碼來源:UpdateTest.java

示例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())));
}
 
開發者ID:hantsy,項目名稱:javaee8-jaxrs-sample,代碼行數:18,代碼來源:PostResourceIT.java

示例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();
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:20,代碼來源:BoxCrudTest.java

示例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);
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:25,代碼來源:BarInstallTest.java

示例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;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:23,代碼來源:AbstractCase.java

示例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());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:27,代碼來源:ComplexTypePropertyValidateDefaultValueTest.java

示例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());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:28,代碼來源:PropertyCreateValidateTest.java

示例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;
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:17,代碼來源:AbstractRequestHandlerTest.java

示例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);
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:29,代碼來源:MoveCollectionTest.java

示例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;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:43,代碼來源:PropertyUtils.java

示例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));
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:28,代碼來源:ApacheHttpRequestFactory.java

示例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);
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:19,代碼來源:ComplexTypePropertyListTest.java

示例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);
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:22,代碼來源:MoveCollectionTest.java

示例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;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:28,代碼來源:AbstractCase.java


注:本文中的org.apache.http.HttpHeaders類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。