简体   繁体   English

如何在Java Spring中的同一服务器中打开多个URL路径

[英]How to open multiple URLs path in a same server in java spring

I am new to java world and I am trying to open multiple urls in a same server.. I am using java spring mvc. 我是Java世界的新手,我想在同一服务器上打开多个URL。我正在使用Java Spring MVC。

I have an external server which I need to retrieve data from different location in the server.. 我有一个外部服务器,我需要从服务器中的其他位置检索数据。

For example, The external server have urls like this : http://server.data.com:1234/dataStorage/thisgate/datalist/hereA 例如,外部服务器具有如下网址: http ://server.data.com:1234/dataStorage/thisgate/datalist/ hereA

1) open the first path with this url : works fine
URL url = new URL(....
URLConnection con = url.openConnection();
HttpURLConnection httpCon = (HttpURLConnection) con;
2) Then authenticate with username, password : works fine 
3) I retrieve data and parse it : works fine

4) [Question]: Then, I need to retrieve another data stream in another path in the same server, How? 4)[问题]:然后,我需要在同一服务器的另一条路径中检索另一条数据流,怎么办?

Let's say the second path in the same server I need to get data http://server.data.com:1234/dataStorage/thisgate/datalist/hereB/ 假设同一台服务器中的第二条路径我需要获取数据 http://server.data.com:1234/dataStorage/thisgate/datalist/hereB/

so my code is like this: 所以我的代码是这样的:

public String HTTPConnection(Model model) throws IOException {  
//>>   1) open the first path with the url    <<//

URL url = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereA/");
URLConnection con = url.openConnection();
HttpURLConnection firstConn = (HttpURLConnection) con;

//>>   2) authentication routine, it works well   <<//

   //:I am not going to put all detail code here, it works fine. 

//>>   3) retrieve data from the url (the first path after authentication) <<//

firstConn.setRequestMethod("GET"); 
BufferedReader firstPathData = new BufferedReader(new InputStreamReader(firstConn.getInputStream()));
// do the parsing and so on....

//>>    4) open the second path in the same server , How???????   <<//

URL redirectUrl = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereB/");
HttpURLConnection secondConn = (HttpURLConnection) redirectUrl.openConnection();
System.out.println(secondConn.getURL());  
BufferedReader secondPathData = new BufferedReader(new InputStreamReader(secondConn.getInputStream()));
        .....
        ......

} }

How can I open or retrieve other data from the second path in the same-already-connected server in nr.4) 如何在nr.4中的同一连接的服务器中从第二条路径打开或检索其他数据)

I don't need to reconnect or re-openConnection... Because it is already connected and authenticated.. 我不需要重新连接或重新打开连接...,因为它已经连接并已通过身份验证。

I just need to do 4) give another path in the same server & get stream... 我只需要做4)在同一服务器上给另一个路径并获取流...

=> this could be redirect or forward but all the examples I found it is about POST example, I think mine is about GET... =>这可以重定向或转发,但是我发现的所有示例都是关于POST的示例,我认为我的是关于GET的...

Please aware this is NOT about posting redirect page on jsp View.. 请注意,这与在jsp View上发布重定向页面无关。

This is to get/open the redirected path and retrieve another data stream in already connected server 这是为了获取/打开重定向路径并在已连接的服务器中检索另一个数据流

Any advices? 有什么建议吗? Thanks a lot in advance 在此先多谢

Should be easier if you use Spring RestTemplate which simplify communication with web server. 如果使用Spring RestTemplate可以简化与Web服务器的通信,应该会更容易。

Check out the documentation - http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html 查看文档-http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html

In your case you should execute as much requests as you need. 在您的情况下,您应该根据需要执行尽可能多的请求。

暂无
暂无

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

相关问题 在同一浏览器Selenium(JAVA)中同时打开多个URL - Open Multiple URLs concurrently in same browser Selenium (JAVA) 如何使用 Jackson (Java) 正确打开 SSL 流到多个 URL? - How to open SSL streams to multiple URLs properly with Jackson (Java)? 如何在 sql 服务器中配置多个目录/数据库,这些目录/数据库位于 spring 启动 java 8 应用程序中的同一数据库服务器上? - How to configure multiple catalogs/databases in sql server which are on same database server in spring boot java 8 app? 如何使用Java / JSoup同时抓取多个URL - How to crawl multiple URLs at the same time using Java/JSoup Spring MVC:将多个URL映射到同一个控制器 - Spring MVC: Mapping Multiple URLs to Same Controller 如何使Spring Security和cas与指向同一服务器的多个URL一起使用 - How to make Spring Security and cas work with Multiples urls pointing to the same server 如何保持多个Java HttpConnections对同一目的地开放 - how to keep multiple Java HttpConnections open to same destination 如何在java spring中读取具有相同前缀的多个属性? - How to read multiple properties with same prefix in java spring? 如何使用Selenium(Java)在多个URL上运行相同的测试,例如其中的100个 - How to run same test on multiple urls like 100s of them using selenium ( Java) 如何在 Java 中运行同一进程的多个线程 - Spring Boot - How to run multiple threads of the same process in Java - Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM