<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: SSL calls thru a proxy with authentication?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/mnccouk">Matt Carless</a> in <i>JBoss Remoting</i> - <a href="http://community.jboss.org/message/564153#564153">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>After many painful hours of trying various things I finally have the answer.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The following is the only way I could get proxy authentication working via aweb service using jboss 5.1.0.GA.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>First upgrade your jbossws to jbossws-cxf-3.3.1.GA(latest version as of writing) from (</span><a class="jive-link-external-small" href="http://www.jboss.org/jbossws/downloads.html" target="_blank">http://www.jboss.org/jbossws/downloads.html</a><span>). It's a simple task make sure you have apache ant installed as you will need it to install this update into jboss.</span></p><p>To upgrage download and unpack the zip file</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Follow the instuctions in the doc folder, basically it's set the home folder of your jboss app in the ant.properties file and run ant deploy-jboss510</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>You should be able to run ant test to test your installation (Don't forget to start your server first).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Now jboss should be in good shape to handle proxies for web service clients</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>You will need to create a proxySelector</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Register the proxySelector</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Add some proxy-Authentication to the header of the web service request and your done.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here's an example proxy selector. This has been taken from the JDK5 documetation. Change the proxy address to yours.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>package com.fugrodata.bgwebservices.session;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>import java.net.*;<br/>import java.util.ArrayList;<br/>import java.util.HashMap;<br/>import java.io.IOException;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class MyProxySelector extends ProxySelector {<br/>&#160;&#160;&#160; // Keep a reference on the previous default<br/>&#160;&#160;&#160; ProxySelector defsel = null;<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160; * Inner class representing a Proxy and a few extra data<br/>&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160; class InnerProxy {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Proxy proxy;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; SocketAddress addr;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // How many times did we fail to reach this proxy?<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; int failedCount = 0;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; InnerProxy(InetSocketAddress a) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; addr = a;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; proxy = new Proxy(Proxy.Type.HTTP, a);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; SocketAddress address() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return addr;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Proxy toProxy() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return proxy;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; int failed() {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ++failedCount;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; }<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160; * A list of proxies, indexed by their address.<br/>&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160; HashMap&lt;SocketAddress, InnerProxy&gt; proxies = new HashMap&lt;SocketAddress, InnerProxy&gt;();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; MyProxySelector(ProxySelector def) {<br/>&#160;&#160;&#160;&#160;&#160; // Save the previous default<br/>&#160;&#160;&#160;&#160;&#160; defsel = def;<br/>&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160; // Populate the HashMap (List of proxies)<br/>&#160;&#160;&#160;&#160;&#160; InnerProxy i = new InnerProxy(new InetSocketAddress("proxy", 8080));<br/>&#160;&#160;&#160;&#160;&#160; proxies.put(i.address(), i);<br/>&#160;&#160;&#160;&#160;&#160; //i = new InnerProxy(new InetSocketAddress("webcache2.mydomain.com", 8080));<br/>&#160;&#160;&#160;&#160;&#160; //proxies.put(i.address(), i);<br/>&#160;&#160;&#160;&#160;&#160; //i = new InnerProxy(new InetSocketAddress("webcache3.mydomain.com", 8080));<br/>&#160;&#160;&#160;&#160;&#160; //proxies.put(i.address(), i);<br/>&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160; * This is the method that the handlers will call.<br/>&#160;&#160;&#160;&#160;&#160;&#160; * Returns a List of proxy.<br/>&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160; public java.util.List&lt;Proxy&gt; select(URI uri) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Let's stick to the specs. <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (uri == null) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new IllegalArgumentException("URI can't be null.");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * If it's a http (or https) URL, then we use our own<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * list.<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; String protocol = uri.getScheme();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ("http".equalsIgnoreCase(protocol) ||<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "https".equalsIgnoreCase(protocol)) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ArrayList&lt;Proxy&gt; l = new ArrayList&lt;Proxy&gt;();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for (InnerProxy p : proxies.values()) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; l.add(p.toProxy());<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return l;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * Not HTTP or HTTPS (could be SOCKS or FTP)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * defer to the default selector.<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (defsel != null) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return defsel.select(uri);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ArrayList&lt;Proxy&gt; l = new ArrayList&lt;Proxy&gt;();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; l.add(Proxy.NO_PROXY);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return l;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160; }<br/>&#160;&#160;&#160; <br/>&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160; * Method called by the handlers when it failed to connect<br/>&#160;&#160;&#160;&#160; * to one of the proxies returned by select().<br/>&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160; public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Let's stick to the specs again.<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (uri == null || sa == null || ioe == null) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new IllegalArgumentException("Arguments can't be null.");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * Let's lookup for the proxy <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; InnerProxy p = proxies.get(sa); <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (p != null) {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * It's one of ours, if it failed more than 3 times<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * let's remove it from the list.<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (p.failed() &gt;= 3)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; proxies.remove(sa);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } else {<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; /*<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; * Not one of ours, let's delegate to the default.<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; */<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (defsel != null)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; defsel.connectFailed(uri, sa, ioe);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<br/>&#160;&#160;&#160;&#160; }<br/>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Register the proxy above using this code</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>MyProxySelector ps = new MyProxySelector(ProxySelector.getDefault());</p><p>ProxySelector.setDefault(ps);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Your jvm will start to use the proxy selector from this point forward. Now to add the authentication for the webservice request to authenticate against the proxy. The Proxy-Authorization header is added manually to the web service request. This is done on the webservice classes, here's an example.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Service service = new Service();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceOperations portType = service.getService();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&lt;String,&#160; List&lt;String&gt;&gt; map2 = (Map&lt;String,&#160; List&lt;String&gt;&gt;) ((BindingProvider) portType).getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&lt;String, List&lt;String&gt;&gt; map = map2;<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (map == null)<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; map = new HashMap&lt;String, List&lt;String&gt;&gt;();<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; map.put("Proxy-Authorization", Collections.singletonList(<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "Basic " +&#160; Base64.encodeBytes(("username:password").getBytes())));<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Adding to HttpRequestHeaders [map="+map+"]&#160; ...");<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ((BindingProvider) portType).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,&#160; map);<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br/>///&#160;&#160;&#160;&#160;&#160;&#160;&#160; portType.webserviceMethod(...);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Change the username and password to suit your proxy in the code above.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Job done!</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/564153#564153">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Remoting at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2050">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>