Java Code Examples for javax.ws.rs.core.Response#fromResponse()

The following examples show how to use javax.ws.rs.core.Response#fromResponse() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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;
}
 
Example 2
Source Project: secure-data-service   File: BasicClient.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Response getHomeResource(Entity home) throws URISyntaxException, MessageProcessingException, IOException {

    URL url = URLBuilder.create(restClient.getBaseURL()).addPath(PathConstants.HOME).build();

    Response response = restClient.getRequest(url);
    if (response.getStatus() == Response.Status.OK.getStatusCode()) {
        try {
            JsonNode element = mapper.readValue(response.readEntity(String.class), JsonNode.class);
            Map<String, List<Link>> links = mapper.readValue(element,
                    new TypeReference<Map<String, List<BasicLink>>>() {
                    });
            home.getData().putAll(links);
        } catch (JsonParseException e) {
            // invalid Json, or non-Json response?
            ResponseBuilder builder = Response.fromResponse(response);
            builder.status(Response.Status.INTERNAL_SERVER_ERROR);
            return builder.build();
        }
    }
    return response;
}
 
Example 3
@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("")){
        resp.header("Access-Control-Allow-Headers", reqHead);
    }
 
    contResp.setResponse(resp.build());
    return contResp;
}
 
Example 4
Source Project: zerocode   File: BasicHttpClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Once the client executes the http call, then it receives the http response. This method takes care of handling
 * that. In case you need to handle it differently you can override this method.
 *
 * @param httpResponse  : Received Apache http response from the server
 *
 * @return  : Effective response with handled http session.
 * @throws IOException
 */
public Response handleResponse(CloseableHttpResponse httpResponse) throws IOException {
    Response serverResponse = createCharsetResponse(httpResponse);

    Header[] allHeaders = httpResponse.getAllHeaders();
    Response.ResponseBuilder responseBuilder = Response.fromResponse(serverResponse);
    for (Header thisHeader : allHeaders) {
        String headerKey = thisHeader.getName();
        responseBuilder = responseBuilder.header(headerKey, thisHeader.getValue());

        handleHttpSession(serverResponse, headerKey);
    }

    return responseBuilder.build();
}
 
Example 5
@Override
public ContainerResponse filter( ContainerRequest req, ContainerResponse contResp ) {

	ResponseBuilder resp = Response.fromResponse( contResp.getResponse());
	Map<String,String> headers = buildHeaders(
			req.getHeaderValue( CORS_REQ_HEADERS ),
			req.getHeaderValue( ORIGIN ));

	for( Map.Entry<String,String> h : headers.entrySet())
		resp.header( h.getKey(), h.getValue());

	contResp.setResponse( resp.build());
	return contResp;
}