Examples of RestResponse


Examples of models.RestResponse

        Logger.info("EDITFORM");
        User user = new User();
        user = user.getUserFromSession(session());
        Form<Community> communityForm = form(Community.class);

        RestResponse response = Community.findByID(id);
        if(response.modelObject instanceof Community) {
            Community community = (Community) response.modelObject;
            communityForm = communityForm.fill(community);
            return ok(views.html.community.edit.render(user, communityForm, "Edit Community", response.jsonString, response.endpoint));
        } else {
View Full Code Here

Examples of models.RestResponse

            }

            Community editCommunity = filledForm.get();

            //Determine if the edited community is changed from original. i.e. don't update unless necessary
            RestResponse originalCommunityResponse = Community.findByID(id);
            Community originalCommunity = null;
            if(originalCommunityResponse.modelObject instanceof Community) {
                originalCommunity = (Community) originalCommunityResponse.modelObject;
            }

            if(editCommunity.equals(originalCommunity)) {
                Logger.info("Communities are equal, nothing to do");
                flash("success", "No changes to community detected");
                return redirect(routes.Communities.show(id));
            } else {
                editCommunity.id = originalCommunity.id;

                RestResponse restResponse = editCommunity.update(user.token());
                HttpResponse httpResponse = restResponse.httpResponse;
                if(httpResponse.getStatusLine().getStatusCode() == 200) {
                    Logger.info("ok");
                    flash("success", "Community has been updated.");
                    return redirect(routes.Communities.show(id));
View Full Code Here

Examples of models.RestResponse

    //TODO index

    public static Result show(Long id) throws IOException {
        User user = new User();
        user = user.getUserFromSession(session());
        RestResponse response = Collection.findByID(id, user.token());
        if(response.httpResponse.getStatusLine().getStatusCode() == 200) {
            return ok(views.html.collection.detail.render(user, (Collection)response.modelObject, "Single Collection", response.jsonString, response.endpoint));
        } else {
            return internalServerError();
        }
View Full Code Here

Examples of net.csdn.modules.http.RestResponse

* 6/28/13 WilliamZhu(allwefantasy@gmail.com)
*/
public class BaseControllerTest extends IocTest {

    public RestResponse runAction(String path, Map params, RestRequest.Method method) throws Exception {
        RestResponse response = new MockRestResponse();

        Map newParams = new HashMap();
        for (Object key : params.keySet()) {
            newParams.put(key, params.get(key).toString());
        }
View Full Code Here

Examples of net.csdn.modules.http.RestResponse

            throw e;
        }
    }

    public RestResponse runAction(String path, Map params, String rawParamsStr, RestRequest.Method method) throws Exception {
        RestResponse response = new MockRestResponse();

        Map newParams = new HashMap();
        if (params != null) {
            for (Object key : params.keySet()) {
                newParams.put(key, params.get(key).toString());
View Full Code Here

Examples of org.apache.cocoon.rest.controller.response.RestResponse

            // get the prepared controller
            Object controller = this.getController(controllerName, inputParameters, configuration);

            // invoke the appropriate method
            HttpServletRequest request = HttpContextHelper.getRequest(inputParameters);
            RestResponse restResponse = this.methodDelegator.delegate(request, controller);

            if (controller instanceof ConditionalGet) {
                storeCacheKey(((ConditionalGet) controller).constructCacheKey());
            }

            // execute the rest response
            RestResponseMetaData restResponseMetaData = restResponse.setup(inputParameters);

            // set the status-code with the result produced by the restResponse execution
            ResponseHeaderCollector.setStatusCode(restResponseMetaData.getStatusCode());

            // set the content type with the result produced by the restResponse execution
View Full Code Here

Examples of org.apache.cocoon.rest.controller.response.RestResponse

            // get the prepared controller
            Object controller = this.getController(controllerName, inputParameters, configuration);

            // invoke the appropriate method
            HttpServletRequest request = HttpContextHelper.getRequest(inputParameters);
            RestResponse restResponse = this.methodDelegator.delegate(request, controller);

            // execute the rest response
            RestResponseMetaData restResponseMetaData = restResponse.execute(outputStream, inputParameters);

            // set the status-code with the result produced by the restResponse execution
            ResponseHeaderCollector.setStatusCode(restResponseMetaData.getStatusCode());

            // set the content type with the result produced by the restResponse execution
View Full Code Here

Examples of org.elasticsearch.thrift.RestResponse

    @Test public void testSimpleApis() throws Exception {
        RestRequest request = new RestRequest(Method.POST, "/test/type1");
        request.setBody(ByteBuffer.wrap(XContentFactory.jsonBuilder().startObject()
                .field("field", "value")
                .endObject().copiedBytes()));
        RestResponse response = client.execute(request);
        Map<String, Object> map = parseBody(response);
        assertThat(response.getStatus(), equalTo(Status.CREATED));
        assertThat(map.get("ok").toString(), equalTo("true"));
        assertThat(map.get("_index").toString(), equalTo("test"));
        assertThat(map.get("_type").toString(), equalTo("type1"));

        request = new RestRequest(Method.GET, "/_cluster/health");
        response = client.execute(request);
        assertThat(response.getStatus(), equalTo(Status.OK));
    }
View Full Code Here

Examples of org.elasticsearch.thrift.RestResponse

    public void testSimpleApis() throws Exception {
        RestRequest request = new RestRequest(Method.POST, "/test/type1/1");
        request.setBody(ByteBuffer.wrap(XContentFactory.jsonBuilder().startObject()
                .field("field", "value")
                .endObject().bytes().copyBytesArray().array()));
        RestResponse response = client.execute(request);
        Map<String, Object> map = parseBody(response);
        assertThat(response.getStatus(), equalTo(Status.CREATED));
        assertThat(map.get("_index").toString(), equalTo("test"));
        assertThat(map.get("_type").toString(), equalTo("type1"));
        assertThat(map.get("_id").toString(), equalTo("1"));

        request = new RestRequest(Method.GET, "/test/type1/1");
        response = client.execute(request);
        map = parseBody(response);
        assertThat(response.getStatus(), equalTo(Status.OK));
        assertThat(map.get("_index").toString(), equalTo("test"));
        assertThat(map.get("_type").toString(), equalTo("type1"));
        assertThat(map.get("_id").toString(), equalTo("1"));
        assertThat(map.get("_source"), notNullValue());
        assertThat(map.get("_source"), instanceOf(Map.class));
        assertThat(((Map<String, String>)map.get("_source")).get("field"), is("value"));

        request = new RestRequest(Method.GET, "/_cluster/health");
        response = client.execute(request);
        assertThat(response.getStatus(), equalTo(Status.OK));

        request = new RestRequest(Method.GET, "/bogusindex");
        response = client.execute(request);
        assertThat(response.getStatus(), equalTo(Status.NOT_FOUND));
    }
View Full Code Here

Examples of org.glassfish.admingui.common.util.RestResponse

        target.register(new HttpBasicAuthFilter(username, password));
        MultivaluedMap payLoad = new MultivaluedHashMap();
        payLoad.putSingle("remoteHostName", request.getRemoteHost());

        Response resp = target.request(RESPONSE_TYPE).post(Entity.entity(payLoad, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse restResp = RestResponse.getRestResponse(resp);

        // Check to see if successful..
        if (restResp.isSuccess()) {
            // Username and Password sent in... validate them!
            CallerPrincipalCallback cpCallback =
                    new CallerPrincipalCallback(clientSubject, username);
            try {
                handler.handle(new Callback[]{ /*pwdCallback,*/cpCallback});
            } catch (Exception ex) {
                AuthException ae = new AuthException();
                ae.initCause(ex);
                throw ae;
            }

            // recreate the session
            Map<String, Object> map = new HashMap<String, Object>();
            Enumeration<String> names = session.getAttributeNames();
            while (names.hasMoreElements()) {
                String key = names.nextElement();
                map.put(key, session.getAttribute(key));
            }
            session.invalidate();
            session = request.getSession(true);
            for (Map.Entry<String, Object> e : map.entrySet()) {
                session.setAttribute(e.getKey(), e.getValue());
            }

            if (session != null) {
                // Get the "extraProperties" section of the response...
                Object obj = restResp.getResponse().get("data");
                Map extraProperties = null;
                if ((obj != null) && (obj instanceof Map)) {
                    obj = ((Map) obj).get("extraProperties");
                    if ((obj != null) && (obj instanceof Map)) {
                        extraProperties = (Map) obj;
                    }
                }

                // Save the Rest Token...
                if (extraProperties != null) {
                    session.putValue(REST_TOKEN, extraProperties.get("token"));
                }

                // Save the Subject...
                session.putValue(SAVED_SUBJECT, clientSubject);

                // Save the userName
                session.putValue(USER_NAME, username);
            }

            try {
                // Redirect...
                String origRequest = (String)session.getAttribute(ORIG_REQUEST_PATH);
                // Explicitly test for favicon.ico, as Firefox seems to ask for this on
                // every page
                if ((origRequest == null) || "/favicon.ico".equals(origRequest)) {
                    origRequest = "/index.jsf";
                }
                logger.log(Level.INFO, "Redirecting to {0}", origRequest);
                response.sendRedirect(response.encodeRedirectURL(origRequest));
            } catch (Exception ex) {
                AuthException ae = new AuthException();
                ae.initCause(ex);
                throw ae;
            }

            // Continue...
            return AuthStatus.SEND_CONTINUE;
        } else {
            int status = restResp.getResponseCode();
            if (status == 403) {
                request.setAttribute("errorText", GuiUtil.getMessage("alert.ConfigurationError"));
                request.setAttribute("messageText", GuiUtil.getMessage("alert.EnableSecureAdmin"));
            }
            RequestDispatcher rd = request.getRequestDispatcher(this.loginErrorPage);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.