<!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: Jboss 6.0 WebService Client with SSL (Saaj)
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/fabiano.oss">Fabiano Oss</a> in <i>JBoss Web Services</i> - <a href="http://community.jboss.org/message/604247#604247">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>protected ByteArrayOutputStream sendMessage(URL urlWSDL, QName qService, QName qPort, String soapMessage) throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; SOAPMessage message;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MimeHeaders header = new MimeHeaders();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; header.addHeader("Content-Type", "application/soap+xml");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; message = factory.createMessage(header, new ByteArrayInputStream(soapMessage.toString().getBytes()));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Service service = Service.create(urlWSDL, qService);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dispatch&lt;SOAPMessage&gt; dispatch = service.createDispatch(qPort, SOAPMessage.class,Service.Mode.MESSAGE);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; setSecurity(dispatch);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; SOAPMessage res = dispatch.invoke(message);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ByteArrayOutputStream out = new ByteArrayOutputStream();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; res.writeTo(out);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return out;</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private void setSecurity(Dispatch&lt;SOAPMessage&gt; dispatch) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, InvalidKeyException, InvalidKeySpecException, UnrecoverableKeyException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Client client = ((org.apache.cxf.jaxws.DispatchImpl) dispatch).getClient();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; HTTPConduit http = (HTTPConduit) client.getConduit();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; setProxy(security, http, httpClientPolicy);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; http.setClient(httpClientPolicy);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TLSClientParameters tlsParams = new TLSClientParameters();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TrustManager[] trustMgr = addTrustManagers(security);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KeyManager[] keyMgr = addCertificado(security);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tlsParams.setKeyManagers(keyMgr);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tlsParams.setTrustManagers(trustMgr);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; http.setTlsClientParameters(tlsParams);</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private void setProxy(SegurancaDES security, HTTPConduit http,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HTTPClientPolicy httpClientPolicy) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; httpClientPolicy.setProxyServer("192.168.1.1");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; httpClientPolicy.setProxyServerPort("3128");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; http.getProxyAuthorization().setUserName("proxyUser");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; http.getProxyAuthorization().setPassword("proxyPassword);</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; private KeyManager[] addCertificado(SegurancaDES security)</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throws KeyStoreException, IOException, NoSuchAlgorithmException,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CertificateException, FileNotFoundException,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; UnrecoverableKeyException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KeyStore ks1;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ks1 = KeyStore.getInstance("PKCS12");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ks1.load(new FileInputStream(new File("file path")),"password".toCharArray());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KeyManagerFactory keyFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; keyFactory.init(ks1, "password".toCharArray());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; KeyManager[] keyMgr = keyFactory.getKeyManagers();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return keyMgr;</p><p>&#160;&#160;&#160; }</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/604247#604247">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


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

</div>

</body>
</html>