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