spring-guides / gs-consuming-web-service

Consuming a SOAP web service :: Learn how to create a client that consumes a WSDL-based service
http://spring.io/guides/gs/consuming-web-service
Apache License 2.0
136 stars 164 forks source link

Does not build with jdk 11 #40

Closed edevil closed 5 years ago

edevil commented 5 years ago

Tried JDK 11 with the complete repository out of the box:

[WARNING] The POM for org.glassfish.jaxb:jaxb-runtime:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.glassfish.jaxb:jaxb-xjc:jar:2.2.11 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Error injecting: org.jvnet.mjiip.v_2.XJC2Mojo
java.lang.NoClassDefFoundError: com/sun/xml/bind/api/ErrorListener
gregturn commented 5 years ago

The guides have yet to be fitted for JDK 9+.

If you're investigating because you want to use Spring WS with JDK 11, then you can inspect the project itself, which tests against JDK 11:

https://github.com/spring-projects/spring-ws/blob/master/pom.xml#L690-L770

edevil commented 5 years ago

I was just trying the current Spring ecosystem after being away for a few years. Thought that jdk 11 was the current stable and the best version to use at the moment.

gregturn commented 5 years ago

The whole portfolio is based on JDK 8. But many projects support JDK 11 or higher.

edevil commented 5 years ago

Got it, thanks.

edevil commented 5 years ago

@gregturn Are there any plans to update the guides for JDK 11? Any issue that I can follow? I still haven't been able to make this example work in JDK 11.

gregturn commented 5 years ago

As posted above, if you add the dependencies shown on that profile, Spring Web Services will operate.

Regarding JDK 11 as a whole, the Spring portfolio certainly has support of it, at least for certain projects. But Spring Framework along with everything else is based on Java 8, probably because a huge majority of the Java community is on that version. To push everything up to, say, Java 11, would cut off LOTS of users.

That being said, many parts like Spring Framework and Spring Boot are Java 11 ready, meaning that if you add the extra configuration settings, they will actually operate and leverage some aspects of that.

And on behalf of the guides, there is a plan to add support, similar to the link earlier in this issue. But we haven't had the time to go apply that across the board.

edevil commented 5 years ago

@gregturn I have tried adding several combinations of dependencies/versions, including the exact dependencies of the `pom.xml´ you listed, but I always get the same error:

org.springframework.ws.soap.client.SoapFaultClientException: Implementation of JAXB-API has not been found on module path or classpath.

https://github.com/edevil/spring-test

dsyer commented 5 years ago

Maybe try it with Spring Boot 2.2 and the spring-boot-starter-web-services (instead of the plain bare dependency on spring-ws)?

edevil commented 5 years ago

@dsyer I've updated the test repository to spring 2.2.0RC1 and got the same error:

➜  spring-test git:(master) ✗ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.0.RC1:run (default-cli) > test-compile @ demo >>>
[INFO]
[INFO] --- maven-jaxb2-plugin:0.14.0:generate (default) @ demo ---
[WARNING] The URI [http://localhost:8080/ws/countries.wsdl] seems to represent an absolute HTTP or HTTPS URL. Getting the last modification timestamp is only possible if the URL is accessible and if the server returns the [Last-Modified] header correctly. This method is not reliable and is likely to fail. In this case the last modification timestamp will be assumed to be unknown.
[ERROR] Could not retrieve the last modification timestamp for the URI [http://localhost:8080/ws/countries.wsdl] from the HTTP URL connection. The [Last-Modified] header was probably not set correctly.
[WARNING] Last modification of the URI [http://localhost:8080/ws/countries.wsdl] is not known.
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/Users/andre/work/vc/spring-test/target/generated-sources/xjc/META-INF/sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to /Users/andre/work/vc/spring-test/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/andre/work/vc/spring-test/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/andre/work/vc/spring-test/target/test-classes
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.2.0.RC1:run (default-cli) < test-compile @ demo <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.0.RC1:run (default-cli) @ demo ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v2.2.0.RC1)

2019-10-10 12:13:53.036  INFO 20925 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication on Giedi.lan with PID 20925 (/Users/andre/work/vc/spring-test/target/classes started by andre in /Users/andre/work/vc/spring-test)
2019-10-10 12:13:53.040  INFO 20925 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2019-10-10 12:13:53.726  INFO 20925 --- [           main] o.s.ws.soap.saaj.SaajSoapMessageFactory  : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
2019-10-10 12:13:53.945  INFO 20925 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.429 seconds (JVM running for 1.916)
2019-10-10 12:13:53.954  INFO 20925 --- [           main] com.example.demo.CountryClient           : Requesting location for Spain
2019-10-10 12:13:54.197  INFO 20925 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-10 12:13:54.208 ERROR 20925 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:787) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    at com.example.demo.DemoApplication.main(DemoApplication.java:13) ~[classes/:na]
Caused by: org.springframework.ws.soap.client.SoapFaultClientException: Implementation of JAXB-API has not been found on module path or classpath.
    at org.springframework.ws.soap.client.core.SoapFaultMessageResolver.resolveFault(SoapFaultMessageResolver.java:38) ~[spring-ws-core-3.0.7.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.handleFault(WebServiceTemplate.java:830) ~[spring-ws-core-3.0.7.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:624) ~[spring-ws-core-3.0.7.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) ~[spring-ws-core-3.0.7.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) ~[spring-ws-core-3.0.7.RELEASE.jar:na]
    at com.example.demo.CountryClient.getCountry(CountryClient.java:21) ~[classes/:na]
    at com.example.demo.DemoApplication.lambda$lookup$0(DemoApplication.java:24) ~[classes/:na]
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) ~[spring-boot-2.2.0.RC1.jar:2.2.0.RC1]
    ... 5 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.618 s
[INFO] Finished at: 2019-10-10T12:13:54+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.0.RC1:run (default-cli) on project demo: Application finished with exit code: 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

pom.xml

dsyer commented 5 years ago

Looks like you do need to add the jaxb jars as well. This works for me:

        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
        </dependency>

See also this wiki page: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-with-Java-9-and-above#jaxb

edevil commented 5 years ago

@dsyer I added the jar that was missing, jaxb-api, but I still get the same error. Does the order of the dependencies matter?

I read that wiki page but I did not find anything else relevant to this problem in particular.

dsyer commented 5 years ago

The wiki page recommends adding precisely the same dependency, so I'm not sure what you were reading. The order should not matter, but you have to add the runtime not the api jar. My fork of this repo has that change and it works for me. Check it out.

edevil commented 5 years ago

@dsyer Thanks for the help, but the repository I'm having trouble with is gs-consuming-web-service, not gs-producing-web-service. For some reason the last one works fine while the first does not with the same dependencies...

gregturn commented 5 years ago

The problem appears to be solely in the server.

Running this repo as is works perfectly fine...when the server is running on JDK 8. Thus, something is wrong with the server running on JDK 11.

I figured this out when I dialed up log levels for org.springframework.ws and com.sun.xml.bind to TRACE.

gregturn commented 5 years ago

If you add this ONE dependency to gs-producing-web-service:

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

...then you can bump it's java.version to 11 and run it.

That, combined with the changes found in https://github.com/edevil/spring-test/pull/2 should do the trick.

dsyer commented 5 years ago

I got it working (on the consumer side as well) too. I had to bump the jaxb plugin version to 0.14.0 (in addition to adding the jaxb runtime).

edevil commented 5 years ago

@dsyer Wow, thanks! :) You saved me a lot of time. Everything seems to be working now.

edevil commented 5 years ago

@dsyer Yeah, I had already bumped that version. I was completely unaware that this new problem was on the server side.