如果对此问题有任何帮助,我将非常感激。我使用Camel作为代理,并使用路由上的处理器将http请求和响应记录到数据库中。
这是我的路线:
final String proxyEndpoint = https4://targetServler?bridgeEndpoint=true&throwExceptionOnFailure=false;
onException(Exception.class).handled(false).process(exceptionHandlingProcessor)
.id(exceptionHandlingProcessor.getId());
from("servlet://?matchOnUriPrefix=true")//
.setExchangePattern(ExchangePattern.InOut)//
.routeId("proxy-route")//
.choice()//
.when(header(Exchange.HTTP_PATH)//
.regex("^(\\/?static\\/.*|favicon.ico)$"))//
.to(proxyEndpoint)//
.otherwise()//
.process(validationProcessor).id(validationProcessor.getId())//
.process(logRequestProcessor).id(logRequestProcessor.getId())//
.to(proxyEndpoint)//
.convertBodyTo(String.class)//
.process(logResponseProcessor).id(logResponseProcessor.getId());
这可以工作并路由每个请求,并且任何非静态资源都会记录到数据库中(在处理器内部完成)。
然后我需要第二条路径用于DB中的其他请求/其他表,但这次必须更改URI(从数据库中读取)。所以我补充道:
from("servlet://?matchOnUriPrefix=true&servletName=AnotherCamelServlet")
.setExchangePattern(ExchangePattern.InOut)//
.routeId("second-route")//
.process(handleRequestForSecondRouteProcessor)//
.id(handleRequestForSecondRouteProcessor.getId())//
.to("https4://dummyuri")//
.convertBodyTo(String.class)//
.process(logResponseForSecondRouteProcessor).id(logResponseForSecondRouteProcessor.getId());
在handleRequestForSecondRouteProcessor中,我添加了uri头的替换:
inMessage.setHeader(Exchange.HTTP_URI, newUriFromDatabase
+ "?bridgeEndpoint=true&throwExceptionOnFailure=false"); // not sure if needed
但每次我调用第二条路径时,都会发生连接重置。 (顺便说一句,如果我拨打第一条路线(有效)然后按F5,则会出现同样的问题)。
java.net.SocketException:连接重置 在java.net.SocketInputStream.read(SocketInputStream.java:209) 在java.net.SocketInputStream.read(SocketInputStream.java:141) at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) 在org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) 在org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) 在org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) 在org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) 在org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185) 在org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) 在org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111) 在org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) 在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) 在org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) at org.apache.camel.component.http4.HttpProducer.executeMethod(HttpProducer.java:334) 在org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:193) at org.apache.camel.util.AsyncProcessorConverterHelper $ ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) 在org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) 在org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) 在org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) 在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) 在org.apache.camel.processor.Pipeline.process(Pipeline.java:138) 在org.apache.camel.processor.Pipeline.process(Pipeline.java:101) 在org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) 在org.apache.camel.http.common.CamelServlet.doService(CamelServlet.java:208) 在org.apache.camel.http.common.CamelServlet.service(CamelServlet.java:78) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790) 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459) 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
我很欣赏每一个想法,因为我现在已经讨论了这个话题。如果需要更多信息,请发表评论。 谢谢!
答案 0 :(得分:1)
当您收到第一个请求时,会有很多标题包含与该请求相关的信息。其中一些标题很可能会干扰您的下一个请求。尝试删除所有标题,然后再调用第二条路线并查看是否有帮助,然后您可以从那里开始尝试删除必要的标题。
.removeHeaders("*")