Skip to content
Advertisement

Common request/response objects between 2 SOAP webservices in Java

In my project we must call 2 contract first SOAP Web Services with identical Request/Response objects.

As the web services were contract first, I created classes using CXF wsdl2java, now I have 2 set of identical classes in 2 packages. Is there a way I can refactor those classes into a set of classes.

To describe more I have 2 packages, each contain following classes, with exactly identical properties and codes:

JavaScript

and

JavaScript

and

JavaScript

and

JavaScript

and

JavaScript

and

JavaScript

And then I have 2 WebService interfaces which also like each other (bound to different end-points), with different WebService method names

JavaScript

and

JavaScript

As you can see only namespaces and service endpoints and method names are different. Besides these 2 service interfaces, there are 2 package-info.java files which are annotated with different namespaces.

When I tried to move the common classes to another package and use them, as they were not in the same package with annotated package-info.java files, their namespaces were not added correctly to the request envelopes, and I got errors at service endpoint.

So the question is, how can I use 1 set of request/response classes, is it possible at all?

Advertisement

Answer

It’s a bit complex, but you can specify (when applying wsdl2java) a “binding file” that will allow you, via XJC, to customize the way Java classes are generated (eg the package names, the type mapping, etc…)

In your particular case, you should look at “episode“:

A .episode file is generated by the XJC (XML Schema to Java) compiler. It is a schema bindings that associates schema types with existing classes. It is useful when you have one XML schema that is imported by other schemas as it prevents the model from being regenerated.

(Old but) Interesting article:

https://dzone.com/articles/reusing-generated-jaxb-classes

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement