Examples of SimpleResponse


Examples of org.apache.axis2.transport.http.server.SimpleResponse

        this.configurationContext = configurationContext;
    }

    public boolean processRequest(final SimpleHttpServerConnection conn, final SimpleRequest request) throws IOException {
        MessageContext msgContext = null;
        SimpleResponse response = new SimpleResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        try {
            if (configurationContext == null) {
                throw new AxisFault(Messages.getMessage("cannotBeNullConfigurationContext"));
            }

            InputStream inStream = request.getBody();

            TransportOutDescription transportOut =
                    configurationContext.getAxisConfiguration().getTransportOut(
                            new QName(Constants.TRANSPORT_HTTP));
            msgContext =
                    new MessageContext(
                            configurationContext,
                            configurationContext.getAxisConfiguration().getTransportIn(
                                    new QName(Constants.TRANSPORT_HTTP)),
                            transportOut);
            msgContext.setServerSide(true);

            HttpVersion ver = request.getRequestLine().getHttpVersion();
            if (ver == null) {
                throw new AxisFault("HTTP version can not be Null");
            }
            String httpVersion = null;
            if (HttpVersion.HTTP_1_0.equals(ver)) {
                httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
            } else if (HttpVersion.HTTP_1_1.equals(ver)) {
                httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
                /**
                 * Transport Sender configuration via axis2.xml
                 */
                this.transportOutConfiguration(configurationContext,response);
            } else {
                throw new AxisFault("Unknown supported protocol version " + ver);
            }


            msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);

            //set the transport Headers
            msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, getHeaders(request));
            msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());

            //This is way to provide Accsess to the transport information to the transport Sender
            msgContext.setProperty(
                    HTTPConstants.HTTPOutTransportInfo,
                    new SimpleHTTPOutTransportInfo(response));

            String soapAction = null;
            if (request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION) != null) {
                soapAction = request.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION).getValue();
            }
            if (HTTPConstants.HEADER_GET.equals(request.getRequestLine().getMethod())) {
                //It is GET handle the Get request
                boolean processed =
                        HTTPTransportUtils.processHTTPGetRequest(
                                msgContext,
                                inStream,
                                baos,
                                request.getContentType(),
                                soapAction,
                                request.getRequestLine().getUri(),
                                configurationContext,
                                HTTPTransportReceiver.getGetRequestParameters(
                                        request.getRequestLine().getUri()));
                if (!processed) {
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
                    response.addHeader(new Header("Content-Type", "text/html"));
                    response.setBodyString(HTTPTransportReceiver.getServicesHTML(configurationContext));
                    setResponseHeaders(conn, request, response,0);
                    conn.writeResponse(response);
                    return true;
                }
            } else {
                ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
                byte[] bytes = new byte[8192];
                int size = 0;
                while ((size = inStream.read(bytes)) > 0) {
                    baosIn.write(bytes, 0, size);
                }
                inStream = new ByteArrayInputStream(baosIn.toByteArray());

                //It is POST, handle it
                HTTPTransportUtils.processHTTPPostRequest(
                        msgContext,
                        inStream,
                        baos,
                        request.getContentType(),
                        soapAction,
                        request.getRequestLine().getUri(),
                        configurationContext);
            }

            OperationContext operationContext = msgContext.getOperationContext();

            Object contextWritten = null;
            if (operationContext!=null)
                contextWritten = operationContext.getProperty(Constants.RESPONSE_WRITTEN);

            if (contextWritten != null &&
                    Constants.VALUE_TRUE.equals(contextWritten)) {
                response.setStatusLine(
                        request.getRequestLine().getHttpVersion(), 200, "OK");
            } else {
                response.setStatusLine(
                        request.getRequestLine().getHttpVersion(), 202, "OK");
            }
            response.setBody(new ByteArrayInputStream(baos.toByteArray()));
            setResponseHeaders(conn, request, response,
                    baos.toByteArray().length);
            conn.writeResponse(response);
        } catch (Throwable e) {
            if(!(e instanceof java.net.SocketException)) {
                log.debug(e.getMessage(), e);
            }
            try {
                AxisEngine engine = new AxisEngine(configurationContext);
                if (msgContext != null) {
                    msgContext.setProperty(MessageContext.TRANSPORT_OUT, baos);
                    MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 500, "Internal server error");
                    engine.sendFault(faultContext);
                    response.setBody(new ByteArrayInputStream(baos.toByteArray()));
                    setResponseHeaders(conn, request, response,baos.toByteArray().length);
                    conn.writeResponse(response);
                }
            } catch (SocketException e1) {
                log.debug(e1.getMessage(), e1);
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

                    final SimpleRequest request) throws IOException {

                // Make sure the request if fully consumed
                request.getBodyBytes();
               
                SimpleResponse response = new SimpleResponse();
                response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
                response.setBodyString("stuff back");

                conn.setKeepAlive(true);
                conn.writeResponse(response);
               
                return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

                    final SimpleRequest request) throws IOException {

                // Make sure the request if fully consumed
                request.getBodyBytes();
               
                SimpleResponse response = new SimpleResponse();
                response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
                response.setBodyString("stuff back");

                conn.setKeepAlive(true);
                conn.writeResponse(response);
               
                return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

                    final SimpleRequest request) throws IOException {

                // Make sure the request if fully consumed
                request.getBodyBytes();
               
                SimpleResponse response = new SimpleResponse();
                response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
                response.setBodyString("stuff back");

                conn.setKeepAlive(true);
                conn.writeResponse(response);
               
                return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

            {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (ver.equals(HttpVersion.HTTP_1_0)) {
                    return false;
                } else {
                    SimpleResponse response = new SimpleResponse();
                    response.setStatusLine(ver, HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
                    response.addHeader(new Header("Proxy-Connection", "close"));
                    conn.setKeepAlive(false);
                    // Make sure the request body is fully consumed
                    request.getBodyBytes();
                    conn.writeResponse(response);
                    return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

            {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (ver.equals(HttpVersion.HTTP_1_0)) {
                    return false;
                } else {
                    SimpleResponse response = new SimpleResponse();
                    response.setStatusLine(ver, HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
                    response.addHeader(new Header("Proxy-Connection", "close"));
                    conn.setKeepAlive(false);
                    // Make sure the request body is fully consumed
                    request.getBodyBytes();
                    conn.writeResponse(response);
                    return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

                    final SimpleRequest request) throws IOException {

                // Make sure the request if fully consumed
                request.getBodyBytes();
               
                SimpleResponse response = new SimpleResponse();
                response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
                response.setBodyString("stuff back");

                conn.setKeepAlive(true);
                conn.writeResponse(response);
               
                return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

            {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (ver.equals(HttpVersion.HTTP_1_0)) {
                    return false;
                } else {
                    SimpleResponse response = new SimpleResponse();
                    response.setStatusLine(ver, HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
                    response.addHeader(new Header("Proxy-Connection", "close"));
                    conn.setKeepAlive(false);
                    // Make sure the request body is fully consumed
                    request.getBodyBytes();
                    conn.writeResponse(response);
                    return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

                    final SimpleRequest request) throws IOException {

                // Make sure the request if fully consumed
                request.getBodyBytes();
               
                SimpleResponse response = new SimpleResponse();
                response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK);
                response.setBodyString("stuff back");

                conn.setKeepAlive(true);
                conn.writeResponse(response);
               
                return true;
View Full Code Here

Examples of org.apache.commons.httpclient.server.SimpleResponse

            {
                HttpVersion ver = request.getRequestLine().getHttpVersion();
                if (ver.equals(HttpVersion.HTTP_1_0)) {
                    return false;
                } else {
                    SimpleResponse response = new SimpleResponse();
                    response.setStatusLine(ver, HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
                    response.addHeader(new Header("Proxy-Connection", "close"));
                    conn.setKeepAlive(false);
                    // Make sure the request body is fully consumed
                    request.getBodyBytes();
                    conn.writeResponse(response);
                    return true;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.