Example usage for org.apache.http.message BasicLineParser parseStatusLine

List of usage examples for org.apache.http.message BasicLineParser parseStatusLine

Introduction

In this page you can find the example usage for org.apache.http.message BasicLineParser parseStatusLine.

Prototype

public StatusLine parseStatusLine(CharArrayBuffer charArrayBuffer, ParserCursor parserCursor)
            throws ParseException 

Source Link

Usage

From source file:net.oneandone.sushi.fs.webdav.MultiStatus.java

private static void fromXml(Element response, List<MultiStatus> result) throws IOException {
    Element href;//from  w  w w  . j  a v  a2s . co  m
    String str;
    ChildElements iter;
    Element propstat;
    String propstatStatus;
    Element prop;
    int status;
    ChildElements propIter;

    Dom.require(response, Method.XML_RESPONSE, Method.DAV);
    href = Dom.getFirstChildElement(response, "href", Method.DAV);
    if (href == null) {
        throw new IOException("missing href");
    }
    str = Dom.getString(href).trim();
    iter = Method.DAV.childElements(response, XML_PROPSTAT);
    while (iter.hasNext()) {
        propstat = iter.next();
        propstatStatus = Dom.getString(Dom.getFirstChildElement(propstat, XML_STATUS, Method.DAV));
        prop = Dom.getFirstChildElement(propstat, Method.XML_PROP, Method.DAV);
        status = BasicLineParser.parseStatusLine(propstatStatus, BasicLineParser.DEFAULT).getStatusCode();
        propIter = new ChildElements(prop);
        while (propIter.hasNext()) {
            result.add(new MultiStatus(str, Property.fromXml(propIter.next()), status));
        }
    }
}

From source file:at.bitfire.davdroid.webdav.WebDavCollection.java

protected void processMultiStatus(DavMultistatus multistatus) throws HttpException {
    List<WebDavResource> members = new LinkedList<WebDavResource>();

    if (multistatus.response == null) // empty response
        return;//from   w w  w .  jav a2 s  .c  o m

    for (DavResponse singleResponse : multistatus.response) {
        String href = singleResponse.getHref().href;

        for (DavPropstat singlePropstat : singleResponse.getPropstat()) {
            StatusLine status = BasicLineParser.parseStatusLine(singlePropstat.status, new BasicLineParser());

            try {
                checkResponse(status);
            } catch (NotFoundException e) {
                continue;
            }

            WebDavResource referenced = null;

            if (location.equals(location.resolve(href))) {
                // response is about this property
                referenced = this;

            } else {
                // response is about a member, add it
                URI uri = location.resolve(href);
                referenced = new WebDavResource(this, uri);
                members.add(referenced);
            }

            DavProp prop = singlePropstat.prop;

            if (prop.currentUserPrincipal != null)
                referenced.properties.put(Property.CURRENT_USER_PRINCIPAL,
                        prop.currentUserPrincipal.getHref().href);

            if (prop.addressbookHomeSet != null)
                referenced.properties.put(Property.ADDRESSBOOK_HOMESET, prop.addressbookHomeSet.getHref().href);

            if (singlePropstat.prop.calendarHomeSet != null)
                referenced.properties.put(Property.CALENDAR_HOMESET, prop.calendarHomeSet.getHref().href);

            if (prop.displayname != null)
                referenced.properties.put(Property.DISPLAY_NAME, prop.displayname.getDisplayName());

            if (prop.resourcetype != null) {
                if (prop.resourcetype.getAddressbook() != null) {
                    referenced.properties.put(Property.IS_ADDRESSBOOK, "1");

                    if (prop.addressbookDescription != null)
                        referenced.properties.put(Property.DESCRIPTION,
                                prop.addressbookDescription.getDescription());
                } else
                    referenced.properties.remove(Property.IS_ADDRESSBOOK);

                if (prop.resourcetype.getCalendar() != null) {
                    referenced.properties.put(Property.IS_CALENDAR, "1");

                    if (prop.calendarDescription != null)
                        referenced.properties.put(Property.DESCRIPTION,
                                prop.calendarDescription.getDescription());
                } else
                    referenced.properties.remove(Property.IS_CALENDAR);
            }

            if (prop.getctag != null)
                referenced.properties.put(Property.CTAG, prop.getctag.getCTag());

            if (prop.getetag != null)
                referenced.properties.put(Property.ETAG, prop.getetag.getETag());

            if (prop.calendarData != null)
                referenced.content = new ByteArrayInputStream(prop.calendarData.ical.getBytes());
            else if (prop.addressData != null)
                referenced.content = new ByteArrayInputStream(prop.addressData.vcard.getBytes());
        }
    }
    this.members = members;
}

