Example usage for javax.servlet.http HttpServletRequest toString

List of usage examples for javax.servlet.http HttpServletRequest toString

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationHandlerCollection.java

@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {
    // don't do anything if already processed
    if (response.isCommitted() || baseRequest.isHandled())
        return;//from   ww  w .j  a  va2 s  . c om

    final Iterator<Handler> handlers = this.handlers.iterator();
    if (!handlers.hasNext())
        return;

    final ThroughputMetric requestsMetric = metrics.getRequestsMetric();
    final long requestStart = requestsMetric.requestStarted();
    try {
        doHandle(target, baseRequest, request, response);
        if (response instanceof Response) {
            final int status = ((Response) response).getStatus();
            if (HttpStatus.isServerError(status)) {
                metrics.getRequestsMetric().requestFailed();
                metrics.error(status, ((Response) response).getReason());
            } else {
                metrics.getRequestsMetric().requestFinished(((Response) response).getContentCount(),
                        System.currentTimeMillis() - requestStart);
            }
        } else {
            metrics.getRequestsMetric().requestFinished(0, System.currentTimeMillis() - requestStart);
        }
    } catch (final EofException | RuntimeIOException | ContinuationThrowable e) {
        metrics.getRequestsMetric().requestFailed();
        throw e;
    } catch (final Exception e) {
        metrics.getRequestsMetric().requestFailed();

        final DispatcherType type = baseRequest.getDispatcherType();
        if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type))) {
            if (e instanceof IOException)
                throw (IOException) e;
            if (e instanceof RuntimeException)
                throw (RuntimeException) e;
            if (e instanceof ServletException)
                throw (ServletException) e;
        }

        // handle or log exception
        else if (e instanceof RuntimeIOException)
            throw (RuntimeIOException) e;
        else if (e instanceof EofException)
            throw (EofException) e;
        else if ((e instanceof IOException) || (e instanceof UnavailableException)
                || (e instanceof IllegalStateException)) {
            if (Platform.inDebugMode()) {
                LOG.debug("Exception processing request {}: {}", request.getRequestURI(),
                        ExceptionUtils.getMessage(e), e);
                LOG.debug(request.toString());
            }
        } else {
            LOG.error("Exception processing request {}: {}",
                    new Object[] { request.getRequestURI(), ExceptionUtils.getRootCauseMessage(e), e });
            if (Platform.inDebugMode()) {
                LOG.debug(request.toString());
            }
        }

        // send error response if possible
        if (!response.isCommitted()) {
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass());
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
            if (e instanceof UnavailableException) {
                final UnavailableException ue = (UnavailableException) e;
                if (ue.isPermanent()) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
                } else {
                    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, e.getMessage());
                }
            } else if (e instanceof IllegalStateException) {
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, e.getMessage());
            } else {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
            }
        } else {
            // give up
            if (JettyDebug.debug) {
                LOG.debug("Response already committed for handling {}", ExceptionUtils.getMessage(e));
            }
        }
    } catch (final Error e) {
        metrics.getRequestsMetric().requestFailed();

        // only handle some errors
        if (!((e instanceof LinkageError) || (e instanceof AssertionError)))
            throw e;

        final DispatcherType type = baseRequest.getDispatcherType();
        if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type)))
            throw e;

        LOG.error("Error processing request {}: {}",
                new Object[] { request.getRequestURI(), ExceptionUtils.getRootCauseMessage(e), e });
        if (JettyDebug.debug) {
            LOG.debug(request.toString());
        }

        // TODO httpResponse.getHttpConnection().forceClose();
        if (!response.isCommitted()) {
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass());
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        } else {
            if (JettyDebug.debug) {
                LOG.debug("Response already committed for handling {}", ExceptionUtils.getMessage(e));
            }
        }
    }
}

From source file:org.encuestame.core.security.CustomAuthenticationEntryPoint.java

/**
 *
 *///from w w w .  j a  v a  2 s  .com
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        org.springframework.security.core.AuthenticationException authException)
        throws IOException, ServletException {

    if (authException != null) {
        // you can check for the spefic exception here and redirect like
        // this
        logger.debug("respnse" + response.toString());
        logger.debug("respnse" + response.getContentType());
        logger.debug("request" + request.toString());
        logger.debug("request" + request.getContentType());
        //response.sendRedirect("403.html");
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    String redirectUrl = null;

    if (useForward) {

        if (forceHttps && "http".equals(request.getScheme())) {
            // First redirect the current request to HTTPS.
            // When that request is received, the forward to the login page
            // will be used.
            redirectUrl = buildHttpsRedirectUrlForRequest(httpRequest);
        }

        if (redirectUrl == null) {
            String loginForm = determineUrlToUseForThisRequest(httpRequest, httpResponse, authException);

            if (logger.isDebugEnabled()) {
                logger.debug("Server side forward to: " + loginForm);
            }

            RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(loginForm);

            dispatcher.forward(request, response);

            return;
        }
    } else {
        // redirect to login page. Use https if forceHttps true

        redirectUrl = buildRedirectUrlToLoginPage(httpRequest, httpResponse, authException);

    }

    redirectStrategy.sendRedirect(httpRequest, httpResponse, redirectUrl);
}

From source file:org.opencms.main.OpenCmsCore.java

/**
 * Initializes a new cms object from the session data of the request.<p>
 * // www .  j  av a2  s  . c o m
 * If no session data is found, <code>null</code> is returned.<p>
 * 
 * @param req the request
 * 
 * @return the new initialized cms object
 * 
 * @throws CmsException if something goes wrong
 */
protected CmsObject initCmsObjectFromSession(HttpServletRequest req) throws CmsException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("Trying to init cms object from session for request \"" + req.toString() + "\".");
    }
    // try to get an OpenCms user session info object for this request
    CmsSessionInfo sessionInfo = m_sessionManager.getSessionInfo(req);

    if (sessionInfo == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No session info found.");
        }
        return null;
    }

    // initialize the requested site root
    CmsSite site = getSiteManager().matchRequest(req);

    // a user name is found in the session manager, reuse this user information
    CmsUUID project = sessionInfo.getProject();

    // initialize site root from request
    String siteroot = null;

    // a dedicated workplace site is configured
    if ((getSiteManager().getWorkplaceSiteMatcher().equals(site.getSiteMatcher()))) {
        // if no dedicated workplace site is configured, 
        // or for the dedicated workplace site, use the site root from the session attribute
        siteroot = sessionInfo.getSiteRoot();
    } else if (site.hasSecureServer()
            && getSiteManager().getWorkplaceSiteMatcher().getUrl().equals(site.getSecureUrl())) {
        // if the workplace is using the secured site
        siteroot = sessionInfo.getSiteRoot();
    } else {
        siteroot = site.getSiteRoot();
    }

    // initialize user from request
    CmsUser user = m_securityManager.readUser(null, sessionInfo.getUserId());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Initializing cms object with user \"" + user.getName() + "\".");
    }
    return initCmsObject(req, user, siteroot, project, sessionInfo.getOrganizationalUnitFqn());
}

From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java

private void showSnoop(PortalRenderContext rcontext, boolean b, ServletConfig servletConfig,
        HttpServletRequest req) {
    Enumeration e = null;//from w ww.  j ava  2 s .  c o m

    rcontext.put("snoopRequest", req.toString());

    if (servletConfig != null) {
        Map<String, Object> m = new HashMap<String, Object>();
        e = servletConfig.getInitParameterNames();

        if (e != null) {
            while (e.hasMoreElements()) {
                String param = (String) e.nextElement();
                m.put(param, servletConfig.getInitParameter(param));
            }
        }
        rcontext.put("snoopServletConfigParams", m);
    }
    rcontext.put("snoopRequest", req);

    e = req.getHeaderNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getHeader(name));
        }
        rcontext.put("snoopRequestHeaders", m);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getParameter(name));
        }
        rcontext.put("snoopRequestParamsSingle", m);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String[] vals = (String[]) req.getParameterValues(name);
            StringBuilder sb = new StringBuilder();
            if (vals != null) {
                sb.append(vals[0]);
                for (int i = 1; i < vals.length; i++)
                    sb.append("           ").append(vals[i]);
            }
            m.put(name, sb.toString());
        }
        rcontext.put("snoopRequestParamsMulti", m);
    }

    e = req.getAttributeNames();
    if (e.hasMoreElements()) {
        Map<String, Object> m = new HashMap<String, Object>();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            m.put(name, req.getAttribute(name));

        }
        rcontext.put("snoopRequestAttr", m);
    }
}

From source file:org.sakaiproject.util.Web.java

