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


Java HttpHeaders.getRequestHeader方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.HttpHeaders.getRequestHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.getRequestHeader方法的具體用法?Java HttpHeaders.getRequestHeader怎麽用?Java HttpHeaders.getRequestHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.getRequestHeader方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUsername

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
public static String getUsername(HttpHeaders headers) {
    List<String> authorizationHeader = headers.getRequestHeader("Authorization");

    if (authorizationHeader == null || authorizationHeader.size() == 0) {
        throw new IllegalArgumentException("Basic authorization is not set");
    }

    String authString = authorizationHeader.get(0);
    // Get encoded username and password
    final String encodedUserPassword = authString.replaceFirst("Basic ", "");

    // Decode username and password
    String usernameAndPassword = new String(Base64.getDecoder().decode(encodedUserPassword));

    // Split username and password tokens
    final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
    return tokenizer.nextToken();
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:19,代碼來源:OscAuthFilter.java

示例2: getAuthorizationToken

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
/**
 * Returns the token (as a String), if it exists, otherwise returns null.
 *
 * @param headers the HttpHeader to inspect to find Authorization Bearer header
 * @return the token if found, otherwise null
 * @since 1.0.0
 */
private String getAuthorizationToken(HttpHeaders headers) {
    final List<String> header = headers.getRequestHeader("Authorization");
    if (header != null) {
        final String bearer = header.get(0);
        if (bearer != null) {
            return bearer.substring("Bearer ".length());
        }
    }
    return null;
}
 
開發者ID:stevespringett,項目名稱:Alpine,代碼行數:18,代碼來源:JwtAuthenticationService.java

示例3: modelUpload

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
@PUT
   @Produces(MediaType.APPLICATION_JSON)
   @Path("model/{bucketKey}/object")
   public Response modelUpload(
    	@Context HttpServletRequest request,
   	@PathParam("bucketKey") String bucketKey,
   	@QueryParam("objectKey") String objectKey,
   	@Context HttpHeaders headers,
    	InputStream is
) 
	throws IOException, 
	       URISyntaxException,
	       GeneralSecurityException 
   {
   	APIImpl impl = getAPIImpl( request );
   	if( impl == null )
   	{
           return Response.status( Response.Status.UNAUTHORIZED ).build();     
   	}
   	
   	List<String> value = headers.getRequestHeader( HttpHeaders.CONTENT_LENGTH );
   	String data = value.get( 0 );
   	long length = Long.parseLong( data );

   	Result result = impl.objectUploadStream( bucketKey, objectKey, is, length, null );
   	return formatReturn( result );
   }
 
開發者ID:IBM,項目名稱:MaximoForgeViewerPlugin,代碼行數:28,代碼來源:ForgeRS.java

示例4: getId

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
private String getId( HttpHeaders headers) {
	// get the email we set in AuthenticationFilter
	List<String> id = headers.getRequestHeader( AuthenticationFilter.HEADER_PROPERTY_ID );
	
	if( id == null || id.size() != 1 )
		throw new NotAuthorizedException("Unauthorized!");
	
	return id.get(0);
}
 
開發者ID:maltesander,項目名稱:rest-jersey2-json-jwt-authentication,代碼行數:10,代碼來源:UserRestService.java

示例5: batchRequest

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
/**
 * バッチリクエストを処理する.
 * @param uriInfo uriInfo
 * @param headers headers
 * @param request request
 * @param reader reader
 * @return レスポンス
 */
@WriteAPI
@POST
public Response batchRequest(
        @Context UriInfo uriInfo,
        @Context HttpHeaders headers,
        @Context Request request,
        Reader reader) {

    long startTime = System.currentTimeMillis();
    // タイムアウト時間 (personium-unit-config.properties io.personium.core.odata.batch.timeoutInSecで設定. 単位は秒)
    long batchTimeoutInSec = PersoniumUnitConfig.getOdataBatchRequestTimeoutInMillis();

    // Lockを他プロセスに譲るためにスリープするか否かの拡張ヘッダの値を取得する
    BatchPriority priority = BatchPriority.LOW;
    List<String> priorityHeaders = headers.getRequestHeader(X_PERSONIUM_PRIORITY);
    if (priorityHeaders != null) {
        priority = BatchPriority.fromString(priorityHeaders.get(0));
    }

    timer = new BatchElapsedTimer(startTime, batchTimeoutInSec, priority);

    checkAccessContext(this.odataResource.getAccessContext());

    // TODO 不正なコンテントタイプが指定された場合エラーを返卻する
    String boundary = headers.getMediaType().getParameters().get("boundary");

    // リクエストボディのパース
    BatchBodyParser parser = new BatchBodyParser();
    List<BatchBodyPart> bodyParts = parser.parse(boundary, reader, uriInfo.getRequestUri().toString());
    if (bodyParts == null || bodyParts.size() == 0) {
        // パース処理失敗
        throw PersoniumCoreException.OData.BATCH_BODY_PARSE_ERROR;
    }
    if (bodyParts.size() > Integer.parseInt(PersoniumUnitConfig.getOdataBatchBulkRequestMaxSize())) {
        // $Batchで指定されたリクエスト數が不正
        throw PersoniumCoreException.OData.TOO_MANY_REQUESTS.params(bodyParts.size());
    }

    UserDataODataProducer producer = (UserDataODataProducer) this.odataResource.getODataProducer();
    entityTypeIds = producer.getEntityTypeIds();

    List<NavigationPropertyBulkContext> npBulkContexts = new ArrayList<NavigationPropertyBulkContext>();

    StringBuilder responseBody = new StringBuilder();

    // 1件ずつリクエストを実行
    for (BatchBodyPart bodyPart : bodyParts) {
        executePartRequest(responseBody, uriInfo, boundary, npBulkContexts, bodyPart);
    }

    // POSTのbulk実行
    checkAndExecBulk(responseBody, uriInfo, boundary, npBulkContexts);

    // バウンダリ終端文字列
    responseBody.append("--" + boundary + "--");

    // レスポンス作成
    String contentType = ODataBatchProvider.MULTIPART_MIXED + "; boundary=" + boundary;
    return Response.status(HttpStatus.SC_ACCEPTED)
            .header(HttpHeaders.CONTENT_TYPE, contentType)
            .header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataVersion.V2.asString)
            .entity(responseBody.toString())
            .build();
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:73,代碼來源:ODataBatchResource.java

示例6: updateBinary

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
Response updateBinary(final byte[] message, final HttpHeaders headers,
    final boolean replace) {
  servlet.getMetrics().incrementRequests(1);
  if (servlet.isReadOnly()) {
    servlet.getMetrics().incrementFailedPutRequests(1);
    return Response.status(Response.Status.FORBIDDEN)
      .type(MIMETYPE_TEXT).entity("Forbidden" + CRLF)
      .build();
  }
  Table table = null;
  try {
    byte[] row = rowspec.getRow();
    byte[][] columns = rowspec.getColumns();
    byte[] column = null;
    if (columns != null) {
      column = columns[0];
    }
    long timestamp = HConstants.LATEST_TIMESTAMP;
    List<String> vals = headers.getRequestHeader("X-Row");
    if (vals != null && !vals.isEmpty()) {
      row = Bytes.toBytes(vals.get(0));
    }
    vals = headers.getRequestHeader("X-Column");
    if (vals != null && !vals.isEmpty()) {
      column = Bytes.toBytes(vals.get(0));
    }
    vals = headers.getRequestHeader("X-Timestamp");
    if (vals != null && !vals.isEmpty()) {
      timestamp = Long.valueOf(vals.get(0));
    }
    if (column == null) {
      servlet.getMetrics().incrementFailedPutRequests(1);
      return Response.status(Response.Status.BAD_REQUEST)
          .type(MIMETYPE_TEXT).entity("Bad request: Column found to be null." + CRLF)
          .build();
    }
    Put put = new Put(row);
    byte parts[][] = KeyValue.parseColumn(column);
    if (parts.length != 2) {
      return Response.status(Response.Status.BAD_REQUEST)
        .type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
        .build();
    }
    put.addImmutable(parts[0], parts[1], timestamp, message);
    table = servlet.getTable(tableResource.getName());
    table.put(put);
    if (LOG.isDebugEnabled()) {
      LOG.debug("PUT " + put.toString());
    }
    servlet.getMetrics().incrementSucessfulPutRequests(1);
    return Response.ok().build();
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedPutRequests(1);
    return processException(e);
  } finally {
    if (table != null) try {
      table.close();
    } catch (IOException ioe) {
      LOG.debug(ioe);
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:63,代碼來源:RowResource.java

示例7: getFirstHeader

import javax.ws.rs.core.HttpHeaders; //導入方法依賴的package包/類
/**
 * ヘッダ情報から指定されたキーのヘッダを取得する. <br />
 * 存在しない場合はnullを返卻する.
 * @param headers ヘッダ情報
 * @param key 取得するヘッダのキー
 * @param defaultValue ヘッダが存在しない場合のデフォルト値
 * @return 指定されたキーのヘッダ
 */
private String getFirstHeader(HttpHeaders headers, String key, String defaultValue) {
    List<String> header = headers.getRequestHeader(key);
    if (header != null && header.size() > 0) {
        return header.get(0);
    }
    return defaultValue;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:16,代碼來源:DavMoveResource.java


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