From source file:com.github.sardine.DavResource.java

/**
 * Retrieves the status code portion of the Response's <CODE>status</CODE> element.
 * If it is not present, returns {@link #DEFAULT_STATUS_CODE} (a.k.a. <CODE>200</CODE>).
 *
 * @param response The response complex type of the multistatus
 * @return DEFAULT_STATUS_CODE if not found in response; -1 if status line was malformed
 *///ww  w. j av  a 2  s  .  co  m
private int getStatusCode(Response response) {
    String status = response.getStatus();
    if (status == null || status.isEmpty()) {
        return DEFAULT_STATUS_CODE;
    }
    try {
        return BasicLineParser.parseStatusLine(response.getStatus(), null).getStatusCode();
    } catch (ParseException e) {
        log.warning(String.format("Failed to parse status line: %s", status));
        return -1;
    }
}

From source file:net.hiroq.rxwsc.RxWebSocketClient.java

/**
 * Parse HttpStatusLine//from  w  ww  .ja  va 2  s.c  o m
 *
 * @param line
 * @return
 */
private StatusLine parseStatusLine(String line) {
    if (TextUtils.isEmpty(line)) {
        return null;
    }
    return BasicLineParser.parseStatusLine(line, new BasicLineParser());
}

From source file:com.irccloud.android.HTTPFetcher.java

private StatusLine parseStatusLine(String line) {
    if (TextUtils.isEmpty(line)) {
        return null;
    }/*  ww w. j a v  a2  s  .  c om*/
    return BasicLineParser.parseStatusLine(line, new BasicLineParser());
}

From source file:com.appunite.websocket.WebSocket.java

/**
 * Read headers from connection input stream, parse them and ensure that
 * everything is correct. (not thread safe)
 * //  w  ww  .j  a  va2s  . c o m
 * @param key
 *            - string sent by client to server
 * @throws IOException
 *             - throw when connection was broken
 * @throws WrongWebsocketResponse
 *             - throw when wrong response was given from server (hanshake
 *             error)
 */
private void readHandshakeHeaders(String key) throws IOException, WrongWebsocketResponse {
    // schould get response:
    // HTTP/1.1 101 Switching Protocols
    // Upgrade: websocket
    // Connection: Upgrade
    // Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
    StatusLine statusLine;
    List<Header> headers = Lists.newArrayList();
    try {
        String statusLineStr = mInputStream.readLine();
        if (TextUtils.isEmpty(statusLineStr)) {
            throw new WrongWebsocketResponse("Wrong HTTP response status line");
        }
        statusLine = BasicLineParser.parseStatusLine(statusLineStr, null);
        for (;;) {
            String headerLineStr = mInputStream.readLine();
            if (TextUtils.isEmpty(headerLineStr))
                break;
            Header header = BasicLineParser.parseHeader(headerLineStr, null);
            headers.add(header);
        }
    } catch (ParseException e) {
        throw new WrongWebsocketResponse("Wrong HTTP response", e);
    }

    verifyHandshakeStatusLine(statusLine);
    verifyHanshakeHeaders(key, headers);
}