Package info.openurl.oom

Examples of info.openurl.oom.OpenURLResponse


            status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }
        HashMap<String, String> header_map = new HashMap<String, String>();
        header_map.put("Content-Length", baos.size() + "");
        header_map.put("Date", HttpDate.getHttpDate());
        return new OpenURLResponse(status, responseFormat, baos.toByteArray(), header_map);
    }
View Full Code Here


    /**
     * Resolves the OpenURLResponse.
     */
    public OpenURLResponse resolve(OpenURLRequest openURLRequest) throws OpenURLException {
        OpenURLResponse response = null;

        // Try each ContentObject until someone responds
        ContextObject[] contextObjects = openURLRequest.getContextObjects();
        for (int i = 0; response == null && i < contextObjects.length; ++i) {
            ContextObject contextObject = contextObjects[i];
View Full Code Here

    /**
     * Creates an OpenURLResponse.
     */
    public OpenURLResponse openURLResponseFactory(int status, String redirectURL, String contentType, byte[] bytes) {
        return new OpenURLResponse(status, redirectURL, contentType, bytes);
    }
View Full Code Here

            status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        }
        HashMap<String, String> header_map = new HashMap<String, String>();
        header_map.put("Content-Length", Integer.toString(b.length));
        header_map.put("Date", HttpDate.getHttpDate());
        return new OpenURLResponse(status, responseFormat, b, header_map);
    }
View Full Code Here

                resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Request");
                return;
            }

            // Process the ContextObjects
            final OpenURLResponse result = processor.resolve(openURLRequest);

            // See if anyone handled the request
            int status;
            if (result == null) {
                status = HttpServletResponse.SC_NOT_FOUND;
            } else {
                status = result.getStatus();
                final Cookie[] cookies = result.getCookies();
                if (cookies != null) {
                    for (int i = 0; i < cookies.length; ++i) {
                        resp.addCookie(cookies[i]);
                    }
                }

                final Map sessionMap = result.getSessionMap();
                if (sessionMap != null) {
                    final HttpSession session = req.getSession(true);
                    final Iterator iter = sessionMap.entrySet().iterator();
                    while (iter.hasNext()) {
                        final Map.Entry entry = (Entry) iter.next();
                        session.setAttribute((String) entry.getKey(), entry.getValue());
                    }
                }

                final Map headerMap = result.getHeaderMap();
                if (headerMap != null) {
                    final Iterator iter = headerMap.entrySet().iterator();
                    while (iter.hasNext()) {
                        final Map.Entry entry = (Entry) iter.next();
                        resp.setHeader((String) entry.getKey(), (String) entry.getValue());
                    }
                }
            }

            // Allow the processor to generate a variety of response types
            switch (status) {
                case HttpServletResponse.SC_MOVED_TEMPORARILY:
                    resp.sendRedirect(resp.encodeRedirectURL(result.getRedirectURL()));
                    break;
                case HttpServletResponse.SC_SEE_OTHER:
                case HttpServletResponse.SC_MOVED_PERMANENTLY:
                    resp.setStatus(status);
                    resp.setHeader("Location", result.getRedirectURL());
                    break;
                case HttpServletResponse.SC_NOT_FOUND:
                    resp.sendError(status);
                    break;
                default:
                    final OutputStream out = resp.getOutputStream();
                    resp.setStatus(status);
                    resp.setContentType(result.getContentType());
                    final InputStream is = result.getInputStream();
                    final byte[] bytes = new byte[1024];
                    int len;

                    while ((len = is.read(bytes)) != -1) {
                        out.write(bytes, 0, len);
View Full Code Here

            // rchute: Add requester for possible extension processing
            final ContextObject[] coa = openURLRequest.getContextObjects();
            coa[0].getRequesters()[0].addDescriptor(req.getRemoteAddr());

            // Process the ContextObjects
            final OpenURLResponse result = processor.resolve(openURLRequest);

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("OpenURLRequestProcessor resolving to a result");
            }

            // See if anyone handled the request
            int status;

            if (result == null) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("OpenURLRequestProcessor didn't find result");
                }

                status = HttpServletResponse.SC_NOT_FOUND;
            } else {
                status = result.getStatus();
                final Cookie[] cookies = result.getCookies();

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("OpenURLRequestProcessor status: {}", status);
                }

                if (cookies != null) {
                    for (int i = 0; i < cookies.length; ++i) {
                        resp.addCookie(cookies[i]);
                    }
                }

                final Map<?, ?> sessionMap = result.getSessionMap();

                if (sessionMap != null) {
                    final HttpSession session = req.getSession(true);
                    final Iterator<?> iter = sessionMap.entrySet().iterator();

                    while (iter.hasNext()) {
                        final Map.Entry<?, ?> entry = (Entry<?, ?>) iter.next();
                        final String key = (String) entry.getKey();
                        final String value = (String) entry.getValue();

                        session.setAttribute(key, value);
                    }
                }

                final Map<?, ?> headerMap = result.getHeaderMap();

                if (headerMap != null) {
                    final Iterator<?> iter = headerMap.entrySet().iterator();

                    while (iter.hasNext()) {
                        final Map.Entry<?, ?> entry = (Entry<?, ?>) iter.next();

                        resp.setHeader((String) entry.getKey(), (String) entry.getValue());
                    }
                }
            }

            // Allow the processor to generate a variety of response types
            switch (status) {
                case HttpServletResponse.SC_MOVED_TEMPORARILY:
                    resp.sendRedirect(resp.encodeRedirectURL(result.getRedirectURL()));
                    break;
                case HttpServletResponse.SC_SEE_OTHER:
                case HttpServletResponse.SC_MOVED_PERMANENTLY:
                    resp.setStatus(status);
                    resp.setHeader("Location", result.getRedirectURL());

                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Redirect URL: {}", result.getRedirectURL());
                    }

                    break;
                case HttpServletResponse.SC_NOT_FOUND:
                    final String id = req.getParameter("rft_id");
                    resp.sendError(status, id != null ? id + " not found" : "");

                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("RFT_ID ({}) not found", id);
                    }

                    break;
                default:
                    final OutputStream out = resp.getOutputStream();

                    resp.setStatus(status);
                    resp.setContentType(result.getContentType());

                    final InputStream is = result.getInputStream();
                    final byte[] bytes = new byte[1024];
                    int len;

                    while ((len = is.read(bytes)) != -1) {
                        out.write(bytes, 0, len);
View Full Code Here

TOP

Related Classes of info.openurl.oom.OpenURLResponse

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.