저지 클라이언트에 프록시 서버를 구성하고 싶습니다.
(http.proxyHost와 같은 JVM 인수를 사용하여) 전체 응용 프로그램에 프록시를 구성하고 싶지 않고 Apache 클라이언트를 사용하지 않습니다.
here HttpUrlConnectionFactory를 통해 HttpUrlConnection 을 제공함으로써 옵션을 수행 할 수있는 옵션이 있지만 모든 코드 예제를 찾을 수 없습니다.
누구든지 어떻게 할 수 있는지 알고 있습니까?
감사합니다.저지 클라이언트에 프록시 구성
답변
시도는, 내가 완료있어 :
이 HttpURLConnectionFactory 구현 및 방법 'getHttpURLConnection'를 오버라이드 (override), 내 구현 (루카 덕분에)입니다 :
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128));
return new HttpURLConnection(url, proxy);
사이클로 작업하기 전에 Jersey Client를 인스턴스화하고
URLConnectionClientHandler
을 새로 작성하고 해당 생성자에HttpURLConnectionFactory
을 제공하십시오. 그런 다음 새 Client를 작성하고 Client 생성자에서 ClientHandler를 제공하십시오. 내 코드 :
URLConnectionClientHandler urlConnectionClientHandler = new URLConnectionClientHandler(new MyHttpURLConnectionFactory());
_client = new Client(urlConnectionClientHandler);
희망의 도움이됩니다. 모든
루카의 도움으로
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
conn = new URL(url).openConnection(proxy);
현재 어떻게'Client.create (config)'를 사용하고 있는지 잘 모르겠습니다. 클라이언트를 생성 할 때'UrlConnection'을 사용하는 옵션을 찾을 수 없습니다. – danieln
먼저 나는
import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
/**
*
* @author Aimable
*/
public class ConnectionFactory implements HttpURLConnectionFactory {
Proxy proxy;
String proxyHost;
Integer proxyPort;
SSLContext sslContext;
public ConnectionFactory() {
}
public ConnectionFactory(String proxyHost, Integer proxyPort) {
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
}
private void initializeProxy() {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
}
@Override
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
initializeProxy();
HttpURLConnection con = (HttpURLConnection) url.openConnection(proxy);
if (con instanceof HttpsURLConnection) {
System.out.println("The valus is....");
HttpsURLConnection httpsCon = (HttpsURLConnection) url.openConnection(proxy);
httpsCon.setHostnameVerifier(getHostnameVerifier());
httpsCon.setSSLSocketFactory(getSslContext().getSocketFactory());
return httpsCon;
} else {
return con;
}
}
public SSLContext getSslContext() {
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new TrustManager[]{new SecureTrustManager()}, new SecureRandom());
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
} catch (KeyManagementException ex) {
Logger.getLogger(ConnectionFactory.class.getName()).log(Level.SEVERE, null, ex);
}
return sslContext;
}
private HostnameVerifier getHostnameVerifier() {
return new HostnameVerifier() {
@Override
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession) {
return true;
}
};
}
}
후 나는 또한 SecureTrustManager
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
/**
*
* @author Aimable
*/
public class SecureTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1)
throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public boolean isClientTrusted(X509Certificate[] arg0) {
return true;
}
public boolean isServerTrusted(X509Certificate[] arg0) {
return true;
}
}
라는 다른 클래스를 만들고이 클래스를 생성 한 후 생성 내가이
URLConnectionClientHandler cc = new URLConnectionClientHandler(new ConnectionFactory(webProxy.getWebserviceProxyHost(), webProxy.getWebserviceProxyPort()));
client = new Client(cc);
client.setConnectTimeout(2000000);
같은 클라이언트를 호출하고있어이 수업 후
proxyHost 및 webProxy.getWebservi로 webProxy.getWeserviceHost를 대체하십시오. ceProxyPort() 프록시 포트로.
이것은 나를 위해 일했으며 또한 당신을 위해 작동해야합니다. 저지 1.8을 사용하고 있지만 저지 2에서도 작동해야합니다.
덕분에이 기능이 저에게 효과적이었습니다. – whoami
- 1. 저지 - 버전 1.14의 프록시 자동 인증
- 2. 봄 저지 웹 앱 - 구성
- 3. 소프트웨어의 여러 클라이언트에 서로 다른 프록시 사용
- 4. x ++로 프록시 구성
- 5. TFS 프록시 서버 구성
- 6. 자바 자동 프록시 구성
- 7. Maven + 확신 : 프록시 구성
- 8. CAS 프록시 구성
- 9. 프록시 구성 이클립시
- 10. wadl에서 저지 클라이언트에 대한 void 메소드를 생성 할 수 없습니다
- 11. WS02는 저지 서비스를 지원합니까?
- 12. 저지
- 13. WinHTTP 및 Excel로 프록시 구성
- 14. GSOAP : 자동 프록시 구성 URL
- 15. WCF 데이터 서비스 클라이언트에 대한 System.ServiceModel 구성 섹션 생성
- 16. 자바 저지 클라이언트 API
- 17. WCF 서비스 구성 정보가 클라이언트에 있습니까?
- 18. 저지 + Guice 저지 자원을 저지 자원과 혼합 할 수 없음
- 19. 저지 로깅 필터
- 20. 3 개의 Squid 프록시 서버로 구성된 프록시 배열 구성
- 21. 자격 증명이있는 NetCFSvcUtil로 만든 클라이언트에 웹 프록시 추가
- 22. 각 클라이언트에 app.config 파일 대신 wcf 프록시 프로젝트 사용
- 23. WCF 서비스가 클라이언트에 프록시 개체를 반환 할 수 있습니까?
- 24. ClickOnce는 인증이 필요한 프록시 뒤에있는 클라이언트에 응용 프로그램 배포를 지원합니까?
- 25. 저지 : 서블릿에서 저지 필터로 데이터를 전송하는 방법
- 26. 리디렉션 저지 로깅 필터는
- 27. 저지 클라이언트
- 28. 저지 URISchemeScanner
- 29. 저지 생성자
- 30. 저지 : com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
이것은 Java 6 이후 버전에서만 작동합니다. Proxy가있는 HttpURLConnection 생성자는 Java 5에서 사용할 수 없습니다. –