use of com.predic8.membrane.core.transport.Transport in project service-proxy by membrane.
the class HttpRouter method createTransport.
/**
* Same as the default config from monitor-beans.xml
*/
private Transport createTransport(ProxyConfiguration proxyConfiguration) {
Transport transport = new HttpTransport();
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(new RuleMatchingInterceptor());
interceptors.add(new DispatchingInterceptor());
interceptors.add(new UserFeatureInterceptor());
HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor();
interceptors.add(httpClientInterceptor);
transport.setInterceptors(interceptors);
return transport;
}
use of com.predic8.membrane.core.transport.Transport in project service-proxy by membrane.
the class ServiceInvocationTest method createRouter.
private HttpRouter createRouter() throws Exception {
HttpRouter router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(createFirstRule());
router.getRuleManager().addProxyAndOpenPortIfNew(createServiceRule());
router.getTransport().getInterceptors().add(router.getTransport().getInterceptors().size() - 1, new MockInterceptor("transport-log"));
router.init();
return router;
}
use of com.predic8.membrane.core.transport.Transport in project service-proxy by membrane.
the class MembraneServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
try {
appCtx = new BaseLocationXmlWebApplicationContext();
log.debug("loading beans configuration from: " + getProxiesXmlLocation(config));
router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config.getServletContext(), getProxiesXmlLocation(config));
if (router == null)
throw new RuntimeException("No <router> with a <servletTransport> was found. To use <router> with <transport>, use MembraneServletContextListener instead of MembraneServlet.");
} catch (Exception e) {
throw new ServletException(e);
}
}
use of com.predic8.membrane.core.transport.Transport in project service-proxy by membrane.
the class AbstractHttpHandler method generateErrorResponse.
private Response generateErrorResponse(Exception e) {
String msg;
boolean printStackTrace = transport.isPrintStackTrace();
if (printStackTrace) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
msg = sw.toString();
} else {
msg = e.toString();
}
String comment = "Stack traces can be " + (printStackTrace ? "dis" : "en") + "abled by setting the " + "@printStackTrace attribute on <a href=\"https://membrane-soa.org/service-proxy-doc/current/configuration/reference/transport.htm\">transport</a>. " + "More details might be found in the log.";
Response error = null;
ResponseBuilder b = null;
if (e instanceof URISyntaxException)
b = Response.badRequest();
if (b == null)
b = Response.internalServerError();
switch(ContentTypeDetector.detect(exchange.getRequest()).getEffectiveContentType()) {
case XML:
error = b.header(HttpUtil.createHeaders(MimeType.TEXT_XML_UTF8)).body(("<error><message>" + StringEscapeUtils.escapeXml(msg) + "</message><comment>" + StringEscapeUtils.escapeXml(comment) + "</comment></error>").getBytes(Constants.UTF_8_CHARSET)).build();
break;
case JSON:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
JsonGenerator jg = new JsonFactory().createGenerator(baos);
jg.writeStartObject();
jg.writeFieldName("error");
jg.writeString(msg);
jg.writeFieldName("comment");
jg.writeString(comment);
jg.close();
} catch (Exception f) {
log.error("Error generating JSON error response", f);
}
error = b.header(HttpUtil.createHeaders(MimeType.APPLICATION_JSON_UTF8)).body(baos.toByteArray()).build();
break;
case SOAP:
error = b.header(HttpUtil.createHeaders(MimeType.TEXT_XML_UTF8)).body(HttpUtil.getFaultSOAPBody("Internal Server Error", msg + " " + comment).getBytes(Constants.UTF_8_CHARSET)).build();
break;
case UNKNOWN:
error = HttpUtil.setHTMLErrorResponse(b, msg, comment);
break;
}
return error;
}
use of com.predic8.membrane.core.transport.Transport in project service-proxy by membrane.
the class HttpEndpointListener method run.
@Override
public void run() {
while (!closed) {
try {
Socket socket = serverSocket.accept();
openSockets.put(socket, Boolean.TRUE);
try {
if (log.isDebugEnabled())
log.debug("Accepted connection from " + socket.getRemoteSocketAddress());
transport.getExecutorService().execute(new HttpServerHandler(socket, this));
} catch (RejectedExecutionException e) {
openSockets.remove(socket);
log.error("HttpServerHandler execution rejected. Might be due to a proxies.xml hot deployment in progress or a low" + " value for <transport maxThreadPoolSize=\"...\">.");
socket.close();
}
} catch (SocketException e) {
String message = e.getMessage();
if (message != null && (message.endsWith("socket closed") || message.endsWith("Socket closed"))) {
log.debug("socket closed.");
break;
} else
log.error("", e);
} catch (NullPointerException e) {
// Ignore this. serverSocket variable is set null during a loop in the process of closing server socket.
} catch (Exception e) {
log.error("", e);
}
}
}
Aggregations