List of usage examples for org.apache.http.message HeaderGroup HeaderGroup
public HeaderGroup()
From source file:com.apigee.sdk.apm.http.client.cache.HttpCacheEntry.java
/** * Create a new {@link HttpCacheEntry}//from ww w.j a va2s . c om * * @param requestDate * Date/time when the request was made (Used for age * calculations) * @param responseDate * Date/time that the response came back (Used for age * calculations) * @param statusLine * HTTP status line * @param responseHeaders * Header[] from original HTTP Response */ public HttpCacheEntry(final Date requestDate, final Date responseDate, final StatusLine statusLine, final Header[] responseHeaders, final Resource resource, final Set<String> variants) { super(); if (requestDate == null) { throw new IllegalArgumentException("Request date may not be null"); } if (responseDate == null) { throw new IllegalArgumentException("Response date may not be null"); } if (statusLine == null) { throw new IllegalArgumentException("Status line may not be null"); } if (responseHeaders == null) { throw new IllegalArgumentException("Response headers may not be null"); } if (resource == null) { throw new IllegalArgumentException("Resource may not be null"); } this.requestDate = requestDate; this.responseDate = responseDate; this.statusLine = statusLine; this.responseHeaders = new HeaderGroup(); this.responseHeaders.setHeaders(responseHeaders); this.resource = resource; this.variantURIs = variants != null ? new HashSet<String>(variants) : new HashSet<String>(); }
From source file:it.unimi.di.law.warc.io.AbstractWarcReader_NYU.java
protected WarcRecord read(final boolean consecutive) throws IOException { if (consecutive && this.payload != null) { this.payload.consume(); this.payload = null; this.line.clear(); // check WARC version if (!(this.version.getMajor() == 0 && this.version.getMinor() == 18)) { this.buffer.readLine(this.line); this.buffer.readLine(this.line); } else {/*from w ww . j av a2 s .c o m*/ if (!this.skip) { this.buffer.readLine(this.line); this.skip = true; } } if (line.length() != 0) throw new WarcFormatException("Missing CRLFs at WARC record end, got \"" + line + "\""); this.line.clear(); } // first header line this.version = parseHead(); if (this.version == null) return null; if (VERSION && (this.version.getMajor() != 1 || this.version.getMinor() != 0)) throw new IllegalArgumentException("Unsupported WARC version " + this.version); // rest of headers final HeaderGroup warcHeaders = new HeaderGroup(); try { warcHeaders.setHeaders(AbstractMessageParser.parseHeaders(this.buffer, -1, -1, null)); } catch (HttpException e) { throw new WarcFormatException("Can't parse WARC headers", e); } // payload final Header payloadLengthHeader = WarcHeader.getFirstHeader(warcHeaders, WarcHeader.Name.CONTENT_LENGTH); if (payloadLengthHeader == null) throw new WarcFormatException("Missing 'Content-Length' WARC header"); long payloadLength = -1; try { payloadLength = Long.parseLong(payloadLengthHeader.getValue()); } catch (NumberFormatException e) { throw new WarcFormatException( "Can't parse 'Content-Length' WARC header (is \"" + payloadLengthHeader.getValue() + "\")", e); } this.payload = new BoundSessionInputBuffer(this.buffer, payloadLength); return AbstractWarcRecord.fromPayload(warcHeaders, this.payload); }
From source file:org.trancecode.xproc.step.RequestParser.java
private HeaderGroup parseHeaders(final XdmNode requestNode) { final HeaderGroup group = new HeaderGroup(); final Iterable<XdmNode> children = SaxonAxis.childElements(requestNode, XProcXmlModel.Elements.HEADER); for (final XdmNode child : children) { final String nameHeader = child.getAttributeValue(XProcXmlModel.Attributes.NAME); final String valueHeader = child.getAttributeValue(XProcXmlModel.Attributes.VALUE); if (!Strings.isNullOrEmpty(nameHeader) && !Strings.isNullOrEmpty(valueHeader)) { group.addHeader(new BasicHeader(nameHeader, valueHeader)); }/*from w w w.ja v a 2 s . c o m*/ } return group; }
From source file:com.joyent.manta.http.MantaHttpHeaders.java
/** * Converts a key value to a collection of {@link Header} objects. * @param name header name// w w w. j a v a2 s. c o m * @param value header value * @return as list of headers */ private HeaderGroup parseHeaderKeyValue(final String name, final Object value) { HeaderGroup group = new HeaderGroup(); if (value == null) { group.addHeader(new BasicHeader(name, null)); return group; } final Class<?> valueClass = value.getClass(); if (value instanceof Iterable<?>) { Iterable<?> iterable = (Iterable<?>) value; for (Object multiple : iterable) { final Header header = new BasicHeader(name, MantaUtils.asString(multiple)); group.addHeader(header); } } else if (valueClass.isArray()) { Object[] array = (Object[]) value; for (Object multiple : array) { final Header header = new BasicHeader(name, MantaUtils.asString(multiple)); group.addHeader(header); } } else { group.addHeader(new BasicHeader(name, MantaUtils.asString(value))); } return group; }
From source file:org.trancecode.http.BodypartResponseParser.java
public BodypartResponseParser(final InputStream stream, final String boundary, final HttpParams params, final String contentType, final String charset) { this.stream = stream; this.boundary = "--" + boundary; this.params = params; this.contentType = contentType; this.charset = charset; sessionBuffer = new TubularSessionInputBuffer(stream, 4096, params == null ? new BasicHttpParams() : params); this.headers = new HeaderGroup(); }