Search in sources :

Example 16 with Header

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

the class LargeBodyTest method largeChunked.

@Test
public void largeChunked() throws Exception {
    setup();
    long len = Integer.MAX_VALUE + 1l;
    Exchange e = new Request.Builder().post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange();
    new HttpClient(hcc).call(e);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Test(org.junit.Test)

Example 17 with Header

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

the class HttpUtil method createHeaders.

public static Header createHeaders(String contentType, String... headers) {
    Header header = new Header();
    if (contentType != null)
        header.setContentType(contentType);
    synchronized (GMT_DATE_FORMAT) {
        header.add("Date", GMT_DATE_FORMAT.format(new Date()));
    }
    header.add("Server", Constants.PRODUCT_NAME + " " + Constants.VERSION + ". See http://membrane-soa.org");
    header.add("Connection", Header.CLOSE);
    for (int i = 0; i < headers.length; i += 2) {
        header.add(headers[i], headers[i + 1]);
    }
    return header;
}
Also used : Header(com.predic8.membrane.core.http.Header) Date(java.util.Date)

Example 18 with Header

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

the class GroovyTest method test.

@Test
public void test() throws IOException, InterruptedException {
    Process2 sl = new Process2.Builder().in(getExampleDir("groovy")).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent groovyCalled = new SubstringWaitableConsoleEvent(sl, "X-Groovy header added with value :Groovy interceptor");
        getAndAssert200("http://localhost:2000/");
        assertTrue(groovyCalled.occurred());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) SubstringWaitableConsoleEvent(com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent) Test(org.junit.Test)

Example 19 with Header

use of com.predic8.membrane.core.http.Header 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 20 with Header

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

the class RoutingTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File base = getExampleDir("versioning/routing");
    String[] header = new String[] { "Content-Type", "text/xml" };
    String request_v11 = FileUtils.readFileToString(new File(base, "request_v11.xml"));
    String request_v20 = FileUtils.readFileToString(new File(base, "request_v20.xml"));
    replaceInFile(new File(base, "proxies.xml"), "8080", "3024");
    replaceInFile(new File(base, "proxies.xml"), "2000", "3025");
    replaceInFile(new File(base, "src/com/predic8/contactservice/Launcher.java"), "8080", "3024");
    Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start();
    try {
        Process2 antNode1 = new Process2.Builder().in(base).waitAfterStartFor("run:").executable("ant run").start();
        try {
            // wait for Endpoints to start
            Thread.sleep(2000);
            // directly talk to versioned endpoints
            assertContains("1.1", postAndAssert(200, "http://localhost:3024/ContactService/v11", header, request_v11));
            assertContains("2.0", postAndAssert(200, "http://localhost:3024/ContactService/v20", header, request_v20));
            // talk to wrong endpoint
            postAndAssert(500, "http://localhost:3024/ContactService/v20", header, request_v11);
            // talk to proxy
            assertContains("1.1", postAndAssert(200, "http://localhost:3025/ContactService", header, request_v11));
            assertContains("2.0", postAndAssert(200, "http://localhost:3025/ContactService", header, request_v20));
        } finally {
            antNode1.killScript();
        }
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) AssertUtils.replaceInFile(com.predic8.membrane.test.AssertUtils.replaceInFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)26 Header (com.predic8.membrane.core.http.Header)16 Request (com.predic8.membrane.core.http.Request)13 IOException (java.io.IOException)13 Response (com.predic8.membrane.core.http.Response)12 CacheBuilder (com.google.common.cache.CacheBuilder)8 Test (org.junit.Test)8 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)7 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)6 UnknownHostException (java.net.UnknownHostException)6 MCElement (com.predic8.membrane.annot.MCElement)5 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 AbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot)4 DynamicAbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot)4 HeaderField (com.predic8.membrane.core.http.HeaderField)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Cache (com.google.common.cache.Cache)2