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


Java ContainerResponse類代碼示例

本文整理匯總了Java中com.sun.jersey.spi.container.ContainerResponse的典型用法代碼示例。如果您正苦於以下問題:Java ContainerResponse類的具體用法?Java ContainerResponse怎麽用?Java ContainerResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ContainerResponse類屬於com.sun.jersey.spi.container包,在下文中一共展示了ContainerResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addResponseHeaders

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
/**
 * 全てのレスポンスに共通するレスポンスヘッダーを追加する.
 * Access-Control-Allow-Origin, Access-Control-Allow-Headers<br/>
 * X-Personium-Version<br/>
 * @param request
 * @param response
 */
private void addResponseHeaders(final ContainerRequest request, final ContainerResponse response) {
    MultivaluedMap<String, Object> mm = response.getHttpHeaders();
    String acrh = request.getHeaderValue(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS);
    if (acrh != null) {
        mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, acrh);
    } else {
        mm.remove(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS);
    }
    mm.putSingle(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, HttpHeaders.Value.ASTERISK);
    // X-Personium-Version
    mm.putSingle(HttpHeaders.X_PERSONIUM_VERSION, PersoniumUnitConfig.getCoreVersion());
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:20,代碼來源:PersoniumCoreContainerFilter.java

示例2: testFilterContainerRequestContainerResponse

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
/**
 * filter(ContainerRequest req, ContainerResponse res): ContainerResponseのテスト.
 * レスポンスフィルタとしてログ出力をしていることを確認。
 */
