简体   繁体   English

Spring app对非spring webapp的响应

[英]Spring app Response to non-spring webapp

I have two applications. 我有两个应用程序。 One is a legacy webapp which is servlet-based. 一种是基于Servlet的旧版Web应用程序。 The other is a spring-based webapp. 另一个是基于Spring的Webapp。 The legacy app has a page that has multiple jquery tabs. 旧版应用程序的页面包含多个jquery标签。 I want one of the tabs to act as an iframe to the spring based application. 我希望其中一个标签充当基于Spring的应用程序的iframe。 I have done the following to achieve that: 我已经做到以下几点:

  1. trigger an http post request (by openning and http url connection and writing to a printing to a writer) to the spring app, upon clicking on the tab name 单击选项卡名称时,触发对Spring应用程序的http发布请求(通过打开和http url连接并向作者写入打印内容)
  2. the request contains information about the user in the legacy system, encrypted using a generated key shared on both systems 该请求包含有关旧系统中用户的信息,并使用在两个系统上共享的生成的密钥进行加密
  3. configure the spring mvc framework to intercept calls to the url and calls a method to process the request. 配置spring mvc框架以拦截对url的调用并调用一种方法来处理请求。

The request handling ideally should do the following: 理想情况下,请求处理应执行以下操作:

  1. decrypt the request data using the shared key 使用共享密钥解密请求数据
  2. validate the request, license, etc 验证请求,许可证等
  3. if the requester is deemed to be authentic and user has a valid license (uses an api for the license validation) then set up an account for the user and authenticate them programmatically into spring security 如果请求者被认为是真实的,并且用户具有有效的许可证(使用api进行许可证验证),则为该用户设置一个帐户,并通过编程方式对他们进行身份验证,以确保Spring安全
  4. generate a random authentication key (to be used for future communications instead of the shared key) 生成随机认证密钥(用于将来的通信,而不是共享密钥)
  5. send the random key back to legacy system (encrypted using the shared key) 将随机密钥发送回旧系统(使用共享密钥加密)
  6. direct the user to a specific page in the spring app 将用户定向到spring应用程序中的特定页面

1 , 2 and 3 are complete, but I am struggling with 4 and 5 . 123是完整的,但我挣扎45 How can I send the second key to the legacy system and have the legacy system read it in using a buffered reader and then open the redirect page in the tab? 如何将第二个密钥发送到旧系统,并让旧系统使用buffered reader读取它,然后在选项卡中打开重定向页面? Is it even possible in one response? 有可能在一个回应中吗?

I used the @ResponseBody to return the key, but dont know how to send the redirect? 我使用@ResponseBody返回密钥,但不知道如何发送重定向? ps feel free to ask me questions if anything is not clear ps随时问我问题是否不清楚

Solved it as follows: 解决方法如下:

  1. the tab page on legacy application is preloaded with an iframe but without source, along with it a form with hidden fields is placed but without values, the form has the iframe as its target, and its action points to spring app url 旧版应用程序的标签页上预加载了iframe,但没有源代码,并且已放置带有隐藏字段但没有值的表单,该表单以iframe为目标,其操作指向spring应用程序的url
  2. when the tab page is opened, an ajax call is performed to a servlet on the legacy application 当打开标签页时,将对旧版应用程序上的servlet进行ajax调用
  3. The servlet makes a call to the spring app on `/spring-url.do` with params. Servlet使用参数调用`/ spring-url.do`上的spring应用程序。 The call is performed by opening an `HttpURLConnection`. 通过打开“ HttpURLConnection”来执行该调用。
  4. `/spring-url.do` is intercepted by spring dispatcher and a method handles it as follows: Spring调度程序会拦截`/ spring-url.do`,并按照以下方法进行处理:
  5. if it's the user's first time then generate a new key for them and write it to the response (it does so by forwarding the request to another controller whose return type is `@ResponseBody String`) 如果这是用户的第一次,则为他们生成一个新密钥并将其写入响应(通过将请求转发到另一个返回类型为@ResponseBody String的控制器来完成)
  6. the response is read by the legacy application servlet and the key is persisted on the legacy app database for future communications 响应由旧版应用程序servlet读取,并且密钥保留在旧版应用程序数据库中,以备将来进行通信
  7. the servlet encrypts the user data using the new key and returns it to the ajax call servlet使用新密钥加密用户数据,并将其返回给ajax调用
  8. ajax success function reads the response and sets the value of the hidden form fields and programmatically submits the form ajax成功函数读取响应并设置隐藏表单字段的值,并以编程方式提交表单
  9. spring intercepts the url again, but this time it's an existing user, so it doesnot generate the new key, instead it validates the data and forwards request to a page on the spring app. spring会再次拦截该url,但这一次它是现有用户,因此它不会生成新密钥,而是会验证数据并将请求转发到spring应用程序上的页面。

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

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