public boolean returnResponse(int statusCode) { HTTPResponse httpRes = new HTTPResponse(); httpRes.setStatusCode(statusCode); httpRes.setContentLength(0); return post(httpRes); }
public HTTPResponse() { setVersion(HTTP.VERSION_11); setContentType(HTML.CONTENT_TYPE); setServer(HTTPServer.getName()); setContent(""); }
public boolean post(HTTPResponse httpRes, long contentOffset, long contentLength, boolean isOnlyHeader) { //TODO Close if Connection != keep-alive if (httpRes.hasContentInputStream() == true) return post(httpRes,httpRes.getContentInputStream(), contentOffset, contentLength, isOnlyHeader); return post(httpRes,httpRes.getContent(), contentOffset, contentLength, isOnlyHeader); } }
public String toString() { StringBuffer str = new StringBuffer(); str.append(getStatusLineString()); str.append(getHeaderString()); str.append(HTTP.CRLF); str.append(getContentString()); return str.toString(); }
HTTPResponse httpRes = new HTTPResponse(); httpRes.setStatusCode(HTTPStatus.OK); if (contentType != null) { httpRes.setContentType(contentType); httpRes.setContentLanguage(contentLanguage); httpRes.setContent(fileByte);
private boolean post(HTTPResponse httpRes, byte content[], long contentOffset, long contentLength, boolean isOnlyHeader) httpRes.setDate(Calendar.getInstance()); httpRes.setContentLength(contentLength); out.write(httpRes.getHeader().getBytes()); out.write(HTTP.CRLF.getBytes()); if (isOnlyHeader == true) { boolean isChunkedResponse = httpRes.isChunked();
HTTPResponse httpRes = new HTTPResponse(); httpRes.setContentType(contentType); httpRes.setStatusCode(HTTPStatus.OK); httpRes.setContentLength(contentLen); httpRes.setContentInputStream(contentIn);
public HTTPResponse post(String host, int port, boolean isKeepAlive) HTTPResponse httpRes = new HTTPResponse(); httpRes.set(in, isHeaderRequest); } catch (SocketException e) { httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); Debug.warning(e); } catch (IOException e) { httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); Debug.warning(e); } finally {
public void httpRequestRecieved(HTTPRequest httpReq) { String uri = httpReq.getURI(); if (uri.startsWith(PRESENTATION_URI) == false) { super.httpRequestRecieved(httpReq); return; } Clock clock = Clock.getInstance(); String contents = "<HTML><BODY><H1>" + clock.toString() + "</H1></BODY></HTML>"; HTTPResponse httpRes = new HTTPResponse(); httpRes.setStatusCode(HTTPStatus.OK); httpRes.setContent(contents); httpReq.post(httpRes); }
public boolean post(HTTPResponse httpRes) { HTTPSocket httpSock = getSocket(); long offset = 0; long length = httpRes.getContentLength(); if (hasContentRange() == true) { long firstPos = getContentRangeFirstPosition(); long lastPos = getContentRangeLastPosition(); // Thanks for Brent Hills (10/26/04) if (lastPos <= 0) lastPos = length - 1; if ((firstPos > length ) || (lastPos > length)) return returnResponse(HTTPStatus.INVALID_RANGE); httpRes.setContentRange(firstPos, lastPos, length); httpRes.setStatusCode(HTTPStatus.PARTIAL_CONTENT); offset = firstPos; length = lastPos - firstPos + 1; } return httpSock.post(httpRes, offset, length, isHeadRequest()); //httpSock.close(); }
httpReq.setURI(uri); HTTPResponse httpRes = httpReq.post(host, port); if (httpRes.isSuccessful() == false) throw new ParserException("HTTP comunication failed: no answer from peer." + "Unable to retrive resoure -> "+locationURL.toString()); String content = new String(httpRes.getContent()); ByteArrayInputStream strBuf = new ByteArrayInputStream(content.getBytes()); return parse(strBuf);
public int getStatusCode() { if (statusCode != 0) return statusCode; HTTPStatus httpStatus = new HTTPStatus(getFirstLine()); return httpStatus.getStatusCode(); }
HTTPResponse httpRes = new HTTPResponse(); httpRes.setStatusCode(HTTPStatus.OK); if (contentType != null) { httpRes.setContentType(contentType); httpRes.setContentLanguage(contentLanguage); httpRes.setContent(fileByte);
private boolean post(HTTPResponse httpRes, InputStream in, long contentOffset, long contentLength, boolean isOnlyHeader) httpRes.setDate(Calendar.getInstance()); httpRes.setContentLength(contentLength); out.write(httpRes.getHeader().getBytes()); out.write(HTTP.CRLF.getBytes()); boolean isChunkedResponse = httpRes.isChunked();
HTTPResponse httpRes = new HTTPResponse(); httpRes.setContentType(contentType); httpRes.setStatusCode(HTTPStatus.OK); httpRes.setContentLength(contentLen); httpRes.setContentInputStream(contentIn);
public HTTPResponse post(String host, int port, boolean isKeepAlive) HTTPResponse httpRes = new HTTPResponse(); httpRes.set(in, isHeaderRequest); } catch (SocketException e) { httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); Debug.warning(e); } catch (IOException e) { httpRes.setStatusCode(HTTPStatus.INTERNAL_SERVER_ERROR); Debug.warning(e); } finally {
public boolean post(HTTPResponse httpRes) { HTTPSocket httpSock = getSocket(); long offset = 0; long length = httpRes.getContentLength(); if (hasContentRange() == true) { long firstPos = getContentRangeFirstPosition(); long lastPos = getContentRangeLastPosition(); // Thanks for Brent Hills (10/26/04) if (lastPos <= 0) lastPos = length - 1; if ((firstPos > length ) || (lastPos > length)) return returnResponse(HTTPStatus.INVALID_RANGE); httpRes.setContentRange(firstPos, lastPos, length); httpRes.setStatusCode(HTTPStatus.PARTIAL_CONTENT); offset = firstPos; length = lastPos - firstPos + 1; } return httpSock.post(httpRes, offset, length, isHeadRequest()); //httpSock.close(); }
public String toString() { StringBuffer str = new StringBuffer(); str.append(getStatusLineString()); str.append(getHeaderString()); str.append(HTTP.CRLF); str.append(getContentString()); return str.toString(); }
httpReq.setURI(uri); HTTPResponse httpRes = httpReq.post(host, port); if (httpRes.isSuccessful() == false) throw new ParserException("HTTP comunication failed: no answer from peer." + "Unable to retrive resoure -> "+locationURL.toString()); String content = new String(httpRes.getContent()); ByteArrayInputStream strBuf = new ByteArrayInputStream(content.getBytes()); return parse(strBuf);
public int getStatusCode() { if (statusCode != 0) return statusCode; HTTPStatus httpStatus = new HTTPStatus(getFirstLine()); return httpStatus.getStatusCode(); }