Search in sources :

Example 1 with ResponseBuilderImpl

use of org.jboss.resteasy.specimpl.ResponseBuilderImpl in project oxAuth by GluuFederation.

the class RedirectUtil method getRedirectResponseBuilder.

public static ResponseBuilder getRedirectResponseBuilder(RedirectUri redirectUriResponse, HttpServletRequest httpRequest) {
    ResponseBuilder builder;
    if (httpRequest != null && httpRequest.getHeader(NO_REDIRECT_HEADER) != null) {
        try {
            URI redirectURI = URI.create(redirectUriResponse.toString());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put(JSON_REDIRECT_PROPNAME, redirectURI.toURL());
            String jsonResp = jsonObject.toString();
            jsonResp = jsonResp.replace("\\/", "/");
            builder = Response.ok(new GenericEntity<String>(jsonResp, String.class), MediaType.APPLICATION_JSON_TYPE);
        } catch (MalformedURLException e) {
            builder = Response.serverError();
            log.debug(e.getMessage(), e);
        } catch (JSONException e) {
            builder = Response.serverError();
            log.debug(e.getMessage(), e);
        }
    } else if (redirectUriResponse.getResponseMode() != ResponseMode.FORM_POST) {
        URI redirectURI = URI.create(redirectUriResponse.toString());
        builder = new ResponseBuilderImpl();
        builder = Response.status(HTTP_REDIRECT);
        builder.location(redirectURI);
    } else {
        builder = new ResponseBuilderImpl();
        builder.status(Response.Status.OK);
        builder.type(MediaType.TEXT_HTML_TYPE);
        builder.cacheControl(CacheControl.valueOf("no-cache, no-store"));
        builder.header("Pragma", "no-cache");
        builder.entity(redirectUriResponse.toString());
    }
    return builder;
}
Also used : MalformedURLException(java.net.MalformedURLException) JSONObject(org.codehaus.jettison.json.JSONObject) GenericEntity(javax.ws.rs.core.GenericEntity) ResponseBuilderImpl(org.jboss.resteasy.specimpl.ResponseBuilderImpl) JSONException(org.codehaus.jettison.json.JSONException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) URI(java.net.URI)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 ResponseBuilderImpl (org.jboss.resteasy.specimpl.ResponseBuilderImpl)1