List of usage examples for org.apache.http.message BasicLineParser DEFAULT
BasicLineParser DEFAULT
To view the source code for org.apache.http.message BasicLineParser DEFAULT.
Click Source Link
From source file:net.oneandone.sushi.fs.webdav.MultiStatus.java
private static void fromXml(Element response, List<MultiStatus> result) throws IOException { Element href;// w w w .j av a 2 s. com 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:org.vietspider.net.apache.DefaultResponseParser.java
public DefaultResponseParser(final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { if (buffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); }//from w ww. j a v a 2s . c o m if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this._sessionBuffer = buffer; // this.timeoutSocket = params.getBooleanParameter("vietspider.socket.timeout", false); this.maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT; if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); this.maxGarbageLines = params.getIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, Integer.MAX_VALUE); }
From source file:org.vietspider.net.apache.DefaultResponseParser.java
public static Header[] parseHeaders(final SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, LineParser parser) throws HttpException, IOException { if (inbuffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); }//from w ww.j av a 2 s . c o m if (parser == null) parser = BasicLineParser.DEFAULT; ArrayList<CharArrayBuffer> headerLines = new ArrayList<CharArrayBuffer>(); CharArrayBuffer current = null; CharArrayBuffer previous = null; for (;;) { if (current == null) { current = new CharArrayBuffer(64); } else { current.clear(); } int l = inbuffer.readLine(current); if (l == -1 || current.length() < 1) { break; } // Parse the header name and value // Check for folded headers first // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2 // discussion on folded headers if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) { // we have continuation folded header // so append value int i = 0; while (i < current.length()) { char ch = current.charAt(i); if (ch != ' ' && ch != '\t') { break; } i++; } if (maxLineLen > 0 && previous.length() + 1 + current.length() - i > maxLineLen) { throw new IOException("Maximum line length limit exceeded"); } previous.append(' '); previous.append(current, i, current.length() - i); } else { headerLines.add(current); previous = current; current = null; } if (maxHeaderCount > 0 && headerLines.size() >= maxHeaderCount) { throw new IOException("Maximum header count exceeded"); } } Header[] headers = new Header[headerLines.size()]; for (int i = 0; i < headerLines.size(); i++) { CharArrayBuffer buffer = headerLines.get(i); try { headers[i] = parser.parseHeader(buffer); } catch (ParseException ex) { throw new ProtocolException(ex.getMessage()); } } return headers; }
From source file:org.mycard.net.network.AndroidHttpClientConnection.java
/*** * Parses the response headers and adds them to the * given {@code headers} object, and returns the response StatusLine * @param headers store parsed header to headers. * @throws IOException/*from w w w . jav a2s . c o m*/ * @return StatusLine * @see HttpClientConnection#receiveResponseHeader() */ public StatusLine parseResponseHeader(Headers headers) throws IOException, ParseException { assertOpen(); CharArrayBuffer current = new CharArrayBuffer(64); if (inbuffer.readLine(current) == -1) { throw new NoHttpResponseException("The target server failed to respond"); } // Create the status line from the status string StatusLine statusline = BasicLineParser.DEFAULT.parseStatusLine(current, new ParserCursor(0, current.length())); //if (HttpLog.LOGV) HttpLog.v("read: " + statusline); int statusCode = statusline.getStatusCode(); // Parse header body CharArrayBuffer previous = null; int headerNumber = 0; while (true) { if (current == null) { current = new CharArrayBuffer(64); } else { // This must be he buffer used to parse the status current.clear(); } int l = inbuffer.readLine(current); if (l == -1 || current.length() < 1) { break; } // Parse the header name and value // Check for folded headers first // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2 // discussion on folded headers char first = current.charAt(0); if ((first == ' ' || first == '\t') && previous != null) { // we have continuation folded header // so append value int start = 0; int length = current.length(); while (start < length) { char ch = current.charAt(start); if (ch != ' ' && ch != '\t') { break; } start++; } if (maxLineLength > 0 && previous.length() + 1 + current.length() - start > maxLineLength) { throw new IOException("Maximum line length limit exceeded"); } previous.append(' '); previous.append(current, start, current.length() - start); } else { if (previous != null) { headers.parseHeader(previous); } headerNumber++; previous = current; current = null; } if (maxHeaderCount > 0 && headerNumber >= maxHeaderCount) { throw new IOException("Maximum header count exceeded"); } } if (previous != null) { headers.parseHeader(previous); } if (statusCode >= 200) { this.metrics.incrementResponseCount(); } return statusline; }