Using proxy with sample ConsumerServlet (newbie)

43 views
Skip to first unread message

Alex Little

unread,
Dec 18, 2007, 11:27:24 AM12/18/07
to OpenID4Java
Hi,
I'm trying out the openid4java library and using the sample
ConsumerServlet as my consumer, however I'm having problems setting
the proxy so all requests go through the proxy (I'm on my office PC
and need a proxy host/port configured, but no authentication
required).

I've uncommented the proxy setup section in the
ConsumerServlet.authRequest method which fixes the problem for _some_
requests. However, I was still getting a connection refused error when
the ConsumerServlet.verifyResponse method was called, so I then added
the proxy settings at the beginning of this method - but these appear
to be being completely ignored (see the stack trace at bottom of this
message).

Does anyone have any ideas what I need to do to get the proxy
recognised for all the http requests? I've seen the other posts in
this group about the proxy but none of these seemed to fix this
particular problem. I've found that if i hard code the proxy settings
into the HttpClientFactory then all works fine - but this obviously
isn't really a great solution!

Any help much appreciated!

Cheers,
Alex

ps.for info the code also runs fine on a server in our DMZ that
doesn't need the proxy setting - but I can't really do all my
development on that machine :-(

Stack trace:
-------------------------------------------------------

18-Dec-2007 16:09:30 org.openid4java.consumer.ConsumerManager call
SEVERE: Error talking to http://pip.verisignlabs.com/server response
code: -1
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.create
Socket(ReflectionSocketFactory.java:139)
at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.c
reateSocket(DefaultProtocolSocketFactory.java:124)
at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java
:706)
at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$Http
ConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1321)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
pMethodDirector.java:386)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
thodDirector.java:170)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:396)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:324)
at
org.openid4java.consumer.ConsumerManager.call(ConsumerManager.java:59
3)
at
org.openid4java.consumer.ConsumerManager.verifySignature(ConsumerMana
ger.java:1723)
at
org.openid4java.consumer.ConsumerManager.verify(ConsumerManager.java:
1167)
at
org.openid4java.samples.consumerservlet.ConsumerServlet.verifyRespons
e(ConsumerServlet.java:249)
at
org.openid4java.samples.consumerservlet.ConsumerServlet.doGet(Consume
rServlet.java:82)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol
$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool
$ControlRunnable.run(ThreadP
ool.java:684)

Johnny Bufu

unread,
Dec 18, 2007, 1:22:38 PM12/18/07
to openi...@googlegroups.com
Alex,

On 18-Dec-07, at 8:27 AM, Alex Little wrote:
> Does anyone have any ideas what I need to do to get the proxy
> recognised for all the http requests? I've seen the other posts in
> this group about the proxy but none of these seemed to fix this
> particular problem. I've found that if i hard code the proxy settings
> into the HttpClientFactory then all works fine - but this obviously
> isn't really a great solution!

Try putting the proxy configuration in ConsumerServlet.init().

This is what I believe happens now: when the ConsumerManager is
created, it initializes its HttpClient _without_ any proxy config.
Subsequent HTTP calls use the proxy config only if they getNewInstance
() from the HttpClientFactory (which I think is true for the
discovery package), but not for the calls placed by the
ConsumerManager itself (associations and verification).

If this works, we should update the example and document the proxy
configuration / usage better.


Johnny

Alex Little

unread,
Dec 19, 2007, 5:07:16 AM12/19/07
to openi...@googlegroups.com
Cheers Johnny,
Yes - that did the trick :-) I did find that the proxy had to be set before the ConsumerManager was created  - a not-very-interesting-patch below!

Alex

Index: D:/eclipse/workspace/openid4java/samples/consumer-servlet/src/main/java/org/openid4java/samples/consumerservlet/ConsumerServlet.java
===================================================================
--- D:/eclipse/workspace/openid4java/samples/consumer-servlet/src/main/java/org/openid4java/samples/consumerservlet/ConsumerServlet.java    (revision 428)
+++ D:/eclipse/workspace/openid4java/samples/consumer-servlet/src/main/java/org/openid4java/samples/consumerservlet/ConsumerServlet.java    (working copy)
@@ -58,6 +58,11 @@
         log.debug("context: " + context);
 
         try {
+            // --- Forward proxy setup (only if needed) ---
+            // ProxyProperties proxyProps = new ProxyProperties();
+            // proxyProps.setProxyName(" proxy.example.com");
+            // proxyProps.setProxyPort(8080);
+            // HttpClientFactory.setProxyProperties(proxyProps);
             this.manager = new ConsumerManager();
         } catch (ConsumerException e) {
             throw new ServletException(e);
@@ -108,12 +113,6 @@
             // String returnToUrl = "http://example.com/openid";
             String returnToUrl = httpReq.getRequestURL().toString();
 
-            // --- Forward proxy setup (only if needed) ---
-            // ProxyProperties proxyProps = new ProxyProperties();
-            // proxyProps.setProxyName(" proxy.example.com");
-            // proxyProps.setProxyPort(8080);
-            // HttpClientFactory.setProxyProperties(proxyProps);
-
             // perform discovery on the user-supplied identifier
             List discoveries = manager.discover(userSuppliedString);
 

Reply all
Reply to author
Forward
0 new messages