public HttpMessage parse() throws HttpException, IOException { // if (!isReadyForParsing()) { // throw new IllegalArgumentException( // "not ready for parsing, some packets are out-of-order"); // } if (log.isDebugEnabled()) { log.debug("parsing stream: " + key); } // byte[] data = getDataAsBuffer().buffer(); byte[] data = getDataAsBuffer().toByteArray(); SessionInputBuffer input = new SessionInputBufferMockup(data); HttpMessage msg = null; switch (type) { case TYPE_REQUEST: HttpRequestParser requestParser = new HttpRequestParser(input, lineParser, requestFactory, new BasicHttpParams()); msg = requestParser.parse(); break; case TYPE_RESPONSE: HttpResponseParser responseParser = new HttpResponseParser(input, lineParser, responseFactory, new BasicHttpParams()); msg = responseParser.parse(); ((HttpResponse) msg).setEntity(entityDeserializer.deserialize(input, msg)); break; } return msg; }
public AxisHttpConnectionImpl(final Socket socket, final HttpParams params) throws IOException { super(); if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } int buffersize = HttpConnectionParams.getSocketBufferSize(params); this.socket = socket; this.outbuffer = new SocketOutputBuffer(socket, buffersize, params); this.inbuffer = new SocketInputBuffer(socket, buffersize, params); this.contentLenStrategy = new StrictContentLengthStrategy(); this.requestParser = new HttpRequestParser( this.inbuffer, null, new DefaultHttpRequestFactory(), params); this.responseWriter = new HttpResponseWriter( this.outbuffer, null, params); }
private HttpMessage getHttpMessage(final byte[] data) { final HttpParams httpParams = new BasicHttpParams(); final AbstractSessionInputBuffer inputBuffer = new AbstractSessionInputBuffer() { { init(new ByteArrayInputStream(data), 128, httpParams); } @Override public boolean isDataAvailable(int i) throws IOException { return this.hasBufferedData(); } }; final HttpRequestFactory msearchRequestFactory = new HttpRequestFactory() { @Override public HttpRequest newHttpRequest(RequestLine requestLine) throws MethodNotSupportedException { if (!requestLine.getMethod().equalsIgnoreCase("m-search")) throw new MethodNotSupportedException("Invalid method: " + requestLine.getMethod()); if (!requestLine.getUri().equals("*")) throw new MethodNotSupportedException("Invalid URI: " + requestLine.getUri()); return new BasicHttpRequest(requestLine); } @Override public HttpRequest newHttpRequest(String method, String uri) throws MethodNotSupportedException { if (!method.equalsIgnoreCase("m-search")) throw new MethodNotSupportedException("Invalid method: " + method); if (!uri.equals("*")) throw new MethodNotSupportedException("Invalid URI: " + uri); return new BasicHttpRequest(method, uri); } }; HttpRequestParser requestParser = new HttpRequestParser(inputBuffer, null, msearchRequestFactory, httpParams); try { return requestParser.parse(); } catch (Exception e) { e.printStackTrace(); } return null; }