maven wsimport throwing security exception with PKIX path building failed: - web-services

I have an ejb which is annotated with #Webserivce. Everything in glassfish4.
The wsdl is generated correctly, soapUi can also send requests.
But when I try to generate client artifacts using jax ws maven plugin which is configured as following.
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>transactionService.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.me.backend.connector.ws</packageName>
<sourceDestDir>${basedir}/target/generated-sources/main/java</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
I get sun.security.validator.ValidatorException: PKIX path building failed:
So I need to know
How can I tell jax ws plugin to use the certificates ?
How can I get the certificates, currently the webservice and the client are both on localhost for development purpose
How can I tell glassfish4 not to use https and use http when exposing the webservice ?

Just noticed. Glassfish generates both http and https wsdl locations. So the http one works

Related

Apache CXF - How can I automate WSDL relative path resolution for Client Stubs generation?

In my maven project in order to generating client stubs using apache cxf, I've configured the pom as follows:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<frontEnd>jaxws21</frontEnd>
<markGenerated>true</markGenerated>
<xjcargs>
<xjcarg>-Xts</xjcarg>
</xjcargs>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/MyServiceA_v1.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/MyServiceA_v1.wsdl</wsdlLocation>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/MyServiceB_v1.wsdl</wsdl>
<wsdlLocation>classpath:wsdl/MyServiceB_v1.wsdl</wsdlLocation>
</wsdlOption>
</wsdlOptions>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.cxf.xjcplugins</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
Then I've downloaded "manually" all the WSDLs from the server, which exposes the web services, into my resource project folder "\my-project\src\main\resources\wsdl" and all the related XSDs inside my xsd project folder "\my-project\src\main\resources\wsdl\xsd".
After that I've changed manually all the schemaLocation inside the WSDLs file in order to have only relative path (then running cxf generation the java client stubs are correctly generated).
Example:
Inside a wsdl I've changed:
<xs:import namespace="http://ws.myproject.priv.schema/MyServiceA/v1" schemaLocation="http://161.29.123.124:8080/web-1.0/ws/MyServiceA_v1?myServiceA_v1.0.xsd"/>
with the relative path (related to the folder \my-project\src\main\resources\wsdl\xsd)
<xs:import namespace="http://ws.myproject.priv.schema/MyServiceA/v1" schemaLocation="xsd/myServiceA_v1.0.xsd"/>
Is there a way (with maven, apache cxf, ant or something else...) to download automatically all the WSDLs and XSDs from the server to my folders and then automatically changing the server paths with my project relative paths?
How can I automate this process?

jax-ws maven plugin sets wsdlLocation to absolute path

I generate web service client using
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<target>2.1</target>
<xnocompile>false</xnocompile>
</configuration>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
</plugin>
my EndpointService.wsdl is in src/main/wsdl. Plugin generates EndointServiceService.java with annotation
#WebServiceClient(name = "EndpointServiceService", targetNamespace = "http://soap.endpoint.fsg.ftc/", wsdlLocation = "file:/D:/Source/java/branches/9.3.0/camel-smev/wscapi/src/wsdl/EndpointService.wsdl")
so if wsdl
D:/Source/java/branches/9.3.0/camel-smev/wscapi/src/wsdl/EndpointService.wsdl
not exist(on another machine), it throw exception in runtime.
if i copy wsdl to this dir it runs successfully. How can i include wsdl into my target jar and make client use it? Or how to exclude wsdl dependency at runtime at all? Maybe try older version or another plugin?
add the < wsdllocation > tag in the plugin configuration to a relative path for your wsdl.
you can find an example here

The #javax.jws.WebMethod annotation cannot be used in with #javax.jws.WebService.endpointInterface element in maven

I am trying to create a JWS web service from a WSDL file that's already defined/created by me.
I have followed a two step approach like:
wsimport - from "jaxws-maven-plugin" - to create wsdl artifact files - SUCESS
wsgen - from "jaxws-maven-plugin" - to compile my SEI and create a war file - FAILED
I am seeing issues with #2. The error is:
The #javax.jws.WebMethod annotation cannot be used in with #javax.jws.WebService.endpointInterface element in maven
Can someone help me to resolve this issue?
I used this configuration in my pom.xml. Additionally, avoid to use #WebParam for your parameters, in your #Webmethod. Hope this helps you.
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<sei>service.CompanyImpl</sei>
<genWsdl>true</genWsdl>
<encoding>UTF-8</encoding>
<inlineSchemas>true</inlineSchemas>
<verbose>true</verbose>
</configuration>
</execution>
</executions>

WebSphere problems with webservices when build/deploy with Maven

