Plirkee Plirkee - 1 year ago 154
Java Question

java web service jax-ws client authentication Tomcat not working

I have the following client that consumes web service that is running on tomcat (local host)


import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NewClass {
static {
//for localhost testing only
public boolean verify(String hostname, sslSession) {
if (hostname.equals("localhost")) {
return true;
return false;
public static void main(String[] args) {


private static java.util.List<java.lang.Object> receive(int resNumber) {

System.setProperty("","c:\\mylocalhost.jks"); //path to jks
System.setProperty("","****"); //path to jks
System.setProperty("","c:\\myclient.jks"); //path to jks
System.setProperty("","*****"); //path to jks

client.NewWebService_Service service = new client.NewWebService_Service();
client.NewWebService port = service.getNewWebServicePort();
java.util.Map<String,Object> rmap = ((BindingProvider)port).getRequestContext();
java.util.Map<String,List<String>> header= new HashMap();
header.put("Username", Collections.singletonList("1"));
header.put("Password", Collections.singletonList("1"));

rmap.put(MessageContext.HTTP_REQUEST_HEADERS , header);
return port.receiveData(resNumber);



Now on tomcat I have the following in server.xml

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true"

keystoreFile="conf/mytomcatkeystore.jks" clientAuth="false" scheme="https" secure="true"

and I am using following options to start tomcat

set JAVA_OPTS="" "****" ""

Now, web service call over ssl works fine when
however if
I set
in server.xml I get the following error. HTTP transport error: Unrecognized SSL message, plaintext connection?

Tried to search for solution on many sites - with no luck.
If somebody can help - will be grateful.

Answer Source

O.K. After many frustrating hours, I finally found the solution, thanks to this SO post.

So the solution was to comment out the following line inside the server.xml

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download