具体来说,我使用的版本是Jersey 1.19.目前这就是我在做的事情:
Client client = Client.create();
client.getProperties().put(ApacheHttpClientConfig.PROPERTY_PROXY_URI, "myhost:myport");
Run Code Online (Sandbox Code Playgroud)
但是,这对我来说不起作用,因为我有一个UnknownHostException:
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException:
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助.
我想使用spring security. 从spring 官方文档 中 23.2 WebSocket Authentication,WebSocket 将重用在建立 WebSocket 连接时在 HTTP 请求中找到的相同身份验证信息。所以我设置了 spring security 来验证rest service. 如果用户通过了其余的认证,则拥有WebSocket连接的权限,否则无法建立WebSocket连接。以下是代码:
用于登录的休息服务:WssAuthService.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* Authentication service.
*/
@RestController
@RequestMapping(path = "/hpdm")
public class WssAuthService {
@RequestMapping(path = "/login", method = RequestMethod.GET)
public String login(){
return "Login success to WssBroker...";
}
}
Run Code Online (Sandbox Code Playgroud)
spring 安全配置:WebSecurityConfig.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy; …Run Code Online (Sandbox Code Playgroud)