public static String snoop(PrintWriter out, boolean html, ServletConfig config, HttpServletRequest req) {
    // if no out, send to system out
    ByteArrayOutputStream ostream = null;
    if (out == null) {
        ostream = new ByteArrayOutputStream();
        out = new PrintWriter(ostream);
        html = false;//from  ww  w.  j  a v a2  s .c  o  m
    }

    String h1 = "";
    String h1x = "";
    String pre = "";
    String prex = "";
    String b = "";
    String bx = "";
    String p = "";
    if (html) {
        h1 = "<h1>";
        h1x = "</h1>";
        pre = "<pre>";
        prex = "</pre>";
        b = "<b>";
        bx = "</b>";
        p = "<p>";
    }

    Enumeration<?> e = null;

    out.println(h1 + "Snoop for request" + h1x);
    out.println(req.toString());

    if (config != null) {
        e = config.getInitParameterNames();
        if (e != null) {
            boolean first = true;
            while (e.hasMoreElements()) {
                if (first) {
                    out.println(h1 + "Init Parameters" + h1x);
                    out.println(pre);
                    first = false;
                }
                String param = (String) e.nextElement();
                out.println(" " + param + ": " + config.getInitParameter(param));
            }
            out.println(prex);
        }
    }

    out.println(h1 + "Request information:" + h1x);
    out.println(pre);

    print(out, "Request method", req.getMethod());
    String requestUri = req.getRequestURI();
    print(out, "Request URI", requestUri);
    displayStringChars(out, requestUri);
    print(out, "Request protocol", req.getProtocol());
    String servletPath = req.getServletPath();
    print(out, "Servlet path", servletPath);
    displayStringChars(out, servletPath);
    String contextPath = req.getContextPath();
    print(out, "Context path", contextPath);
    displayStringChars(out, contextPath);
    String pathInfo = req.getPathInfo();
    print(out, "Path info", pathInfo);
    displayStringChars(out, pathInfo);
    print(out, "Path translated", req.getPathTranslated());
    print(out, "Query string", req.getQueryString());
    print(out, "Content length", req.getContentLength());
    print(out, "Content type", req.getContentType());
    print(out, "Server name", req.getServerName());
    print(out, "Server port", req.getServerPort());
    print(out, "Remote user", req.getRemoteUser());
    print(out, "Remote address", req.getRemoteAddr());
    // print(out, "Remote host", req.getRemoteHost());
    print(out, "Authorization scheme", req.getAuthType());

    out.println(prex);

    e = req.getHeaderNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request headers:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getHeader(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Single Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + " = " + req.getParameter(name));
        }
        out.println(prex);
    }

    e = req.getParameterNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Servlet parameters (Multiple Value style):" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            String vals[] = (String[]) req.getParameterValues(name);
            if (vals != null) {
                out.print(b + " " + name + " = " + bx);
                out.println(vals[0]);
                for (int i = 1; i < vals.length; i++)
                    out.println("           " + vals[i]);
            }
            out.println(p);
        }
        out.println(prex);
    }

    e = req.getAttributeNames();
    if (e.hasMoreElements()) {
        out.println(h1 + "Request attributes:" + h1x);
        out.println(pre);
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            out.println(" " + name + ": " + req.getAttribute(name));
        }
        out.println(prex);
    }

    if (ostream != null) {
        out.flush();
        return ostream.toString();
    }

    return "";
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * OPTIONS Method.</br>//  w w  w. j  a va 2 s .c om
 * 
 * 
 * @param req
 *            HttpServletRequest
 * @param resp
 *            HttpServletResponse
 * @throws IOException
 *             if an error in the underlying store occurs
 */
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    String lockOwner = "doOptions" + System.nanoTime() + req.toString();
    String path = getRelativePath(req);
    if (fResLocks.lock(path, lockOwner, false, 0)) {
        try {
            resp.addHeader("DAV", "1, 2");

            String methodsAllowed = determineMethodsAllowed(fStore.objectExists(path), fStore.isFolder(path));
            resp.addHeader("Allow", methodsAllowed);
            resp.addHeader("MS-Author-Via", "DAV");
        } catch (AccessDeniedException e) {
            log.error("WebdavServer not authenticated: ", e);
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
        } catch (WebdavException e) {
            log.error("WebdavServer internal error: ", e);
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        } finally {
            fResLocks.unlock(path, lockOwner);
        }
    } else {
        log.error("WebdavServer unable to lock resource " + lockOwner);
        resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * PROPFIND Method./*from w  w w  . jav a  2 s  .  co  m*/
 * 
 * @param req
 *            HttpServletRequest
 * @param resp
 *            HttpServletResponse
 * @throws IOException
 *             if an error in the underlying store occurs
 * @throws ServletException
 */
protected void doPropfind(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    // Retrieve the resources
    String lockOwner = "doPropfind" + System.nanoTime() + req.toString();
    String path = getRelativePath(req);
    if ((path.toUpperCase().startsWith("/WEB-INF")) || (path.toUpperCase().startsWith("/META-INF"))) {
        log.error("WebdavServer cannot access /WEB-INF and /META-INF");
        resp.sendError(WebdavStatus.SC_FORBIDDEN);
        return;
    }

    int depth = getDepth(req);
    if (fResLocks.lock(path, lockOwner, false, depth)) {
        try {
            if (!fStore.objectExists(path)) {
                resp.setStatus(WebdavStatus.SC_NOT_FOUND);
                return;
                // we do not to continue since there is no root
                // resource
            }

            Vector properties = null;
            path = getCleanPath(getRelativePath(req));

            PropertyNodeType nodeType = getPropertyNodeAndType(req);

            if (nodeType.getType() == FIND_BY_PROPERTY) {
                properties = getPropertiesFromXML(nodeType.getNode());
            }

            resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
            resp.setContentType("text/xml; charset=UTF-8");

            // Create multistatus object
            XMLWriter generatedXML = new XMLWriter(resp.getWriter());
            generatedXML.writeXMLHeader();
            generatedXML.writeElement(null, "multistatus" + generateNamespaceDeclarations(), XMLWriter.OPENING);
            if (depth == 0) {
                parseProperties(req, generatedXML, path, nodeType.getType(), properties);
            } else {
                recursiveParseProperties(path, req, generatedXML, nodeType.getType(), properties, depth);
            }
            generatedXML.writeElement(null, "multistatus", XMLWriter.CLOSING);
            generatedXML.sendData();
        } catch (AccessDeniedException e) {
            log.error("WebdavServer not authenticated: ", e);
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
        } catch (WebdavException e) {
            log.error("WebdavServer internal error: ", e);
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        } finally {
            fResLocks.unlock(path, lockOwner);
        }
    } else {
        log.error("WebdavServer unable to lock resource " + lockOwner);
        resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * PROPPATCH Method.//from  ww w.  java 2  s.c  o  m
 * 
 * @param req
 *            HttpServletRequest
 * @param resp
 *            HttpServletResponse
 * @throws IOException
 *             if an error in the underlying store occurs
 */
protected void doProppatch(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if (readOnly) {
        log.error("WebdavServer not authenticated for write");
        resp.sendError(WebdavStatus.SC_FORBIDDEN);
    } else {
        String lockOwner = "doProppatch" + System.nanoTime() + req.toString();
        String path = getRelativePath(req);
        if ((path.toUpperCase().startsWith("/WEB-INF")) || (path.toUpperCase().startsWith("/META-INF"))) {
            log.error("WebdavServer cannot access /WEB-INF and /META-INF");
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
            return;
        }

        if (fResLocks.lock(path, lockOwner, false, -1)) {
            try {
                if (!fStore.objectExists(path)) {
                    resp.setStatus(WebdavStatus.SC_NOT_FOUND);
                    return;
                    // we do not to continue since there is no root
                    // resource
                }

                Properties[] properties = getPropertiesToSetOrRemove(req);
                // Set properties
                if (properties[0] != null && properties[0].size() > 0)
                    fStore.setCustomProperties(path, properties[0]);

                // Remove properties
                if (properties[1] != null && properties[1].size() > 0)
                    fStore.removeCustomProperties(path, properties[1]);

            } catch (WebdavException e) {
                log.error("WebdavServer internal error: ", e);
                resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            } finally {
                fResLocks.unlock(path, lockOwner);
            }
        } else {
            log.error("WebdavServer unable to lock resource " + lockOwner);
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * GET Method//from  ww w.  j  a va 2  s .  c  o m
 * 
 * @param req
 *            HttpServletRequest
 * @param resp
 *            HttpServletResponse
 * @param includeBody
 *            if the resource content should be included or not (GET/HEAD)
 * @throws IOException
 *             if an error in the underlying store occurs
 */
protected void doGet(HttpServletRequest req, HttpServletResponse resp, boolean includeBody)
        throws ServletException, IOException {

    String lockOwner = "doGet" + System.nanoTime() + req.toString();
    String path = getRelativePath(req);
    if (fResLocks.lock(path, lockOwner, false, 0)) {
        try {

            if (fStore.isResource(path)) {
                // path points to a file but ends with / or \
                if (path.endsWith("/") || (path.endsWith("\\"))) {
                    resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getRequestURI());
                } else {

                    // setting headers
                    long lastModified = fStore.getLastModified(path).getTime();
                    resp.setDateHeader("last-modified", lastModified);

                    long resourceLength = fStore.getResourceLength(path);
                    if (resourceLength > 0) {
                        if (resourceLength <= Integer.MAX_VALUE) {
                            resp.setContentLength((int) resourceLength);
                        } else {
                            resp.setHeader("content-length", "" + resourceLength);
                            // is "content-length" the right header? is long
                            // a valid format?
                        }

                    }

                    String mimeType = getServletContext().getMimeType(path);
                    if (mimeType != null) {
                        resp.setContentType(mimeType);
                    }

                    if (includeBody) {
                        OutputStream out = resp.getOutputStream();
                        InputStream in = fStore.getResourceContent(path);
                        try {
                            int read = -1;
                            byte[] copyBuffer = new byte[BUF_SIZE];

                            while ((read = in.read(copyBuffer, 0, copyBuffer.length)) != -1) {
                                out.write(copyBuffer, 0, read);
                            }

                        } finally {

                            in.close();
                            out.flush();
                            out.close();
                        }
                    }
                }
            } else {
                if (includeBody && fStore.isFolder(path)) {
                    renderHtml(path, resp.getOutputStream(), req.getContextPath());
                    resp.setContentType("text/html");
                } else {
                    if (!fStore.objectExists(path) && includeBody) {
                        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
                    } else {
                        // Check if we're included so we can return the appropriate 
                        // missing resource name in the error
                        String requestUri = (String) req.getAttribute("javax.servlet.include.request_uri");
                        if (requestUri == null) {
                            requestUri = req.getRequestURI();
                        } else {
                            // We're included, and the response.sendError() below is going
                            // to be ignored by the resource that is including us.
                            // Therefore, the only way we can let the including resource
                            // know is by including warning message in response
                            resp.getWriter()
                                    .write("The requested resource (" + requestUri + ") is not available");
                        }

                        resp.sendError(HttpServletResponse.SC_NOT_FOUND, requestUri);
                    }
                }
            }
        } catch (AccessDeniedException e) {
            log.error("WebdavServer not authenticated: ", e);
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
        } catch (ObjectAlreadyExistsException e) {
            resp.sendError(WebdavStatus.SC_NOT_FOUND, req.getRequestURI());
        } catch (WebdavException e) {
            log.error("WebdavServer internal error: ", e);
            resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
        } finally {
            fResLocks.unlock(path, lockOwner);
        }
    } else {
        log.error("WebdavServer unable to lock resource " + lockOwner);
        resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.webdavaccess.servlet.WebdavServlet.java

/**
 * MKCOL Method.//from www.  j  av a  2 s  .co  m
 * 
 * @param req
 *            HttpServletRequest
 * @param resp
 *            HttpServletResponse
 * @throws IOException
 *             if an error in the underlying store occurs
 */
protected void doMkcol(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    if (req.getContentLength() > 0) {
        resp.sendError(WebdavStatus.SC_NOT_IMPLEMENTED);
    } else {

        if (!readOnly) {
            // not readonly
            String path = getRelativePath(req);
            String parentPath = getParentPath(path);
            String lockOwner = "doMkcol" + System.nanoTime() + req.toString();
            if (fResLocks.lock(path, lockOwner, true, 0)) {
                try {
                    if (parentPath != null && fStore.isFolder(parentPath)) {
                        boolean isFolder = fStore.isFolder(path);
                        if (!fStore.objectExists(path)) {
                            try {
                                fStore.createFolder(path);
                                resp.setStatus(WebdavStatus.SC_CREATED);
                            } catch (ObjectAlreadyExistsException e) {
                                String methodsAllowed = determineMethodsAllowed(true, isFolder);
                                resp.addHeader("Allow", methodsAllowed);
                                resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                            }
                        } else {
                            // object already exists
                            String methodsAllowed = determineMethodsAllowed(true, isFolder);
                            resp.addHeader("Allow", methodsAllowed);
                            resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
                        }
                    } else {
                        resp.sendError(WebdavStatus.SC_CONFLICT);
                    }
                } catch (AccessDeniedException e) {
                    log.error("WebdavServer not authenticated: ", e);
                    resp.sendError(WebdavStatus.SC_FORBIDDEN);
                } catch (WebdavException e) {
                    log.error("WebdavServer internal error: ", e);
                    resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                } finally {
                    fResLocks.unlock(path, lockOwner);
                }
            } else {
                log.error("WebdavServer unable to lock resource " + lockOwner);
                resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            log.error("WebdavServer not authenticated for write");
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
        }
    }

}