Package org.gridgain.grid.kernal.processors.rest

Examples of org.gridgain.grid.kernal.processors.rest.GridRestResponse


            res.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

            return;
        }

        GridRestResponse cmdRes;

        Map<String, Object> params = parameters(req);

        try {
            GridRestRequest cmdReq = createRequest(cmd, params, req);

            if (log.isDebugEnabled())
                log.debug("Initialized command request: " + cmdReq);

            cmdRes = hnd.handle(cmdReq);

            if (cmdRes == null)
                throw new IllegalStateException("Received null result from handler: " + hnd);

            byte[] sesTok = cmdRes.sessionTokenBytes();

            if (sesTok != null)
                cmdRes.setSessionToken(U.byteArray2HexString(sesTok));

            res.setStatus(HttpServletResponse.SC_OK);
        }
        catch (Throwable e) {
            res.setStatus(HttpServletResponse.SC_OK);

            U.error(log, "Failed to process HTTP request [action=" + act + ", req=" + req + ']', e);

            cmdRes = new GridRestResponse(STATUS_FAILED, e.getMessage());
        }

        JsonConfig cfg = new GridJettyJsonConfig();
        JSON json;

        try {
            json = JSONSerializer.toJSON(cmdRes, cfg);
        }
        catch (JSONException e) {
            U.error(log, "Failed to convert response to JSON: " + cmdRes, e);

            json = JSONSerializer.toJSON(new GridRestResponse(STATUS_FAILED, e.getMessage()), cfg);
        }

        try {
            if (log.isDebugEnabled())
                log.debug("Parsed command response into JSON object: " + json.toString(2));
View Full Code Here


            authorize(req, subjCtx);
        }
        catch (GridSecurityException e) {
            assert subjCtx != null;

            GridRestResponse res = new GridRestResponse(STATUS_SECURITY_CHECK_FAILED, e.getMessage());

            if (ctx.isEnterprise()) {
                try {
                    res.sessionTokenBytes(updateSessionToken(req, subjCtx));
                }
                catch (GridException e1) {
                    U.warn(log, "Cannot update response session token: " + e1.getMessage());
                }
            }

            return new GridFinishedFuture<>(ctx, res);
        }
        catch (GridException e) {
            return new GridFinishedFuture<>(ctx, new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
        }

        interceptRequest(req);

        GridRestCommandHandler hnd = handlers.get(req.command());

        GridFuture<GridRestResponse> res = hnd == null ? null : hnd.handleAsync(req);

        if (res == null)
            return new GridFinishedFuture<>(ctx,
                new GridException("Failed to find registered handler for command: " + req.command()));

        final GridSecurityContext subjCtx0 = subjCtx;

        return res.chain(new C1<GridFuture<GridRestResponse>, GridRestResponse>() {
            @Override public GridRestResponse apply(GridFuture<GridRestResponse> f) {
                GridRestResponse res;

                try {
                    res = f.get();
                }
                catch (Exception e) {
                    LT.error(log, e, "Failed to handle request: " + req.command());

                    if (log.isDebugEnabled())
                        log.debug("Failed to handle request [req=" + req + ", e=" + e + "]");

                    res = new GridRestResponse(STATUS_FAILED, e.getMessage());
                }

                assert res != null;

                if (ctx.secureSession().enabled()) {
                    try {
                        res.sessionTokenBytes(updateSessionToken(req, subjCtx0));
                    }
                    catch (GridException e) {
                        U.warn(log, "Cannot update response session token: " + e.getMessage());
                    }
                }
View Full Code Here

TOP

Related Classes of org.gridgain.grid.kernal.processors.rest.GridRestResponse

Copyright © 2018 www.massapicom. 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.