简体   繁体   English

如何使用JSESSIONID设置特定的会话?

[英]How can I set an specific session with the JSESSIONID?

I have a perfectly working web Java 1.5 web application that runs on Tomcat 5. The application is dependent on its session, so everything works well as long as the Session Cookie is passed around, or the JSESSIONID comes at the end of the context path like this ";jsessionid=..." 我有一个运行良好的Web Java 1.5 Web应用程序,该应用程序可以在Tomcat 5上运行。该应用程序依赖于其会话,因此只要传递Session Cookie或JSESSIONID位于上下文路径的末尾(例如,这个“; jsessionid = ...”

I now have to make my application work, in an environment that works like this: 现在,我必须在这样的环境中使应用程序正常工作:

  • Every request to my app will be a POST to just one URL, with no parameters whatsover (so I won't be able to set the jsessionid in the context path). 对我的应用程序的每个请求都将是一个仅包含一个URL的POST,并且没有参数whatsover(因此我将无法在上下文路径中设置jsessionid)。
  • No redirects allowed, I have to return HTTP status 200 with my response. 不允许重定向,我必须在响应中返回HTTP状态200。
  • The body of the POST is an specific XML (I can add custom parameters there). POST的主体是特定的XML(我可以在其中添加自定义参数)。

As my application is old and works well, I wanted to make this work without having to change everything. 由于我的应用程序很旧且运行良好,因此我希望无需更改所有内容即可使它正常工作。 I was able to make the single URL thing work by adding as one of the parameters in the XML body, the actual URL that should be executed, and then forwarding the response to that URL, also appending the rest of the parameters there. 通过将应执行的实际URL作为XML主体中的参数之一添加,然后将响应转发到该URL,并将其余参数附加到XML主体中,我能够使单个URL正常工作。 Here is an example: 这是一个例子:

POST http://server.com/singleUrl.do

<xml>
  <parameters>url=realPage.do&amp;param1=value1&amp;param2=value2</parameters>
</xml>

I then forward this to: 然后,我将此转发给:

http://server.com/realPage.do?param1=value1&param2=value2

And it works. 而且有效。 I just added an abstraction layer to my application, and everything works fine. 我刚刚在应用程序中添加了一个抽象层,并且一切正常。 Except the session... 除了会议...

As no session cookies are ever sent, I lose my session between POSTs. 由于从未发送过会话Cookie,因此我在两次POST之间丢失了会话。 I added the JSESSIONID as one of the custom parameters in the XML, like this: 我将JSESSIONID添加为XML中的自定义参数之一,如下所示:

<xml>
  <parameters>url=realPage.do&amp;param1=value1&amp;param2=value2&amp;jsessionid=ABC121312</parameters>
</xml>

And tried forwarding to: 并尝试转发至:

http://server.com/realPage.do;jsessionid=ABC121312?param1=value1&param2=value2

But it doesn't work. 但这是行不通的。 The same thing, with a redirect, works. 具有重定向功能的同一件事也可以工作。 But of course, in my new requirement no redirects are allowed. 但是,当然,在我的新要求中,不允许重定向。

Finally, my question. 最后,我的问题。 How could I set the session that corresponds to that JSESSIONID? 如何设置与该J​​SESSIONID对应的会话? I'd like to do it in the same abstraction layer that processes the request before sending them to my "real" application. 我想在将请求发送到我的“真实”应用程序之前,在处理请求的同一抽象层中进行处理。

I think I've come up with a solution for this... I've implemented a proxy, which parses the XML and then makes a new request, with the JSESSIONID in place. 我想我已经为此提出了一个解决方案...我实现了一个代理,该代理解析XML,然后发出新请求,并带有JSESSIONID。 I then write the response of that request on the response of the real request. 然后,我将该请求的响应写在实际请求的响应上。

I've made a prototype and it seems to be working. 我已经制作了一个原型,它似乎正在工作。 It's really ugly, but at least my application doesn't know any of this is actually happening. 这确实很丑陋,但至少我的应用程序不知道任何这种情况实际上正在发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM