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

The following examples show how to use javax.ws.rs.core.Response#fromResponse() . 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
Source File: ResponseCorsFilter.java    From semanticMDR with GNU General Public License v3.0 6 votes vote down vote up
@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 File: BasicClient.java    From secure-data-service with 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
Source File: ResponseCorsFilter.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
@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 File: BasicHttpClient.java    From zerocode with 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
Source File: ResponseCorsFilter.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@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;
}