当前位置: 首页>>代码示例>>Java>>正文


Java ContainerResponseContext.setEntity方法代码示例

本文整理汇总了Java中javax.ws.rs.container.ContainerResponseContext.setEntity方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerResponseContext.setEntity方法的具体用法?Java ContainerResponseContext.setEntity怎么用?Java ContainerResponseContext.setEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.container.ContainerResponseContext的用法示例。


在下文中一共展示了ContainerResponseContext.setEntity方法的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包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

    final EntityTag entityTag = getEntityTag(responseContext);
    final Date lastModified = getLastModified(responseContext);

    responseContext.getHeaders().putSingle(HttpHeaders.CACHE_CONTROL, cacheControl);
    writeHeader(responseContext, HttpHeaders.ETAG, entityTag);
    writeHeader(responseContext, HttpHeaders.LAST_MODIFIED, lastModified == null ? null : HttpUtils.getHttpDateFormat().format(lastModified));

    final Response.ResponseBuilder builder = evaluatePreconditions(requestContext, entityTag, lastModified);
    if (builder != null) {
        responseContext.setStatusInfo(Response.Status.NO_CONTENT);
        responseContext.setEntity(null);
    }
}
 
开发者ID:Microbule,项目名称:microbule,代码行数:17,代码来源:ContainerCacheFilter.java

示例4: populateResponse

import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
public void populateResponse(ContainerResponseContext responseContext) {
    if (hasResponseContent) {
        responseContext.setEntity(responseContent);
    }
    if (hasResponseContentType) {
        responseContext.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
    }
    if (hasResponseStatus) {
        responseContext.setStatus(responseStatus);
    }
    for (Entry<String, String> headers : responseHeaders.entrySet()) {
        responseContext.getHeaders().putSingle(headers.getKey(), headers.getValue());
    }
    for (NewCookie cookie : responseCookies) {
        responseContext.getHeaders().add(HttpHeaders.SET_COOKIE, cookie);
    }
}
 
开发者ID:pac4j,项目名称:jax-rs-pac4j,代码行数:18,代码来源:JaxRsContext.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 requestContext, ContainerResponseContext responseContext) throws IOException {
    if (doesPathContain(requestContext, "/api/login")) {
        String sessionId = ((TokenInfo) responseContext.getEntity()).getSessionid();
        addCookie(responseContext, newCookie(sessionId));
        responseContext.setEntity("logged in");
    } else if (doesPathContain(requestContext, "/api/login/logout")) {
        addCookie(responseContext, newCookie(""));
    }
}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:11,代码来源:LoginResponseFilter.java

示例7: replaceResponse

import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
/**
 * Set the entity response to a 404 JSON entity.
 */
private void replaceResponse(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) {
	final ServerError serverError = new ServerError();
	if (requestContext.getUriInfo().getPathParameters().size() == 1) {
		// Single parameter ---> entity identifier or whatever identifying a data
		serverError.setCode("entity");
		serverError.setMessage(requestContext.getUriInfo().getPathParameters().values().iterator().next().get(0));
	} else {
		serverError.setCode("data");
	}
	responseContext.setStatus(Status.NOT_FOUND.getStatusCode());
	responseContext.setEntity(toEntity(serverError), responseContext.getEntityAnnotations(), MediaType.APPLICATION_JSON_TYPE);

}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:17,代码来源:NotFoundResponseFilter.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: filter

import javax.ws.rs.container.ContainerResponseContext; //导入方法依赖的package包/类
public void filter(ContainerRequestContext reqc,
		ContainerResponseContext resc) throws IOException {
	MediaType mediaType = this.getMediaTypeFromExtentionOrHeader(reqc);
	resc.setEntity(resc.getEntity(), new Annotation[0], mediaType);
}
 
开发者ID:prime-optimus,项目名称:cricinfo-unofficial,代码行数:6,代码来源:EntityResponseFilter.java


注:本文中的javax.ws.rs.container.ContainerResponseContext.setEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。