Package com.sun.grizzly.tcp.http11

Examples of com.sun.grizzly.tcp.http11.GrizzlyAdapter


    }
     *
     */

    private GrizzlyOutputBuffer getOutputBuffer(GrizzlyResponse res) {
        GrizzlyOutputBuffer ob = res.getOutputBuffer();
        res.setStatus(202);
        res.setContentType("text/html");
        ob.setEncoding("UTF-8");
        return ob;
    }
View Full Code Here


     */
    private synchronized void sendConsentPage(GrizzlyRequest req, GrizzlyResponse res) { //should have only one caller
        setStateMsg(AdapterState.PERMISSION_NEEDED);
        byte[] bytes;
        try {
            GrizzlyOutputBuffer ob = getOutputBuffer(res);
            try {
                // Replace locale specific Strings
                String localHtml = replaceTokens(initHtml, bundle);

                // Replace path token
                String hp = (contextRoot.endsWith("/")) ? contextRoot : contextRoot + "/";
                bytes = localHtml.replace(MYURL_TOKEN, hp).getBytes("UTF-8");
            } catch (Exception ex) {
                bytes = ("Catastrophe:" + ex.getMessage()).getBytes("UTF-8");
            }
            res.setContentLength(bytes.length);
            ob.write(bytes, 0, bytes.length);
            ob.flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

     *
     */
    private void sendStatusPage(GrizzlyRequest req, GrizzlyResponse res) {
        byte[] bytes;
        try {
            GrizzlyOutputBuffer ob = getOutputBuffer(res);
            // Replace locale specific Strings
            String localHtml = replaceTokens(statusHtml, bundle);

            // Replace state token
            String status = getStateMsg().getI18NKey();
            try {
                // Try to get a localized version of this key
                status = bundle.getString(status);
            } catch (MissingResourceException ex) {
                // Use the non-localized String version of the status
                status = getStateMsg().toString();
            }
            String locationUrl = req.getScheme()
                                 + "://" + req.getServerName()
                                 + ':' + req.getServerPort() + "/login.jsf";
            localHtml = localHtml.replace(REDIRECT_TOKEN, locationUrl);
            bytes = localHtml.replace(STATUS_TOKEN, status).getBytes("UTF-8");
            res.setContentLength(bytes.length);
            ob.write(bytes, 0, bytes.length);
            ob.flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

     */
    private void sendStatusNotDAS(GrizzlyRequest req, GrizzlyResponse res) {
        byte[] bytes;
        try {
            String html = Utils.packageResource2String("statusNotDAS.html");
            GrizzlyOutputBuffer ob = getOutputBuffer(res);
            // Replace locale specific Strings
            String localHtml = replaceTokens(html, bundle);

            bytes = localHtml.getBytes("UTF-8");
            res.setContentLength(bytes.length);
            ob.write(bytes, 0, bytes.length);
            ob.flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here

    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED})
    @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML,"text/html;qs=2"})
    public Response create(HashMap<String, String> data) {
        Response.ResponseBuilder responseBuilder = Response.status(UNAUTHORIZED);
        RestActionReporter ar = new RestActionReporter();
        GrizzlyRequest grizzlyRequest = request.get();

        // If the call flow reached here, the request has been authenticated by logic in RestAdapater.
        // We authenticate here once again with supplied remoteHostName to see if the authentication needs to happen
        // as coming from it. This is to support admin gui to authenticate as if coming from remoteHostName that
        // original request to it originated from.
        String hostName = data.get("remoteHostName");
        AdminAccessController.Access access = AdminAccessController.Access.NONE;
        try {
            access = (hostName == null ? AdminAccessController.Access.FULL : ResourceUtil.authenticateViaAdminRealm(habitat, grizzlyRequest, hostName) ) ;
        } catch (Exception e) {
            ar.setMessage("Error while authenticating " + e);
        }

        if (access == AdminAccessController.Access.FULL) {
            responseBuilder.status(OK);

            // Check to see if the username has been set (anonymous user case)
            String username = (String) grizzlyRequest.getAttribute("restUser");
            if (username != null) {
                ar.getExtraProperties().put("username", username);
            }
            ar.getExtraProperties().put("token", sessionManager.createSession(grizzlyRequest));
View Full Code Here

TOP

Related Classes of com.sun.grizzly.tcp.http11.GrizzlyAdapter

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.