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


Java ContainerResponseContext.getEntity方法代碼示例

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


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

示例1: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
		ResourceInfo resourceInfo) {
	MediaType mediaType = responseContext.getMediaType();
	if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
		Object responseData = responseContext.getEntity();
		WrapperResponseEntity jsonResponse;

		if (responseData instanceof WrapperResponseEntity) {
			jsonResponse = (WrapperResponseEntity) responseData;
		} else {
			jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
			jsonResponse.setData(responseData);
		}
		responseContext.setStatus(ResponseCode.OK.getCode());

		responseContext.setEntity(jsonResponse);

	}
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:21,代碼來源:ResponseWrapperHandler.java

示例2: mapResponseLogBean

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
private ResponseLogBean mapResponseLogBean(ContainerResponseContext responseContext) throws IOException {
	ResponseLogBean responseLogBean = new ResponseLogBean();
	responseLogBean.setStatus(responseContext.getStatus());
	Map<String, String> headers = Maps.newHashMap();

	if (responseContext.getEntity() instanceof InputStream) {
		JsonNode responseEntity = objectMapper.readTree((InputStream) responseContext.getEntity());
		responseLogBean.setBody(responseEntity);
		responseContext.setEntity(responseEntity);
	} else {
		responseLogBean.setBody(objectMapper.convertValue(responseContext.getEntity(), JsonNode.class));
	}

	for (Map.Entry<String, List<Object>> header : responseContext.getHeaders().entrySet()) {
		headers.put(header.getKey(), joiner.join(header.getValue()));
	}

	responseLogBean.setHeaders(headers);
	return responseLogBean;
}
 
開發者ID:Mockenize,項目名稱:mockenize-server,代碼行數:21,代碼來源:ResponseLoggingFilter.java

示例3: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
public void filter(ContainerRequestContext requestContext,
		ContainerResponseContext responseContext) throws IOException {
	String method = requestContext.getMethod();

	logger.debug("Requesting " + method + " for path " + requestContext.getUriInfo().getPath());
	Object entity = responseContext.getEntity();
	if (entity != null) {
		logger.debug("Response " + new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(entity));
	}

}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:12,代碼來源:LoggingResponseFilter.java

示例4: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
		throws IOException {
	if(responseContext.getEntityClass() == Template.class) {
		SuspendableContainerResponseContext ctx = (SuspendableContainerResponseContext) responseContext;
		ctx.suspend();
		Template template = (Template) responseContext.getEntity();
		template.render().subscribe(resp -> {
			ctx.setEntity(resp.getEntity());
			ctx.setStatus(resp.getStatus());
			ctx.resume();
		}, err -> ctx.resume(err));
	}
}
 
開發者ID:FroMage,項目名稱:redpipe,代碼行數:15,代碼來源:TemplateResponseFilter.java

示例5: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void processResponse(ContainerRequestContext requestContext,
                            ContainerResponseContext responseContext,
                            ResourceInfo resourceInfo) {
    MediaType mediaType = responseContext.getMediaType();
    if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
        Object responseData = responseContext.getEntity();
        WrapperResponseEntity jsonResponse;

        if (responseData instanceof WrapperResponseEntity) {
            jsonResponse = (WrapperResponseEntity) responseData;
        } else {
            jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
            jsonResponse.setData(responseData);
        }
        responseContext.setStatus(ResponseCode.OK.getCode());

        responseContext.setEntity(jsonResponse);

    }
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:22,代碼來源:ResponseWrapperHandler.java

示例6: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(
		ContainerRequestContext containerRequestContext,
		ContainerResponseContext containerResponseContext)
	throws IOException {

	Object entity = containerResponseContext.getEntity();

	if (entity instanceof Try.Failure) {
		Try.Failure failure = (Try.Failure)entity;

		Exception exception = failure.getException();

		Optional<APIError> optional = _exceptionConverterManager.convert(
			exception);

		APIError apiError = optional.orElseThrow(
			() -> new MustHaveExceptionConverter(exception.getClass()));

		if (_apioLogger != null) {
			_apioLogger.error(apiError);
		}

		ErrorMessageMapper errorMessageMapper =
			_errorMessageMapperManager.getErrorMessageMapper(
				apiError, _httpHeaders);

		String result = ErrorWriter.writeError(
			errorMessageMapper, apiError, _httpHeaders);

		MultivaluedMap<String, Object> headers =
			containerResponseContext.getHeaders();

		headers.remove("Content-Type");
		headers.add("Content-Type", errorMessageMapper.getMediaType());

		containerResponseContext.setEntity(result);
		containerResponseContext.setStatus(apiError.getStatusCode());
	}
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:41,代碼來源:FailureFilter.java

示例7: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
/**
 * Creates JSON API responses for custom JAX-RS actions returning Katharsis resources.
 */
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
	Object response = responseContext.getEntity();
	if (response == null) {
		return;
	}
	
	// only modify responses which contain a single or a list of Katharsis resources
	if (isResourceResponse(response)) {
		KatharsisBoot boot = feature.getBoot();
		ResourceRegistry resourceRegistry = boot.getResourceRegistry();
		DocumentMapper documentMapper = boot.getDocumentMapper();
		
		ServiceUrlProvider serviceUrlProvider = resourceRegistry.getServiceUrlProvider();
		try {
			UriInfo uriInfo = requestContext.getUriInfo();
			if (serviceUrlProvider instanceof UriInfoServiceUrlProvider) {
				((UriInfoServiceUrlProvider) serviceUrlProvider).onRequestStarted(uriInfo);
			}

			JsonApiResponse jsonApiResponse = new JsonApiResponse();
			jsonApiResponse.setEntity(response);
			// use the Katharsis document mapper to create a JSON API response
			responseContext.setEntity(documentMapper.toDocument(jsonApiResponse, null));
			responseContext.getHeaders().put("Content-Type", Arrays.asList((Object)JsonApiMediaType.APPLICATION_JSON_API));
			
		}
		finally {
			if (serviceUrlProvider instanceof UriInfoServiceUrlProvider) {
				((UriInfoServiceUrlProvider) serviceUrlProvider).onRequestFinished();
			}
		}
	}
}
 
