Example usage for org.springframework.http HttpStatus MULTI_STATUS

List of usage examples for org.springframework.http HttpStatus MULTI_STATUS

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus MULTI_STATUS.

Prototype

HttpStatus MULTI_STATUS

To view the source code for org.springframework.http HttpStatus MULTI_STATUS.

Click Source Link

Document

207 Multi-Status .

Usage

From source file:com.ericsson.eiffel.remrem.publish.service.MessageServiceRMQImpl.java

/**
 * Method returns the Http response code for the events.
 *///  w  ww  . jav  a2s  .c o  m
public HttpStatus getHttpStatus() {
    if (statusCodes.size() > 1) {
        return HttpStatus.MULTI_STATUS;
    } else {
        return HttpStatus.valueOf(statusCodes.get(0));

    }
}

From source file:nl.ellipsis.webdav.server.methods.AbstractMethod.java

/**
 * Send a multistatus element containing a complete error report to the client.
 * If the errorList contains only one error, send the error directly without
 * wrapping it in a multistatus message.
 * /*from   www  .  jav  a  2  s.  co m*/
 * @param req
 *            Servlet request
 * @param resp
 *            Servlet response
 * @param errorList
 *            List of error to be displayed
 */
protected static void sendReport(HttpServletRequest req, HttpServletResponse resp,
        Hashtable<String, Integer> errorList) throws IOException {

    if (errorList.size() == 1) {
        int code = errorList.elements().nextElement();
        HttpStatus s = HttpStatus.valueOf(code);
        String status = s.getReasonPhrase();
        if (status != null && !status.isEmpty()) {
            resp.sendError(code, status);
        } else {
            resp.sendError(code);
        }
    } else {
        resp.setStatus(HttpStatus.MULTI_STATUS.value());

        String absoluteUri = req.getRequestURI();
        // String relativePath = getRelativePath(req);

        XMLWriter generatedXML = new XMLWriter();
        generatedXML.writeXMLHeader();

        generatedXML.writeElement(NS_DAV_PREFIX, NS_DAV_FULLNAME, WebDAVConstants.XMLTag.MULTISTATUS,
                XMLWriter.OPENING);

        Enumeration<String> pathList = errorList.keys();
        while (pathList.hasMoreElements()) {

            String errorPath = (String) pathList.nextElement();
            int errorCode = ((Integer) errorList.get(errorPath)).intValue();

            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.RESPONSE, XMLWriter.OPENING);

            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.HREF, XMLWriter.OPENING);
            String toAppend = null;
            if (absoluteUri.endsWith(errorPath)) {
                toAppend = absoluteUri;
            } else if (absoluteUri.contains(errorPath)) {
                int endIndex = absoluteUri.indexOf(errorPath) + errorPath.length();
                toAppend = absoluteUri.substring(0, endIndex);
            }
            if (StringUtils.isEmpty(toAppend)) {
                toAppend = CharsetUtil.FORWARD_SLASH;
            } else if (!toAppend.startsWith(CharsetUtil.FORWARD_SLASH) && !toAppend.startsWith(PROTOCOL_HTTP)) {
                toAppend = CharsetUtil.FORWARD_SLASH + toAppend;
            }
            generatedXML.writeText(errorPath);
            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.HREF, XMLWriter.CLOSING);
            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.STATUS, XMLWriter.OPENING);
            HttpStatus s = HttpStatus.valueOf(errorCode);
            generatedXML.writeText("HTTP/1.1 " + errorCode + " " + s.getReasonPhrase());
            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.STATUS, XMLWriter.CLOSING);

            generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.RESPONSE, XMLWriter.CLOSING);

        }

        generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.MULTISTATUS, XMLWriter.CLOSING);

        Writer writer = resp.getWriter();
        writer.write(generatedXML.toString());
        writer.close();
    }
}