@Ignore
@Test
public void testFilterContainerRequestContainerResponse() {
    // 被テストオブジェクトを準備
    PersoniumCoreContainerFilter containerFilter = new PersoniumCoreContainerFilter();
    // ContainerRequiestモックを準備
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    HttpServletRequest mockServletRequest = mock(HttpServletRequest.class);
    when(mockServletRequest.getAttribute("requestTime")).thenReturn(System.currentTimeMillis());
    containerFilter.setHttpServletRequest(mockServletRequest);

    // ContainerResponseモックを準備
    ContainerResponse mockResponse = mock(ContainerResponse.class);
    when(mockResponse.getStatus()).thenReturn(HttpStatus.SC_OK);

    // 被テスト処理の実行
    ContainerResponse filteredResponse = containerFilter.filter(mockRequest, mockResponse);

    // 結果の検証。
    // ログ出力するだけなので、非Nullであることのみ検査.
    assertNotNull(filteredResponse);
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:27,代碼來源:PersoniumCoreContainerFilterTest.java

示例3: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    if (response.getStatusType().getFamily() == Response.Status.Family.SERVER_ERROR) {
        switch (response.getStatus()) {
            case 500:
                _meter500.mark();
                break;
            case 503:
                _meter503.mark();
                break;
            default:
                _meterOther.mark();
                break;
        }
    }
    return response;
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:18,代碼來源:ServerErrorResponseMetricsFilter.java

示例4: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
/**
 * Extracts the client ID from the query parameter named {@link LongPollingServlet#CLIENT_ID} and subscribes
 * for updates when the data changes in any of the masters in {@link #_masterTypes}.
 * @param request The request
 * @param response The response
 * @return The unmodified response
 */
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
  // TODO check response status
  String clientId = FilterUtils.getClientId(request, _httpContext);
  // don't subscribe if there's no client ID
  if (clientId == null) {
    return response;
  }
  String userId = (AuthUtils.isPermissive() ? null : FilterUtils.getUserId(_httpContext));
  String url = _servletRequest.getRequestURI();
  // TODO should we only subscribe if there were query params, i.e. it was a search request, not just a request for the search page
  for (MasterType masterType : _masterTypes) {
    _updateManager.subscribe(userId, clientId, masterType, url);
  }
  return response;
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:24,代碼來源:MasterSubscriptionFilter.java

示例5: decorateWithGlobalMessages

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
public void decorateWithGlobalMessages(ContainerResponse response, AddonsManager addonsManager,
        StorageService storageService,AuthorizationService authenticationService) {
    try {
        boolean admin=authenticationService.isAdmin();
        boolean notAnonymous = !authenticationService.isAnonymous();
        // Try to update the cache if needed
        triggerCacheUpdateProcessIfNeeded(addonsManager, storageService);
        // update response header with message in cache
        ObjectMapper mapper = new ObjectMapper();
        Predicate<FooterMessage> predicate = p -> isVisible(p.getVisibility(), admin, notAnonymous);
        List<FooterMessage> collect = cache.stream().filter(predicate).collect(Collectors.toList());
        String json = mapper.writeValueAsString(collect);
        response.getResponse().getMetadata().add("Artifactory-UI-messages", json);
    } catch (Exception e) {
        log.error("Fail to attache global message to response header", e);
    }
}
 
開發者ID:alancnet,項目名稱:artifactory,代碼行數:18,代碼來源:GlobalMessageProvider.java

示例6: getDate

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
/**
 * Get the {@link com.google.common.net.HttpHeaders#DATE} HTTP header.
 *
 * @return date header value or absent if the header is not set or the value is invalid
 */
public Optional<DateTime> getDate() {
    if (_date == null) {
        Object headerValue = _httpContext.getHttpHeaders().getFirst(DATE);

        _date = Optional.absent();

        if (headerValue != null) {
            try {
                _date = Optional.of(HttpHeaderUtils.parseDate(ContainerResponse.getHeaderValue(headerValue)));
            } catch (Exception ex) {
                LOG.debug("Error parsing date header: value={}", headerValue, ex);
            }
        }
    }

    return _date;
}
 
開發者ID:bazaarvoice,項目名稱:dropwizard-caching-bundle,代碼行數:23,代碼來源:CacheResponseContext.java

示例7: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {

  Collection<Object> contentTypes = response.getHttpHeaders().get("Content-Type");
  //LOGGER.debug("content types {}", contentTypes);
  if (null != contentTypes) {
    for (Object contentType : contentTypes) {
      if (contentType.equals(APPLICATION_X_PROTOBUF_TYPE) && !shouldSkipWrapping(response.getEntity())) {
        LOGGER.debug("Content type is x-protobuf, wrap response entity");
        ResponseCodeEntityWrapper<Object> wrapper = new ResponseCodeEntityWrapper<>(response.getStatus(), response.getEntity());
        response.setEntity(wrapper, response.getEntityType());
        break;
      }
    }

  }

  return response;
}
 
開發者ID:Wadpam,項目名稱:guja,代碼行數:20,代碼來源:ProtoWrapperResponseFilter.java

示例8: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
{
	if (!isCorsNeeded(request))
		return response;

	MultivaluedMap<String, Object> headers = response.getHttpHeaders();

	headers.add("Access-Control-Allow-Origin", "*");
	headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS");

	String acrh = request.getHeaderValue("Access-Control-Request-Headers");
	if (acrh != null && !acrh.isEmpty())
		headers.add("Access-Control-Allow-Headers", acrh);

	return response;
}
 
開發者ID:zach-m,項目名稱:gae-jersey-guice-jsf,代碼行數:18,代碼來源:CorsFilter.java

示例9: commonLogLine

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
private String commonLogLine(ContainerRequest request, ContainerResponse response) {
	// 127.0.0.1 user-identifier frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
	return MessageFormat.format(//
			"{0} {1} {2} [{3}] \"{4} /{5} {6}\" {7} {8}", //
			"?", //
			// req.getRemoteAddr(),//
			"-", //
			"?", //
			// req.getRemoteUser(),//
			new DateTime().toString("dd/MMM/yyyy:HH:mm:ss ZZ"), //
			request.getMethod(), //
			request.getPath(), //
			"?", //
			// req.getProtocol(),//
			response.getStatus(), //
			"?"//
	);
}
 
開發者ID:HuygensING,項目名稱:elaborate4-backend,代碼行數:19,代碼來源:LoggingResourceFilter.java

示例10: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest req,
		ContainerResponse contResp) {

	//String method = req.getMethod();
	
	ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
	
	resp.header("Access-Control-Allow-Origin", "*");
	resp.header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, x-requested-with");
	resp.header("Access-Control-Allow-Credentials", "true");
	resp.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
	resp.header("Access-Control-Max-Age", "1209600");

	contResp.setResponse(resp.build());
	return contResp;
}
 
開發者ID:GLORIA-project,項目名稱:gloria-core,代碼行數:18,代碼來源:ResponseCorsFilter.java

示例11: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest req,
		ContainerResponse contResp) {

	ResponseBuilder resp = Response.fromResponse(contResp.getResponse());
	resp.header("Access-Control-Allow-Origin", "*").header(
			"Access-Control-Allow-Methods", "GET, POST, OPTIONS");

	String reqHead = req.getHeaderValue("Access-Control-Request-Headers");

	if (null != reqHead && !reqHead.equals(null)) {
		resp.header("Access-Control-Allow-Headers", reqHead);
	}

	contResp.setResponse(resp.build());
	return contResp;
}
 
開發者ID:srdc,項目名稱:semanticMDR,代碼行數:18,代碼來源:ResponseCorsFilter.java

示例12: addRequestIdToResponse

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
/**
 * Private helper that adds the request-id to the response payload.
 * @param response
 */
private void addRequestIdToResponse(ContainerResponse response) {
	
	// The request-id to be injected in the response
	String requestId = StaashRequestContext.getRequestId();
	
	// The key response attributes
	int status = response.getStatus();
	MediaType mediaType = response.getMediaType();
	
	if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
		
		String message = (String)response.getEntity();
		JsonObject json = new JsonObject(message);
		json.putString("request-id", requestId);
		
		Response newJerseyResponse = Response.status(status).type(mediaType).entity(json.toString()).build();
		response.setResponse(newJerseyResponse);
	}
		
	// Add the request id to the response regardless of the media type, 
	// this allows non json responses to have a request id in the response
	response.getHttpHeaders().add("x-nflx-staash-request-id", requestId);
}
 
開發者ID:Netflix,項目名稱:staash,代碼行數:28,代碼來源:StaashAuditFilter.java

示例13: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    Integer status = response.getStatus();

    Counter counter = counters.get(status);
    if (counter == null) {
        // despite the method name, this actually will return a previously created metric with the same name
        Counter newCounter = metricsRegistry.counter(
            MetricRegistry.name(resourceClass, metricBaseName + " " + status + " counter"));
        Counter otherCounter = counters.putIfAbsent(status, newCounter);
        if (otherCounter != null) {
            // we lost the race to set that counter, but shouldn't create a duplicate since Metrics.newCounter will do the right thing
            counter = otherCounter;
        } else {
            counter = newCounter;
        }
    }

    counter.inc();

    return response;
}
 
開發者ID:palominolabs,項目名稱:jersey-metrics-filter,代碼行數:23,代碼來源:HttpStatusCodeCounterResourceFilter.java

示例14: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
    if (incomingOrigin == null) {
        return response;
    }

    MultivaluedMap<String, Object> h = response.getHttpHeaders();
    putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
    putIfNotPresent(h, CorsHeaders.MAX_AGE, Integer.toString(maxAge));
    if (!allowMethods.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.ALLOW_METHODS, allowMethods);
    }
    if (!allowHeaders.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.ALLOW_HEADERS, allowHeaders);
    }
    if (allowCredentials) {
        putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
    }
    return response;
}
 
開發者ID:palominolabs,項目名稱:jersey-cors-filter,代碼行數:22,代碼來源:CorsPreflightResponseResourceFilter.java

示例15: filter

import com.sun.jersey.spi.container.ContainerResponse; //導入依賴的package包/類
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    String incomingOrigin = request.getHeaderValue(CorsHeaders.ORIGIN);
    if (incomingOrigin == null) {
        return response;
    }

    MultivaluedMap<String, Object> h = response.getHttpHeaders();
    putIfNotPresent(h, CorsHeaders.ALLOW_ORIGIN, allowOrigin);
    if (!exposeHeaders.isEmpty()) {
        putIfNotPresent(h, CorsHeaders.EXPOSE_HEADERS, exposeHeaders);
    }
    if (allowCredentials) {
        putIfNotPresent(h, CorsHeaders.ALLOW_CREDENTIALS, Boolean.toString(allowCredentials));
    }
    return response;
}
 
開發者ID:palominolabs,項目名稱:jersey-cors-filter,代碼行數:18,代碼來源:CorsResourceResponseResourceFilter.java


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