Generating web service proxy classes using wsdl2java/Apache CXF - java

I'm trying to generate a web service proxy using the wsdl2java tool that comes with Apache CXF. The generation itself seems to go just fine, but there are some errors in the generated files, a non-existing constructor is called.
The file offers a solution:
//This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
//API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
//compliant code instead.
So I set out to download and install the 2.2 version of the JAX-WS Api. I found the following installation manual explaining how to endorse these new files: http://dcx.sybase.com/1200/en/dbprogramming/httpserver-jaxws-lesson-two.html I followed every step of this guide, removed the old generated files and generated new ones, but the problem persists.
Any tips and/or tricks?
(now of course, I'm using the -frontend jaxws21 flag to generate the proxy, but still).

<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
This is how I solved the issue using maven:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>generate-sources2</id>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/cxf</sourceRoot>
<defaultOptions>
<frontEnd>jaxws21</frontEnd>
</defaultOptions>
<wsdlOptions>
<wsdlOption>
<wsdl>...</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
EDIT: I've found another way to solve this using maven and cxf version 2.7.3. Add these libraries in your dependencies. You now dont have to use the jaxws21 option:
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>

Related

Spring Boot 3 springdoc-openapi-ui doesn't work

I'm trying to add swagger-ui (OpenAPI 3.0) to a Spring Boot v3 application.
I've added the openapi-ui maven dependency, and it should work as per the documentation.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.11</version>
</dependency>
But apparently, it still doesn't work and localhost:8080/swagger-ui.html returns an 404 error.
What am I missing?
According to the documentation:
For spring-boot 3 support, make sure you use springdoc-openapi v2
https://springdoc.org/v2/
For the integration between spring-boot and swagger-ui, add the
library to the list of your project dependencies (No additional
configuration is needed)
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
This will automatically deploy swagger-ui to a spring-boot
application:
Documentation will be available in HTML format, using the official
swagger-ui jars
The Swagger UI page will then be available at
http://server:port/context-path/swagger-ui.html and the OpenAPI
description will be available at the following url for json format:
http://server:port/context-path/v3/api-docs
server: The server name or IP
port: The server port
context-path: The context path of the application
Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml
Please note that modules have been renamed:
https://springdoc.org/v2/#migrating-from-springdoc-v1
I completely agreed with #JCompetence. Please note that
springdoc-openapi-ui now changed to springdoc-openapi-starter-webmvc-ui
from spring boot 3.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
Please try this. If you want to find more info, please check the official link:
https://springdoc.org/v2/#features
For me it helped, just changed the dependency
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
to
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'
or
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
springdoc-openapi-starter-webmvc-ui doesn't work with spring-boot-starter-webflux
until you include spring-boot-starter-web.
If you include spring security then it is dead.
Maven plugin to generate (Java) code from OpenApi spec (.yml files)
Generator “spring” supports Jakarta namespace
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<configOptions>
...
**<useSpringBoot3>true</useSpringBoot3>**
</configOptions>
</configuration>
</plugin>
Generator “java” (to generate a client) doesn’t support Jakarta namespace yet.
So use the Eclipse Transformer plugin (Javax dependencies need provided scope!)
<plugin>
<groupId>org.eclipse.transformer</groupId>
<artifactId>transformer-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<rules>
<jakartaDefaults>true</jakartaDefaults>
</rules>
</configuration>
<executions>
<execution>
<id>jakarta-ee</id>
<goals><goal>jar</goal></goals>
<phase>package</phase>
<configuration>
<artifact>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
</artifact>
</configuration>
</execution>
</executions>
</plugin>

Generate a Typed OData Client With the OData Generator: Autogenerated code does not compile with SAP library

I generated the code using a maven plugin and the code does not compile.
https://sap.github.io/cloud-sdk/docs/java/features/odata/generate-typed-odata-v2-and-v4-client-for-java
I am using the odata V2 Plugin
I am not sure how to resolve this compilation issue:
The method getHttpClient(String) in the type HttpClientAccessor is not applicable for the arguments (HttpDestinationProperties)
Here is my pom file.
<dependency>
<groupId>com.sap.cloud.s4hana.datamodel</groupId>
<artifactId>odata-core</artifactId>
<version>2.28.0</version> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version> </dependency>
<!-- https://mvnrepository.com/artifact/javax.inject/javax.inject --> <dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version> </dependency>
com.sap.cloud.sdk.datamodel
odata-generator-maven-plugin
3.59.0
You're referring to correct documentation but the version number is your pom is incorrect.
In the documentation, it says 3.x.x, which as of 10.12.2022 would be 3.59.0.
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>odata-generator-maven-plugin</artifactId>
<!-- Please use the latest version here-->
<version>3.XX.X</version>
<executions>
<execution>
<id>generate-consumption</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputDirectory>${project.basedir}/edmx</inputDirectory>
<outputDirectory>${project.build.directory}/vdm</outputDirectory>
<deleteOutputDirectory>true</deleteOutputDirectory>
<packageName>com.mycompany.vdm</packageName>
<defaultBasePath>odata/v2/</defaultBasePath>
<compileScope>COMPILE</compileScope>
<serviceMethodsPerEntitySet>true</serviceMethodsPerEntitySet>
<!-- (Optional) You can add a custom copyright header:
<copyrightHeader>Copyright (c) this year, my company</copyrightHeader>
Or use the SAP copyright header:
<sapCopyrightHeader>true</sapCopyrightHeader>
-->
</configuration>
</execution>
</executions>
</plugin>
It feels like you're using an existing project based on an outdated and deprecated SDK version. Could you try generating a new project and use the maven plugin from there?
You can also check out if the service you're going to use has a pregenrated client library on the SAP API Business Hub. Check this one for example https://api.sap.com/api/API_COSTCENTERACTIVITYTYPE_SRV/cloud-sdk/Java

How to generate java stubs from protobuf for Java target 11 using maven?

I am trying to generate stub using protobuf.
My pom.xml has below code
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>3.8.0</protocVersion>
<includeStdTypes>true</includeStdTypes>
<inputDirectories>
<include>src/main/proto</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.24.0</pluginArtifact>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
However, it generates the source files with target as Java1.8.
I am migrating my apps to Java 11, and have included the below jars in pom.xml file:
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.3.2</version>
</dependency>
However maven protoc plugin generates the files Grpc.java with annotnation javax.annotation.Generated instead of javax.annotation.api.Generated
Is there any other way for generating the java stub with target version as JDK 11.
If you follow the grpc-java documentation, it instructs you to use:
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
Previous versions of the examples used javax.annotation:javax.annotation-api:1.2, which does work, but it was replaced with Tomcat for licensing reasons. In your pom.xml, it seems you might have mixed up "activation" vs "annotation", which look pretty similar at a glance.
I'm not aware of a javax.annotation.api.Generated annotation. I've not seen any real evidence that javax.annotation.processing.Generated is an appropriate replacement for javax.annotation.Generated either.

Best way to consume RPC/encoded webservice?

I need to consume old-school RPC/encoded WSDL webservice for my backend. At first I tried to use Apache CXF and JAX-WS for that, but JAX-WS wsimport tool doesn't eat rpc/enoded WSDL.
[ERROR] rpc/encoded wsdls are not supported in JAXWS 2.0.
I'm also in doubt about using JAX-RPC for this job, because it's way out-dated. Axis 1.4 is 5 years old tool.
Currently I see these three options:
use JAX-WS javax.xml.ws.Dispatch to send and receive SOAP and parse it somehow, one example
use JAX-RPC and gain bad karma for using outdated technology,
do it all manually and hate myself later.
Neither of these sound too good, so I would appreciate if you could give some good leads, thought what to do and how to solve it.
UPDATE
My case was solved with hand editing WSDL from encoded to literal (basically under operations input and output use="literal" was the only replacement) and then I could generate stubs with Apache CXF. It could be done, because endpoint wasn't parsing RPC/encoded exactly and RPC/encoded spec XML couldn't be validated against WSDL).
Although Axis 1.4 may work for you, using Apache CXF with that little WSDL hack, may be a better way.
[Old answer]
For reference -- I opted for using JAX-RPC and Axis 1.4 this time. I generated client code and hopefully can replace it with JAX-WS implementation when service gets upgraded.
In case someone would like (well, "like" is not the right word here ;-) to use Axis 1.4, here is a maven plugin that can generate appropriate classes and Port interface.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<!-- Use your .wsdl location here-->
<sourceDirectory>${basedir}/src/main/resources/wsdl</sourceDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- Here the libraries that you need to call the Axis WS client -->
<dependencies>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<!-- activation+mail: To stop Axis generating WARNING about "Attachment support being disabled" -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
</dependencies>
I have the same problem with a WS RPC style, I have a springboot project with eclipse and java 1.8 and this... WS from a provider(It means that I can't change the published wsdl).
If you're using springboot I 'm using the org.codehaus.mojo plugin to generate the sources and works.
store your wsdl in local (I put it in the root of my spring project Myspringproyectfolder/wsdl/servicio.wsdl)
In the WSDL change all the text from use="encoded" to use="literal" as the upper response says
Change in the POM plugin attributes the to the local WSDL modified instead of the original WSDL URL.
pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlUrls>
<wsdlUrl>wsdl/servicio.wsdl</wsdlUrl>
</wsdlUrls>
<keep>true</keep>
<packageName>com.cbb.facturalo.wsclient.generated</packageName>
<sourceDestDir>src/main/java</sourceDestDir>
</configuration>
</plugin>
4.- run the maven/install to generate the sources, port type, object factory, etcetc.

Tutorial how to create a CXF web service from existing Java code and embed it in Tomcat

Do you know a tutorial how to create a CXF soap web service from existing Java code and embed it in Tomcat, and also generate a wsdl file so that any .NET system would be able to generate client code easily?
I miss that WSDL creation point in, for example this
http://www.ibm.com/developerworks/library/ws-pojo-springcxf/
tutorial. No wsdl file is generated. But still it should be present in my case to provide system interoperability.
Do you know a tutorial how to create a CXF soap web service from existing Java code and embed it in Tomcat,
Embedding to Tomcat (to avoid using spring, opening own port): Servlet Transport
also generate a wsdl file
You java code 2 wsdl also maven plugin exists. But you can get the wsdl from working service by http://host:port/servicename?wsdl url and provide it ;)
To create wsdl file for the existing Java SOAP Service, you can use maven plugin. It will generated wsdl files on {project_home}/target/generated/wsdl/MyService.wsdl
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-simple</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<className>com.foo.MyService</className>
<genWsdl>true</genWsdl>
<verbose>true</verbose>
<frontend>jaxws</frontend>
<databinding>jaxb</databinding>
</configuration>
<goals>
<goal>java2ws</goal>
</goals>
</execution>
</executions>
</plugin>

Categories

Resources