Package org.apache.mina.http.api

Examples of org.apache.mina.http.api.DefaultHttpResponse


            String strContent = "Hello ! we reply to request !";
            ByteBuffer content = ByteBuffer.wrap(strContent.getBytes());

            // compute content len
            headers.put("Content-Length", String.valueOf(content.remaining()));
            session.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SUCCESS_OK, headers));
            session.write(new HttpContentChunk(content));
            session.write(new HttpEndOfContent());
            session.close(false);

        }
View Full Code Here


            String strContent = "Hello ! we reply to request !";
            ByteBuffer content = ByteBuffer.wrap(strContent.getBytes());

            // compute content len
            headers.put("Content-Length", String.valueOf(content.remaining()));
            session.write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SUCCESS_OK, headers));
            session.write(content);
            session.write(new HttpEndOfContent());
        }
View Full Code Here

            IoBuffer.allocate(oldBuffer.remaining() + msg.remaining()).put(oldBuffer).put(msg).flip();
            // now let's decode like it was a new message

        case NEW:
            LOG.debug("decoding NEW");
            final DefaultHttpResponse rp = parseHttpReponseHead(msg.buf());

            if (rp == null) {
                // we copy the incoming BB because it's going to be recycled by the inner IoProcessor for next reads
                final ByteBuffer partial = ByteBuffer.allocate(msg.remaining());
                partial.put(msg.buf());
                partial.flip();
                // no request decoded, we accumulate
                session.setAttribute(PARTIAL_HEAD_ATT, partial);
                session.setAttribute(DECODER_STATE_ATT, DecoderState.HEAD);
            } else {
                out.write(rp);
                // is it a response with some body content ?
                LOG.debug("response with content");
                session.setAttribute(DECODER_STATE_ATT, DecoderState.BODY);

                final String contentLen = rp.getHeader("content-length");

                if (contentLen != null) {
                    LOG.debug("found content len : {}", contentLen);
                    session.setAttribute(BODY_REMAINING_BYTES, Integer.valueOf(contentLen));
                } else if ("chunked".equalsIgnoreCase(rp.getHeader("transfer-encoding"))) {
                    LOG.debug("no content len but chunked");
                    session.setAttribute(BODY_CHUNKED, Boolean.valueOf("true"));
                } else if ("close".equalsIgnoreCase(rp.getHeader("connection"))) {
                    session.close(true);
                } else {
                    throw new HttpException(HttpStatus.CLIENT_ERROR_LENGTH_REQUIRED, "no content length !");
                }
            }
View Full Code Here

        final HttpVersion version = HttpVersion.fromString(elements[0]);

        // we put the buffer position where we found the beginning of the HTTP body
        buffer.position(headersAndBody[0].length() + 4);

        return new DefaultHttpResponse(version, status, generalHeaders);
    }
View Full Code Here

            IoBuffer.allocate(oldBuffer.remaining() + msg.remaining()).put(oldBuffer).put(msg).flip();
            // now let's decode like it was a new message

        case NEW:
            LOG.debug("decoding NEW");
            final DefaultHttpResponse rp = parseHttpReponseHead(msg.buf());

            if (rp == null) {
                // we copy the incoming BB because it's going to be recycled by the inner IoProcessor for next reads
                final ByteBuffer partial = ByteBuffer.allocate(msg.remaining());
                partial.put(msg.buf());
                partial.flip();
                // no request decoded, we accumulate
                session.setAttribute(PARTIAL_HEAD_ATT, partial);
                session.setAttribute(DECODER_STATE_ATT, DecoderState.HEAD);
            } else {
              out.write(rp);
                // is it a response with some body content ?
                LOG.debug("response with content");
                session.setAttribute(DECODER_STATE_ATT, DecoderState.BODY);

                final String contentLen = rp.getHeader("content-length");

                if (contentLen != null) {
                    LOG.debug("found content len : {}", contentLen);
                    session.setAttribute(BODY_REMAINING_BYTES, Integer.valueOf(contentLen));
                } else if ("chunked".equalsIgnoreCase(rp.getHeader("transfer-encoding"))) {
                    LOG.debug("no content len but chunked");
                    session.setAttribute(BODY_CHUNKED, Boolean.valueOf("true"));
                } else if ("close".equalsIgnoreCase(rp.getHeader("connection"))) {
                  session.close(true);
                } else {
                    throw new HttpException(HttpStatus.CLIENT_ERROR_LENGTH_REQUIRED, "no content length !");
                }
            }
View Full Code Here

        final HttpVersion version = HttpVersion.fromString(elements[0]);

        // we put the buffer position where we found the beginning of the HTTP body
        buffer.position(headersAndBody[0].length() + 4);

        return new DefaultHttpResponse(version, status, generalHeaders);
    }
View Full Code Here

TOP

Related Classes of org.apache.mina.http.api.DefaultHttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.