開發者ID:katharsis-project,項目名稱:katharsis-framework,代碼行數:38,代碼來源:JsonApiResponseFilter.java

示例8: isBinaryEntity

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
protected boolean isBinaryEntity(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
	Object entity = responseContext.getEntity();
	return entity instanceof byte[]
			|| entity instanceof File
			|| entity instanceof StreamingOutput
			|| entity instanceof InputStream
			|| entity instanceof DataSource;
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:9,代碼來源:GatewayBinaryResponseFilter.java

示例9: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
    if(responseContext.getEntity() instanceof List){
        List<Entity> filteredEntities = AuthorizationFactory.getAuthorizationManager().filterResponse((List<Entity>) responseContext.getEntity(), (User) requestContext.getProperty("user"));
        responseContext.setEntity(filteredEntities);
    }
}
 
開發者ID:rndsolutions,項目名稱:hawkcd,代碼行數:8,代碼來源:SecurityResponseFilter.java

示例10: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext req, ContainerResponseContext resp) throws IOException {

    if (resp.hasEntity() && (resp.getEntity() instanceof Status)) {
        Status status = (Status) resp.getEntity();
        int code = (Status.State.UP == status.getState()) ? 200 : 503;
        resp.setStatus(code);
        resp.setEntity(status.toJson());
        resp.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_JSON);
    }
}
 
開發者ID:wildfly-swarm,項目名稱:wildfly-swarm,代碼行數:12,代碼來源:HealthResponseFilter.java

示例11: filter

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
		throws IOException {
	AuthenticationVariable authenticationVariable = AuthenticationVariable.getAuthenticationVariable();
	try {
		boolean crypt = authenticationVariable.isCrypt();
		if (crypt) {
			Object entity = responseContext.getEntity();
			String key = authenticationVariable.getKey();
			String encrypt = aesCrypto.encrypt(JsonUtil.toJson(entity), key);
			responseContext.setEntity(encrypt, new Annotation[] {}, MediaType.TEXT_PLAIN_TYPE);
		}
	} catch (Exception e) {
		responseContext.setEntity("權限或秘鑰錯誤!", new Annotation[] {}, MediaType.TEXT_PLAIN_TYPE);
	}
	User user = authenticationVariable.getUser();
	if (null != user) {
		UserTokenType userAuthorizationType = user.getUserAuthorizationType();
		MultivaluedMap<String, Object> headers = responseContext.getHeaders();
		if (userAuthorizationType.equals(UserTokenType.SINGLE_TOKEN)) {
			headers.remove(AUTHORIZATION_HEADER);
			headers.add(AUTHORIZATION_HEADER, UserTokenType.SINGLE_TOKEN.getValue() + " " + user.getNewToken());
			Map<String, NewCookie> cookies = responseContext.getCookies();
			NewCookie cookie = new NewCookie(UserTokenType.SINGLE_TOKEN.getValue(), user.getNewToken());
			cookies.put(UserTokenType.SINGLE_TOKEN.getValue(), cookie);
		} else if (user.isNeedRefreshToken()) {
			headers.add(DUBBO_ATTACHMENT_HEADER, "refresh_token=need");
		}
	}
}
 
開發者ID:nince-wyj,項目名稱:jahhan,代碼行數:31,代碼來源:CryptoFilter.java

示例12: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
public void processResponse(ContainerRequestContext requestContext,
                            ContainerResponseContext responseContext,
                            ResourceInfo resourceInfo) {
    Object responseData = responseContext.getEntity();
    logger.info("response:\n", JsonUtils.toJson(responseData));
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:7,代碼來源:ReqResLogHandler.java

示例13: processResponse

import javax.ws.rs.container.ContainerResponseContext; //導入方法依賴的package包/類
public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
		ResourceInfo resourceInfo) {
	Object responseData = responseContext.getEntity();
	logger.info("response:\n",JsonUtils.toJson(responseData));
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:6,代碼來源:ReqResLogHandler.java


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