Search in sources :

Example 11 with Response

use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.

the class HttpUtil method createResponse.

public static Response createResponse(int code, String msg, byte[] body, String contentType, String... headers) {
    Response res = new Response();
    res.setStatusCode(code);
    res.setStatusMessage(msg);
    res.setHeader(createHeaders(contentType, headers));
    if (body != null)
        res.setBodyContent(body);
    return res;
}
Also used : Response(com.predic8.membrane.core.http.Response)

Example 12 with Response

use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.

the class HttpUtil method createSOAPValidationErrorResponse.

public static Response createSOAPValidationErrorResponse(String message) {
    Response response = new Response();
    response.setStatusCode(400);
    response.setStatusMessage("Bad request");
    response.setHeader(createHeaders(MimeType.TEXT_XML_UTF8));
    response.setBodyContent(getFaultSOAPBody(message).getBytes(Constants.UTF_8_CHARSET));
    return response;
}
Also used : Response(com.predic8.membrane.core.http.Response)

Example 13 with Response

use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.

the class HttpServletHandler method writeResponse.

@SuppressWarnings("deprecation")
protected void writeResponse(Response res) throws Exception {
    response.setStatus(res.getStatusCode(), res.getStatusMessage());
    for (HeaderField header : res.getHeader().getAllHeaderFields()) {
        if (header.getHeaderName().equals(Header.TRANSFER_ENCODING))
            continue;
        response.addHeader(header.getHeaderName().toString(), header.getValue());
    }
    ServletOutputStream out = response.getOutputStream();
    res.getBody().write(new PlainBodyTransferrer(out));
    out.flush();
    response.flushBuffer();
    exchange.setTimeResSent(System.currentTimeMillis());
    exchange.collectStatistics();
}
Also used : HeaderField(com.predic8.membrane.core.http.HeaderField) ServletOutputStream(javax.servlet.ServletOutputStream) PlainBodyTransferrer(com.predic8.membrane.core.http.PlainBodyTransferrer)

Example 14 with Response

use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.

the class LBNotificationClient method notifiyClusterManager.

private Response notifiyClusterManager() throws Exception {
    HttpClient client = new HttpClient();
    Exchange exc = new Exchange(null);
    Request r = MessageUtil.getPostRequest(getRequestURL());
    r.setBodyContent(new byte[0]);
    exc.setRequest(r);
    exc.getDestinations().add(getRequestURL());
    Response res = client.call(exc).getResponse();
    return res;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request)

Example 15 with Response

use of com.predic8.membrane.core.http.Response in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleNodeSessionsRequest.

@Mapping("/admin/node/sessions/?(\\?.*)?")
public Response handleNodeSessionsRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_LOAD_BALANCING;
        }

        @Override
        protected void createTabContent() throws Exception {
            h2().text("Node " + params.get("host") + ":" + params.get("port")).end();
            h3().text("Sessions").end();
            createSessionsTable(BalancerUtil.lookupBalancer(router, getBalancerParam(params)).getSessionsByNode(params.get("cluster"), new Node(params.get("host"), Integer.parseInt(params.get("port")))));
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Aggregations

Response (com.predic8.membrane.core.http.Response)29 Exchange (com.predic8.membrane.core.exchange.Exchange)14 IOException (java.io.IOException)14 StringWriter (java.io.StringWriter)9 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 Request (com.predic8.membrane.core.http.Request)7 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)6 Header (com.predic8.membrane.core.http.Header)6 Test (org.junit.Test)6 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)4 Message (com.predic8.membrane.core.http.Message)4 JSONContent (com.predic8.membrane.core.interceptor.rest.JSONContent)4 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)4 SQLException (java.sql.SQLException)4 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 MCElement (com.predic8.membrane.annot.MCElement)3 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)3