我在JAR中有一个我无法改变的第三方servlet.我已经扩展了该servlet并且正常使用它,因为应该使用servlet,客户端发出一个调用我的servlet的HTTP请求.
但是现在客户端想要一个自动服务,也就是说,我需要从servlet所在的同一个webapp对该第三方servlet做一些请求.
我查看了第三方servlet代码,但我没有找到绕过servlet的地方因为HttpServletRequest和HttpServletResponse对象从方法传递给方法……基本上我似乎需要重新实现所有第三方派对代码.
Solutions I found but do not satisfy me:
Call servlet from URL with HttpURLConnection: My common sense says that calling the third party servlet from a url is not the best way to
go, besides the overhead added, I don’t want to expose the third party
servlet. Calling my servlet from a url also brings problems with
sessions and other things.
Call the doGet directly: This seems to be out of the question because there is no implementation for the HttpServletRequest and
HttpServletResponse.
Use jMock or something like that: Didn’t explore this solution yet, but it seams wrong to use a test-driven library in the real
environment.
任何人都知道如何与第三方servlet交互?
编辑:
由于我的英语不是很好,我发现自己很难解释,这里有一个原理图,试图更好地解释
编辑2:在与第三方制造商会面后,他们提出隔离我需要避免调用servlet的方法.如果你没有同样的运气,我确实检查了gigadot和BalusC的答案.