How to create service first soap webservice using spring-boot - java

We can see many tutorials that shows how to produce soap webservice using xsd in spring-boot. Is it possible to create soap webservice without xsd and from plain Java code using spring-boot-webservice module like we do using #webservice annotation in jax-ws

Guides like this start with an xsd file because they use xjc to create java classes from the XSD definition. xjc creates classes with JaxB annotations (javax.xml.bind.annotation). JaxB is an xml binding specification that has been part of the JDK since 1.6, and it requires that all types from the xsd exist as java classes.
I suggest that you do a tutorial that starts with an xsd an take a look at the auto generated classes. There is nothing to prevent you from writing you own classes instead of generating them from a wsdl, and if you don't refer to external schemas I prefer to do the code only approach (I hate xml configuration).
If you look at the tutorial, the gradle task "getJaxb" will create .java files into "build/generated-sources" compile them and copy them into "build/classes" if you copy the *.java files into "src/main/java" (keep the package structure) and delete delete/disable the "genJaxb" task in gradle, and delete your build folder, everything still works (it actually works better since you normally have red lines in your IDE because the XML beans don't exist until you run the generator the first time).
Now all you need to do is master the JaxB annotations, so you can write your own beans.

Related

Load WSDl file from Spring Boot jar file?

Sorry if this is a duplicate, I looked at several other questions but none seemed to match or provide workable solutions.
Problem
I am writing a Spring Boot (v2.0.2) app, this app exposes a RESTful API which then calls into a WSDL service. I've generated the WSDL classes with Maven/jaxb plugin and everything works from my dev machine. When deployed to the server I get an error that the WSDL service class can not load the underlying WSDL file. The problem is that when the Java classes are generated it is using the full path from my dev machine (snippet from the generated service class)
try {
URL baseUrl;
baseUrl = com.mytest.WSDLService.class.getResource(".");
url = new URL(baseUrl, "/home/users/me/projects/wsdltest/wsdl/MyWSDL.wsdl");
} catch (MalformedURLException e) {
The WSDL file (MyWSDL.wsdl) is in the spring boot JAR file for my application, it is in a subdirectory off root called 'wsdl'
Question Is there a way that I can load this WSDL from the JAR file without having to modify the generated classes?
Ideal Solution I'm hoping to find a solution that doesn't make me modify the generated files (we intend to do this for several services), ideally I'd like a solution which can be done at build time (in the pom.xml?), if that's possible.
Solutions Tried
A post on here suggested using the "wsdlLocation" tag in my pom.xml and provide a explicit path to the WSDL file, e.g. <wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>
Tried most of the solutions from this thread
Thanks in advance
I think I was able to find a solution thanks to this SO Thread. Evidently the answer depends on the version of the jaxws tool being used in maven (jaxws-maven-plugin). The project (which I inherited) explicitly asked for version 1.12 (which invoked JAX-WS RI 2.1.7-b01-), using this version of the tools I was able to use the '<wsdlLocation>classpath:wsdl/MyWSDL.wsdl</wsdlLocation>' solution in the thread mentioned. Once I noticed that the pom was using an explicit version I removed that the jaxws was updated (using JAX-WS RI 2.2.10) but then the 'classpath' solution stopped working. I switched to the other option mentioned in the thread '<wsdlLocation>/wsdl/MyWSDL.wsdl</wsdlLocation>'
I did a quick test and this seemed to have solved the problem (in both my dev machine and my test site).
Thank you

JAXB package-info.java declarations are ignored in separate maven modul

I use package-info.java to specify #XmlAccessorType(XmlAccessType.NONE) and some xml java adapters using #XmlJavaTypeAdapters. Model objects (with JAXB annotations) are placed in separate maven module shared by other modules. The configuration in package-info.java is not discovered if model objects are in separate maven module. If I move for testing purposes model objects to same maven module everything is OK. I think separate maven module can be considered equivalent to 3rd party lib from JAXBContext point of view. I use JDK1.7 JAXB reference implementation. Any ideas how configuration may differ?
I also encounter this problem, in my case qualified/unqualified property from package-info.java was ignored. I managed to find two way to workaround this:
like Pavla wrote, copy all JAXB classes with package-info.java locally
include module as a dependency with compile scope (which gives similar result that classes are in module. In my case I created separate jar lib with JAXB classes)
I also spotted that it do not work only in case of creating WebServices (creating object and sending to WS works fine in different modules).
I am using Jbossas7.1.1 and cxf 2.4.6. In the time of registering service Jboss created wsdl from JAXB (in my case path /opt/jboss/jboss-as-7.1.1.Final/standalone/data/wsdl/module.war/SubmitMessage.wsdl). In local setting file is generated properly.
Any ideas why creating WS behaves like this?
I hit this issue recently and the actual problem (with Java 8, i.e. no Java modules involved) was that I had on the classpath two *.jar files which both contained the same package - in one JAR, there was package-info.class with JAXB annotations and in the other one, there wasn't.
In that case, I guess that if package-info.class file is discovered depends on the classpath ordering (which is very brittle and only semi-deterministic).

"Use <jaxb:property> to resolve this conflict" error while converting xsd to java objects using jaxb

I am trying to unmarshall elements of xds file to java oblects. I am using Jaxb mavan plugin and Eclipse IDE.
My .xsd file is can be found from
EiPayload
EiEnrollment
EiClasses
Here is my file structure and error,
Need some help to debug this error..!
Disclaimer: I am a lead dev of the ogc-schemas and the w3c-schemas projects.
You have problems with GML 3.2.1 and XLink 1.0. I've implemented bindings for these schemas in the ogc-schemas and the w3c-schemas project. Here you go:
gml-v_3_2_1.xjb
xlink-v_1_0.xjb
But better use the provided JAR artifacts as episodes.

Create POJO class structure using JAXB from XML

I have looked at below mentioned question:
Java JAXB how to create POJO classes
Java JAXB xml pojo classes
Here is what I want to do.
I want to use JAXB and create POJO Java classes at runtime. If I change my XML in future, I don't need to make change POJO Java class structure manually. I need to only restart whole Java Application and it will generate all classes at runtime without user input
FYI :-
using XJC is not helpful as i can not merge it into application.
I have already automated whole business logic which is not affected by XML file.
Here are some maven modules which you may find helpful
jaxb2-maven-plugin
Mojo's JAXB-2 Maven plugin is used to create an object graph from XSDs based on the JAXB 2.1 implementation and to generate XSDs from JAXB annotated Java classes.
maven-jaxb2-plugin
This Maven plugin wraps and enhances the JAXB Schema Compiler (XJC) and allows compiling XML Schemas (as well as WSDL, DTDs, RELAX NG) into Java classes in Maven builds.
jaxb2-maven-plugin
This plugin uses the Java API for XML Binding (JAXB), version 2+, to generate Java classes from XML Schemas (and optionally binding files) and to create XML Schemas from annotated Java classes

Modify Enunciate generated configuration file to use the latest jackson library for CXF

Enunciate generates the cxf-jaxrs-servlet.xml file automatically and specifies: org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider as the JAX-RS provider. This class has changed to com.fasterxml.jackson.jaxrs.JacksonJaxbJsonProvider in the latest Jackson library. How can I make Enunciate specify the new class as the JSON provider in the automatically generated file? Or can I make Enunciate to use a user provided XML file?
I had a similar issue and am using Maven with Spring. I was able to solve this by using the maven replacer plugin and setting it to overwrite the org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider in jaxrs:providers and replacing it with com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider.
Unfortunately, there's not a good way to do that at the moment. We're tracking support for Jackson 2 at ENUNCIATE-719.

Categories