I am in the process of migrating an application to be built and deployed with Maven. It's deployed on WebSphere 7. I've managed to get part of this application (HTML UI and such) working fine, but the web services are having a problem.
When I try to access the URL for the web service (such as localhost:9000/MyApplication/MyWebServiceProject/MyService), I expect to see a page that say something like "Hello, this is a web service!".
Instead, I see this exception:
[4/1/13 11:49:37:484 EDT] 0000001d WASAxis2Servl E The following exception was encountered while attempting to load the ConfigurationContext for the servlet: com.ibm.ws.websvcs.exception.ConfigurationException: Could not retrieve server module metadata in Axis servlet for module: MyWebServiceProject
com.ibm.ws.websvcs.exception.ConfigurationException: Could not retrieve server module metadata in Axis servlet for module: MyWebServiceProject
at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.init(WASAxis2Servlet.java:290)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:358)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.init(ServletWrapperImpl.java:171)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:739)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3935)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1613)
I'm guessing there's some IBM-specific configuration that is needed for deploying web services via Maven, but I'm not sure what it is.
Relevant sections from the POM for the EAR project:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<applicationName>PolicyGatewayEAR</applicationName>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>was6-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>integration-test</phase>
<id>uninstall</id>
<goals>
<goal>wsUninstallApp</goal>
</goals>
<configuration>
<wasHome>${was7Home}</wasHome>
<verbose>false</verbose>
<failOnError>false</failOnError>
<profileName>was70profile1</profileName>
<workingDirectory>${project.build.directory}/was6-maven-plugin</workingDirectory>
<applicationName>MyApplication</applicationName>
</configuration>
</execution>
<execution>
<phase>integration-test</phase>
<id>installation</id>
<goals>
<goal>installApp</goal>
</goals>
<configuration>
<wasHome>${was7Home}</wasHome>
<verbose>false</verbose>
<failOnError>true</failOnError>
<updateExisting>false</updateExisting>
<profileName>was70profile1</profileName>
<workingDirectory>${project.build.directory}/was6-maven-plugin</workingDirectory>
<applicationName>MyApplication</applicationName>
</configuration>
</execution>
</executions>
</plugin>
POM snippet for the web-service sub-project:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<warSourceDirectory>WebContent</warSourceDirectory>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
This wasn't a problem when I was deploying to WAS using RAD (v8.5) - it's only started since I tried build and deploy the application using Maven. Does anyone know how to resolve this error?
So it turns out that I had to use the same solution as desribed here:
Deployed webservice schema does not match what's in workspace
For some reason, WebSphere was unable to generate the WSDL from code when the WSDL and schema files were not provided in the Maven-build project. The error message I reported is similar to one that I saw when I was running tests with including the WSDL and schema in the EJB project.

CertificateException: No name matching hostname found Maven

I have an HTTPS WSDL URL (https://hostname/MyApp/MyApp.svc?wsdl) that needs to be consumed in a Maven project. The certificate on WSDL is expired and is issued to hostname.company.com.
I have following code in Maven pom.xml
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<scope>compile</scope>
<version>2.1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<wsdlUrls>
<wsdlUrl>https://hostname/MyApp/MyApp.svc?wsdl</wsdlUrl>
</wsdlUrls>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I do a clean and build, I get following error
[jaxws:wsimport]
Processing: https://hostname/MyApp/MyApp.svc?wsdl
jaxws:wsimport args: [-s, C:\WorkspaceNetBeans\Maven\WSTest\target\generated-sources\jaxws-wsimport, -d, C:\WorkspaceNetBeans\Maven\WSTest\target\classes, https://hostname/MyApp/MyApp.svc?wsdl]
parsing WSDL...
java.security.cert.CertificateException: No name matching hostname found
Failed to read the WSDL document: https://hostname/MyApp/MyApp.svc?wsdl, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>.
failed.noservice=Could not find wsdl:service in the provided WSDL(s):
At least one WSDL with at least one service definition needs to be provided.
Failed to parse the WSDL.
I added the certificate to keystore using keytool utility. What else do I need to do?
You can download your wsdl locally from web browser and then run wsimport on that local file to generate your Java model.
You have the possible options:
1) Import the certificate of the server in to the Trust Store, also ensure that the CN name presented in the Server Certificate is same as the Hostname you are using. This link can be helpful:http://bluefoot.info/howtos/how-to-avoid-java-security-cert-certificateexception-no-name-matching-localhost-found/
2) Use a tool like Netbeans or eclipse which can ignore (I doubt it though) SSL aspects of the server.
3) Create a local version of the WSDL resolving all the dependent XSD references and use that WSDL.