Examples of SimpleResponse


Examples of com.betfair.baseline.v2.to.SimpleResponse

    if (dbConnectionStatusDetail != null) {
      ((BaselineMonitor)monitorRegistry.getMonitor("DB"+instance)).setStatus(toStatus(dbConnectionStatusDetail.toString()));
    }

    SimpleResponse response = new SimpleResponse();
    response.setMessage("Health Status Info set for Baseline app.");
    return response;

  }
View Full Code Here

Examples of com.xmage.ws.model.SimpleResponse

* @author noxx
*/
public class SimpleResponseRepresenter implements Representer<SimpleResponse> {

    public JSONObject toJSON(Resource<SimpleResponse> resource) {
        SimpleResponse response = resource.getDefault();

        JSONObject json = new JSONObject();
        json.put("code", response.getCode());
        json.put("message", response.getMessage());

        return json;
    }
View Full Code Here

Examples of fitnesse.http.SimpleResponse

  public void testMakeReponder() throws Exception {
    MockRequest request = new MockRequest();
    request.setResource("PageOne");

    Responder responder = new VersionSelectionResponder();
    SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(root), request);

    String content = response.getContent();
    assertSubString("<a", content);
    assertSubString("?responder=viewVersion", content);
    assertNotSubString("$version", content);
    assertSubString("<h5> Page One tags</h5>", content);
  }
View Full Code Here

Examples of fitnesse.http.SimpleResponse

  @Test
  public void testResponse() throws Exception {
    request.setResource("root");

    SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(root),
        request);
    assertEquals(200, response.getStatus());

    String body = response.getContent();
    assertSubString("<html>", body);
    assertSubString("<form", body);
    assertSubString("method=\"post\"", body);
    assertSubString("name=\"responder\"", body);
    assertSubString("name=\"" + EditResponder.HELP_TEXT + "\"", body);
View Full Code Here

Examples of fitnesse.http.SimpleResponse

    WikiPageUtil.addPage(root, PathParser.parse("TemplateLibrary.TemplateTwo"), "template 2");
    WikiPageUtil.addPage(root, PathParser.parse("ChildPage"), "child content with <html>");

    request.setResource("ChildPage");

    SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(root),
        request);
    assertEquals(200, response.getStatus());

    String body = response.getContent();
    assertSubString("<html>", body);
    assertSubString("<form", body);
    assertSubString("method=\"post\"", body);
    assertSubString("name=\"responder\"", body);
    assertSubString("name=\"" + EditResponder.HELP_TEXT + "\"", body);
View Full Code Here

Examples of fitnesse.http.SimpleResponse

  @Test
  public void shouldSetPageTemplateIfProvidedAsArgument() {
    WikiPageUtil.addPage(root, PathParser.parse("FancyTemplate"), "template page");
    request.setResource("");
    request.addInput(NewPageResponder.PAGE_TEMPLATE, ".FancyTemplate");
    SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(root),
            request);
    assertEquals(200, response.getStatus());

    String body = response.getContent();
    assertSubString("<form", body);
    assertSubString("name=\"" + NewPageResponder.PAGE_TEMPLATE + "\"", body);
    assertSubString("value=\".FancyTemplate\"", body);
  }
View Full Code Here

Examples of fitnesse.http.SimpleResponse

  }

  @Test
  public void testHtml() throws Exception {
    Responder responder = new MergeResponder(request);
    SimpleResponse response = (SimpleResponse) responder.makeResponse(FitNesseUtil.makeTestContext(source), new MockRequest());
    assertHasRegexp("name=\\\"" + EditResponder.CONTENT_INPUT_NAME + "\\\"", response.getContent());
    assertHasRegexp("this is SimplePage", response.getContent());
    assertHasRegexp("name=\\\"oldContent\\\"", response.getContent());
    assertHasRegexp("some new content", response.getContent());
  }
View Full Code Here

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

    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));
            String cookieID = request.getCookieID();
            SessionContext sessionContext = getSessionContext(cookieID);

            msgContext = new MessageContext();
            msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
            msgContext.setConfigurationContext(configurationContext);
            msgContext.setSessionContext(sessionContext);
            msgContext.setTransportIn(configurationContext.getAxisConfiguration().getTransportIn(
                    new QName(Constants.TRANSPORT_HTTP)));
            msgContext.setTransportOut(transportOut);
            msgContext.setServerSide(true);

            HttpVersion ver = request.getRequestLine().getHttpVersion();

            if (ver == null) {
                throw new AxisFault("HTTP version can not be 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 access to the transport information to the transport Sender
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
                    new SimpleHTTPOutTransportInfo(response));
            msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, request.getRequestLine().getUri());


            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())) {
                String uri = request.getRequestLine().getUri();
                log.debug("HTTP GET:" + uri);
                if (uri.equals("/favicon.ico")) {
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 301, "Redirect");
                    response.addHeader(new Header("Location", "http://ws.apache.org/favicon.ico"));
                    conn.writeResponse(response);
                    return true;
                }
                if (!uri.startsWith("/axis2/services/")) {
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 301, "Redirect");
                    response.addHeader(new Header("Location", "/axis2/services/"));
                    conn.writeResponse(response);
                    return true;
                }

                if (uri.indexOf("?") < 0) {
                    if (!(uri.endsWith("/axis2/services/") || uri.endsWith("/axis2/services"))) {
                        String serviceName = uri.replaceAll("/axis2/services/", "");
                        if (serviceName.indexOf("/") < 0) {
                            response.addHeader(new Header("Content-Type", "text/html"));
                            String res = HTTPTransportReceiver.printServiceHTML(serviceName, configurationContext);
                            byte[] buf = res.getBytes();
                            response.setBody(new ByteArrayInputStream(buf));
                            conn.writeResponse(response);
                            return true;
                        }
                    }
                }

                if (uri.endsWith("?wsdl")) {
                    String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 5);
                    HashMap services = configurationContext.getAxisConfiguration().getServices();
                    AxisService service = (AxisService) services.get(serviceName);
                    if (service != null) {
                        response.addHeader(new Header("Content-Type", "text/xml"));
//                        String url = conn.getURL(uri.substring(1, uri.length() - 5));
                        String url = conn.getURL("");
                        int ipindex = url.indexOf("//");
                        String ip = null;
                        if (ipindex >= 0) {
                            ip = url.substring(ipindex + 2, url.length());
                            int seperatorIndex = ip.indexOf(":");
                            if (seperatorIndex > 0) {
                                ip = ip.substring(0, seperatorIndex);
                            }
                        }
                        service.printWSDL(baos, ip);
                        byte[] buf = baos.toByteArray();
                        response.setBody(new ByteArrayInputStream(buf));
                        conn.writeResponse(response);
                        return true;
                    }
                }
                if (uri.endsWith("?xsd")) {
                    String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4);
                    HashMap services = configurationContext.getAxisConfiguration().getServices();
                    AxisService service = (AxisService) services.get(serviceName);
                    if (service != null) {
                        response.addHeader(new Header("Content-Type", "text/xml"));
                        service.printSchema(baos);
                        byte[] buf = baos.toByteArray();
                        response.setBody(new ByteArrayInputStream(buf));
                        conn.writeResponse(response);
                        return true;
                    }
                }

                // 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, msgContext);
                    conn.writeResponse(response);

                    return true;
                }
            } else {
                ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
                byte[]                bytes = new byte[8192];
                int size;

                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());
            }

            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");
            }

            byte[] buf = baos.toByteArray();
            response.setBody(new ByteArrayInputStream(buf));
            setResponseHeaders(conn, request, response, buf.length, msgContext);

            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);
                    byte[] buf = baos.toByteArray();
                    response.setBody(new ByteArrayInputStream(buf));
                    setResponseHeaders(conn, request, response, buf.length, msgContext);
                    conn.writeResponse(response);
                }
            } catch (SocketException e1) {
                log.debug(e1.getMessage(), e1);
View Full Code Here

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

    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));
            String cookieID = request.getCookieID();
            SessionContext sessionContext = getSessionContext(cookieID);

            msgContext = new MessageContext();

            msgContext.setConfigurationContext(configurationContext);
            msgContext.setSessionContext(sessionContext);
            msgContext.setTransportIn(configurationContext.getAxisConfiguration().getTransportIn(
                    new QName(Constants.TRANSPORT_HTTP)));
            msgContext.setTransportOut(transportOut);
            msgContext.setServerSide(true);

            HttpVersion ver = request.getRequestLine().getHttpVersion();

            if (ver == null) {
                throw new AxisFault("HTTP version can not be 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 access to the transport information to the transport Sender
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
                    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())) {
                String uri = request.getRequestLine().getUri();
                log.debug("HTTP GET:" + uri);
                if (uri.equals("/favicon.ico")) {
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 301, "Redirect");
                    response.addHeader(new Header("Location", "http://ws.apache.org/favicon.ico"));
                    conn.writeResponse(response);
                    return true;
                }
                if (!uri.startsWith("/axis2/services/")) {
                    response.setStatusLine(request.getRequestLine().getHttpVersion(), 301, "Redirect");
                    response.addHeader(new Header("Location", "/axis2/services/"));
                    conn.writeResponse(response);
                    return true;
                }

                if (uri.endsWith("?wsdl")) {
                    String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 5);
                    HashMap services = configurationContext.getAxisConfiguration().getServices();
                    AxisService service = (AxisService) services.get(serviceName);
                    if (service != null) {
                        response.addHeader(new Header("Content-Type", "text/xml"));
                        String url = conn.getURL(uri.substring(1, uri.length() - 5));
                        service.printWSDL(baos, url);
                        byte[] buf = baos.toByteArray();
                        response.setBody(new ByteArrayInputStream(buf));
                        conn.writeResponse(response);
                        return true;
                    }
                }
                if (uri.endsWith("?xsd")) {
                    String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4);
                    HashMap services = configurationContext.getAxisConfiguration().getServices();
                    AxisService service = (AxisService) services.get(serviceName);
                    if (service != null) {
                        response.addHeader(new Header("Content-Type", "text/xml"));
                        service.printSchema(baos);
                        byte[] buf = baos.toByteArray();
                        response.setBody(new ByteArrayInputStream(buf));
                        conn.writeResponse(response);
                        return true;
                    }
                }

                // 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, msgContext);
                    conn.writeResponse(response);

                    return true;
                }
            } else {
                ByteArrayOutputStream baosIn = new ByteArrayOutputStream();
                byte[]                bytes = new byte[8192];
                int size;

                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());
            }

            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");
            }

            byte[] buf = baos.toByteArray();
            response.setBody(new ByteArrayInputStream(buf));
            setResponseHeaders(conn, request, response, buf.length, msgContext);

            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);
                    byte[] buf = baos.toByteArray();
                    response.setBody(new ByteArrayInputStream(buf));
                    setResponseHeaders(conn, request, response, buf.length, msgContext);
                    conn.writeResponse(response);
                }
            } catch (SocketException e1) {
                log.debug(e1.getMessage(), e1);
View Full Code Here

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.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);
            }
            response.setStatusLine(request.getRequestLine().getHttpVersion(), 200, "OK");
            response.setBody(new ByteArrayInputStream(baos.toByteArray()));
            setResponseHeaders(conn, request, response,baos.toByteArray().length);
            conn.writeResponse(response);
        } catch (Throwable 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);
                } else {
                    log.error(e, e);
                }
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.