Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating Java Rest Client based on CXF #2017

Closed
peteryhwong opened this issue Feb 2, 2016 · 31 comments
Closed

Generating Java Rest Client based on CXF #2017

peteryhwong opened this issue Feb 2, 2016 · 31 comments

Comments

@peteryhwong
Copy link

As there is now a provision to generate Java CXF-specific Rest server stub (#1854), we would like to see codegen to support generation of Java CXF-specific Rest client. This is because we use CXF as our JAX-RS implementation and would like to leverage this implementation for our client libraries (specifically for inter-service interaction). The current client generator uses Jersey which causes conflict when being used in conjunction with CXF.

@wing328
Copy link
Contributor

wing328 commented Feb 2, 2016

@peteryhwong the Java API client supports many HTTP libraries (e.g. Retrofit, Jersey2.x, etc). Please run java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java for a list of HTTP libraries support.

Ref: https://github.com/swagger-api/swagger-codegen#customizing-the-generator

@wing328 wing328 added this to the v2.1.6 milestone Feb 2, 2016
@peteryhwong
Copy link
Author

@wing328 thanks for this. If I understand correctly, the JavaClientCodeGen supports the following:

        <default> - HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2
        jersey2 - HTTP client: Jersey client 2.6
        feign - HTTP client: Netflix Feign 8.1.1.  JSON processing: Jackson 2.6.3
        okhttp-gson - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1
        retrofit - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)
        retrofit2 - HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)

which do not include CXF client (http://cxf.apache.org/docs/jax-rs-client-api.html), unless you are suggesting an alternative to CXF?

@wing328
Copy link
Contributor

wing328 commented Feb 3, 2016

Yes, that's the list of HTTP libraries supported. CXF client is not supported yet and we would welcome contribution from the community to support that.

You mentioned Jersey (1.x) has conflicts when being used in conjunction with CXF and that's why I suggested other HTTP libraries, which might work with CXF. Do you also encounter conflicts when using other HTTP libraries with CXF?

@wing328
Copy link
Contributor

wing328 commented Feb 3, 2016

And here is the contributing guideline: https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md

@wing328 wing328 modified the milestones: v2.2.0, v2.1.6 Mar 19, 2016
@wing328
Copy link
Contributor

wing328 commented Mar 19, 2016

@peteryhwong do you need help from us to add CXF client support to the Java client?

@peteryhwong
Copy link
Author

@wing328 thanks for asking.

Actually I was thinking if it would not be better if the generation for jersey2, default and cxf would be abstracted to the level of JAX-RS. So that the only difference between them would be the binding at build time. This is so that they would share the same code base.

The problem is that CXF does not provide a thread safe implementation of JAX-RS client. See https://issues.apache.org/jira/browse/CXF-6774

Let me know what you think.

@wing328
Copy link
Contributor

wing328 commented Mar 21, 2016

@peteryhwong Is it correct to say that you can use the Java API client with Jersey2 library to talk to your Java CXF-specific Rest server without issue and you're trying to make the API client (jersey2) conforms to Java CXF following some sort of best practice?

cc @fehguy to see if he's any feedback on this particular topic.

@fehguy
Copy link
Contributor

fehguy commented Mar 21, 2016

@peteryhwong there are many ways to solve this--in most cases, people are very happy to choose a compatible client runtime and have a stand-alone client SDK. They don't care about the abstraction necessarily, and the selection of the base library is all that matters. I don't personally think that complicating the generator with levels of abstraction helps the end users much at all.

@peteryhwong
Copy link
Author

@fehguy @wing328 Thanks for this.

I agree end users might not care as long as if they do not mind the quality or the correctness of the generated code or ever needing to debug through them...

I am thinking in terms of maintaining different implementation of JAX-RS client templates when we could use the same JAX-RS client template for all these implementations. My thinking is around helping to increase the quality of the template, the generated code and also to reduce the complexity of maintaining them.

The same reason applies to JAX-RS server code generation...

@jfiala
Copy link
Contributor

jfiala commented Jun 16, 2016

@wing328 I currently deal with CXF2/3 and would like to improve the CXF server part (to assemble a full usable server) and CXF client part, best both with bean-validation support and same model (#2549). You can assign me #2017 + #2549 if you like, I plan to do this in the next week(s)...

@wing328
Copy link
Contributor

wing328 commented Jun 16, 2016

@jfiala thanks for offering contributions for the improvement. Please let us know if you need any help (e.g. testing)

@cbornet
Copy link
Contributor

cbornet commented Jun 16, 2016

@jfiala IMO, CXF should be done as a library of the jax-rs generator.
Today it differs from JavaJerseyServerCodegen in that it uses JAXB instead of Jackson (I think it can and should use Jackson), it groups the operations by tag and not by path (I don't know cxf but this looks suspicious : what happens if two methods have the same path ? How will CXF resolve the path mapping ?) and it doesn't use the swagger annotations (there should be no harm in adding them even if it cannot produce the online swagger spec).

Other notes :

  • Resteasy should also be done as a lib as the difference with jersey is even smaller.
  • The common templates between jersey1 and jersey2 should be put in the root/common dir.

@jfiala
Copy link
Contributor

jfiala commented Jun 16, 2016

@cbornet: I'd start from the existing Server CXF generator:
https://github.com/swagger-api/swagger-codegen#java-jax-rs-apache-cxf-2--3

I'm using CXF + Jackson right now (as jettison didn't work properly). I'll add this with the lastest CXF/Jackson versions...

Since CXF3 it offers the Swagger2Feature (http://cxf.apache.org/docs/swagger2feature.html) which allows you to generate the Swagger-spec in addition to WADL, looks really nice and also supports Bean-Validation-Annotations + Swagger-Annotations, only more advanced features like nested query parameters or Multiparts are not generated correctly. So one could start off with the Swagger spec and later do code first using the Swagger2Feature after the CXF-generator for server+client is done...

jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 2, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 2, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 2, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 2, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 2, 2016
@jfiala
Copy link
Contributor

jfiala commented Jul 2, 2016

@cbornet: added the cxf client with PR #3281

  • Jackson is used as provider (is already included as dependency of swagger-jaxrs)
  • only cxf-rt-rs-client necessary to allow full client support
  • added bean-validation-api support (currently not supported by CXF wadl2java...)
  • added test templates to generate test classes (currently not supported by CXF wadl2java...)

The current implementation jaxrs-cxf / JavaCXFServerCodegen is in fact the client (interfaces + model).
It would only become the server after adding the implementation stubs.
I suggest renaming it to JavaCXFCodegen and adding a switch to also generate the implementation classes?

jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 3, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 3, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Jul 3, 2016
@jfiala
Copy link
Contributor

jfiala commented Jul 3, 2016

added the complete server WAR (including CXF3 Swagger2Feature + WADL).

@sberyozkin
Copy link

@peteryhwong, re your earlier comment about https://issues.apache.org/jira/browse/CXF-6774, the thread-safe client code was supported for a long time, it is JAX-RS 2.0 Client API which does not provide for a way to have a single thread-safe Client/WebTarget be created and reused, so this is what we did with CXF-6774, added a property to pass to the underlying CXF WebClient via a JAX-RS 2,0 config...
Note CXF WADL and Swagger code will be split into different modules shortly
cheers

@jfiala
Copy link
Contributor

jfiala commented Jul 4, 2016

updated the wiki
https://github.com/swagger-api/swagger-codegen/wiki/Server-stub-generator-HOWTO
added "(scheduled for 2.1.5)" to indicate that it's not yet released...

@wing328 wing328 modified the milestones: v2.3.0, v2.2.0 Jul 7, 2016
@rynger
Copy link
Contributor

rynger commented Aug 8, 2016

Is there particular reason the Path annotation in the JavaJaxRS CXF api template does not use the base path as other implementations do?

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache

Line 15: @path("/")

Would expect @path("/{{baseName}}") as others have surely?

@wing328
Copy link
Contributor

wing328 commented Aug 8, 2016

@rynger I think you actually mean {{basePath}} instead of {{baseName}}.

Do you have time to contribute a PR so that we can review the fix?

@rynger
Copy link
Contributor

rynger commented Aug 8, 2016

I'll try to get a PR sorted for review (would be my first so will need to learn the process).

I pulled the @path("/{{baseName}}") from the resteasy api.mustache template, so I'd assumed that "baseName" was the template property that referred to the swagger basePath.

@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 14, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 15, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 15, 2016
@jfiala
Copy link
Contributor

jfiala commented Oct 15, 2016

@rynger I had to correct the @path annotation at the interface level to @path("/"), as the @path annotation including the full path is already part of the operations. Having the @path annotation at both positions leads to wrong results.

With the annotation at the interface level, the generated code looks like:

@Path("/contextname/myservices")
public interface {{classname}}  {
    @Path("/myservices/mymethod")
    public Response mymethod (String param1);
}

Then users have to access the REST api using /contextname/myservices/myservices/mymethod (duplicate myservices part).

(also see #4003)

jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 15, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 16, 2016
jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 16, 2016
@jfiala
Copy link
Contributor

jfiala commented Oct 16, 2016

added cxf3 JAXRS client in PR #4003

jfiala added a commit to jfiala/swagger-codegen that referenced this issue Oct 17, 2016
wing328 added a commit that referenced this issue Oct 25, 2016
* add pom-file to cxf including cxf-client #2017

* adapt pom sourceFolder in pom.mustache to gen/java #2017

* add test templates for CXF #2017

* optimize mustache template structure, remove tabs #3280 #2549

* refined dependency to swagger-jaxrs #2017

* refined annotations and line breaks #2549

* fix tabs instead of spaces...

* move annotations from getter to field for server model

* cleanup tabs

* add example for gzipping #2017

* add complete WAR to cxf-server #2017

* add readme + rework pom #2017

* add cli switch for beanvalidation #2549

* move beanvalidation into separate subtemplate and reuse for cxf

* add beanValidation java template

* corrected path to mustache file

* fix AbstractOptionsTest, add default false for USE_BEANVALIDATION

* add pom-file to cxf including cxf-client #2017

* adapt pom sourceFolder in pom.mustache to gen/java #2017

* add test templates for CXF #2017

* optimize mustache template structure, remove tabs #3280 #2549

* refined dependency to swagger-jaxrs #2017

* refined annotations and line breaks #2549

* fix tabs instead of spaces...

* move annotations from getter to field for server model

* cleanup tabs

* add example for gzipping #2017

* add complete WAR to cxf-server #2017

* add readme + rework pom #2017

* add cli switch for beanvalidation #2549

* move beanvalidation into separate subtemplate and reuse for cxf

* add beanValidation java template

* corrected path to mustache file

* fix AbstractOptionsTest, add default false for USE_BEANVALIDATION

* add beanvalidation to okhttp-gson library #2549

* cleanup api.mustache for cxf #3281

* temporary fix for invalid BeanValidation-pattern with / #2549

* temporary fix for invalid BeanValidation-pattern with / #2549

* remove jaxrs-annotations from implementation classes #3281

* add configuration to generate spring web application #4003

* clean up unnecessary @path annotation (part of method level!)

* add support for minItems/maxItems #2549

* add support for BeanValidation for query params #2549

* add imports for bean validation #2549

* add switches for various cxf server features #2017

* fix tests #2549 #2017

* re-create bin folder

* cleanup

* cleanup

* Revert "temporary solution for pattern - move to AbstractJavaCodegen #2549"

This reverts commit 82df5e6, reversing
changes made to 65e87f2.

Conflicts:
	bin/akka-scala-petstore.sh
	bin/android-petstore-all.sh
	bin/android-petstore-httpclient.sh
	bin/android-petstore-volley.sh
	bin/android-petstore.sh
	bin/aspnet5-petstore-server.sh
	bin/clojure-petstore.sh
	bin/cpprest-petstore.sh
	bin/csharp-dotnet2-petstore.sh
	bin/csharp-petstore-all.sh
	bin/csharp-petstore.sh
	bin/csharp-property-changed-petstore.sh
	bin/cwiki-petstore.sh
	bin/dart-petstore.sh
	bin/dynamic-html.sh
	bin/erlang-petstore-server.sh
	bin/flash-petstore.sh
	bin/flaskConnexion-python2.sh
	bin/flaskConnexion.sh
	bin/go-petstore-server.sh
	bin/go-petstore.sh
	bin/groovy-petstore.sh
	bin/haskell-servant-petstore.sh
	bin/html-petstore.sh
	bin/html2-petstore.sh
	bin/java-inflector-petstore-server.sh
	bin/java-petstore-all.sh
	bin/java-petstore-feign.sh
	bin/java-petstore-jersey1.sh
	bin/java-petstore-jersey2.sh
	bin/java-petstore-okhttp-gson-parcelable.sh
	bin/java-petstore-okhttp-gson.sh
	bin/java-petstore-retrofit.sh
	bin/java-petstore-retrofit2.sh
	bin/java-petstore-retrofit2rx.sh
	bin/java-undertow-petstore-server.sh
	bin/java8-petstore-jersey2.sh
	bin/javascript-closure-angular.sh
	bin/javascript-petstore-all.sh
	bin/javascript-petstore.sh
	bin/javascript-promise-petstore.sh
	bin/jaxrs-cxf-cdi-petstore-server.sh
	bin/jaxrs-cxf-petstore-server.sh
	bin/jaxrs-jersey1-petstore-server.sh
	bin/jaxrs-petstore-server.sh
	bin/jaxrs-resteasy-joda-petstore-server.json
	bin/jaxrs-resteasy-joda-petstore-server.sh
	bin/jaxrs-resteasy-petstore-server.sh
	bin/jaxrs-spec-petstore-server.sh
	bin/jmeter-petstore.sh
	bin/lumen-petstore-server.sh
	bin/nancyfx-petstore-server.sh
	bin/nodejs-petstore-server.sh
	bin/objc-petstore-all.sh
	bin/objc-petstore-coredata.sh
	bin/objc-petstore.sh
	bin/perl-petstore.sh
	bin/php-petstore.sh
	bin/python-petstore.sh
	bin/qt5-petstore.sh
	bin/rails5-petstore-server.sh
	bin/ruby-petstore.sh
	bin/run-all-petstore
	bin/scala-async-petstore.sh
	bin/scala-petstore.sh
	bin/scalatra-petstore-server.sh
	bin/security/csharp-petstore.sh
	bin/security/go-petstore.sh
	bin/security/java-petstore-okhttp-gson.sh
	bin/security/javascript-closure-angular.sh
	bin/security/javascript-petstore.sh
	bin/security/lumen-petstore-server.sh
	bin/security/objc-petstore.sh
	bin/security/perl-petstore.sh
	bin/security/php-petstore.sh
	bin/security/python-petstore.sh
	bin/security/qt5cpp-petstore.sh
	bin/security/ruby-petstore.sh
	bin/security/run-all-petstore-security-test
	bin/security/scala-petstore.sh
	bin/security/silex-petstore-server.sh
	bin/security/slim-petstore-server.sh
	bin/security/swift-petstore.sh
	bin/security/typescript-angular.sh
	bin/security/typescript-angular2.sh
	bin/security/typescript-fetch.sh
	bin/security/typescript-node.sh
	bin/silex-petstore-server.sh
	bin/sinatra-petstore-server.sh
	bin/slim-petstore-server.sh
	bin/spring-all-pestore.sh
	bin/spring-cloud-feign-petstore.sh
	bin/spring-mvc-petstore-j8-async-server.sh
	bin/spring-mvc-petstore-server.sh
	bin/spring-stubs.sh
	bin/springboot-petstore-server.sh
	bin/swift-petstore-all.sh
	bin/swift-petstore-promisekit.sh
	bin/swift-petstore-rxswift.sh
	bin/swift-petstore.sh
	bin/tizen-petstore.sh
	bin/typescript-angular-petstore.sh
	bin/typescript-angular2-petstore-all.sh
	bin/typescript-angular2-petstore-with-npm.sh
	bin/typescript-angular2-petstore.sh
	bin/typescript-fetch-petstore-all.sh
	bin/typescript-fetch-petstore-target-es6.sh
	bin/typescript-fetch-petstore-with-npm-version.sh
	bin/typescript-fetch-petstore.sh
	bin/typescript-node-petstore-all.sh
	bin/typescript-node-petstore-with-npm.sh
	bin/typescript-node-petstore.sh
	bin/typescript-petstore-npm.json
	bin/windows/akka-scala-petstore.bat
	bin/windows/android-petstore.bat
	bin/windows/aspnet5-petstore-server.bat
	bin/windows/async-scala-petstore.bat
	bin/windows/clojure-petstore.bat
	bin/windows/cpprest-petstore.bat
	bin/windows/csharp-petstore.bat
	bin/windows/dart-petstore.bat
	bin/windows/dynamic-html-petstore.bat
	bin/windows/flash-petstore.bat
	bin/windows/go-petstore.bat
	bin/windows/html-petstore.bat
	bin/windows/java-petstore-okhttp-gson.bat
	bin/windows/java-petstore.bat
	bin/windows/javascript-petstore.bat
	bin/windows/objc-petstore.bat
	bin/windows/perl-petstore.bat
	bin/windows/php-petstore.bat
	bin/windows/python-petstore.bat
	bin/windows/qt5cpp-petstore.bat
	bin/windows/rails5-petstore-server.bat
	bin/windows/ruby-petstore.bat
	bin/windows/scala-petstore.bat
	bin/windows/spring-mvc-petstore-j8-async-server.bat
	bin/windows/spring-mvc-petstore-server.bat
	bin/windows/springboot-petstore-server.bat
	bin/windows/swift-petstore.bat
	bin/windows/tizen-petstore.bat
	bin/windows/typescript-angular.bat
	bin/windows/typescript-angular2.bat
	bin/windows/typescript-fetch.bat
	bin/windows/typescript-node-with-npm.bat
	bin/windows/typescript-node.bat

* Revert "cleanup"

This reverts commit c752ba8.

* Revert "re-create bin folder"

This reverts commit 8a6d413.

Conflicts:
	bin/windows/spring-mvc-petstore-j8-async-server.bat
	bin/windows/spring-mvc-petstore-server.bat
	bin/windows/springboot-petstore-server.bat

* Revert "re-create bin folder"

This reverts commit 8a6d413.

Conflicts:
	bin/windows/spring-mvc-petstore-j8-async-server.bat
	bin/windows/spring-mvc-petstore-server.bat
	bin/windows/springboot-petstore-server.bat

* re-create bin from master

* Revert "re-create bin from master"

This reverts commit d4b5c9a.

* Revert "Revert "re-create bin folder""

This reverts commit 4369b35.

* Revert "re-create bin folder"

This reverts commit 8a6d413.

* Revert "temporary solution for pattern - move to AbstractJavaCodegen #2549"

This reverts commit 82df5e6, reversing
changes made to 65e87f2.

* correct @path to re-activate Swagger support #

* change sourceFolder to default

* re-activate unittest generator + support gzip switch #2017

* add switch to support Spring Boot + integration tests

* add cxf client generator, rename cxf server generator #2017

* add interfaces for language feature support #4003

* add comments #2017

* correct reference to context.xml.mustache #4003

* use dynamic sourceFolder path #2017

* replace tabs with spaces #4003

* use hard-coded sourceFolder #4003

* rename language for backwards compatibility

* cleanup todo comment #4003

* move convertPropertyToBooleanAndWriteBack to DefaultCodegen #4003

* change reference to beanValidation.mustache to local copy for cxf

* cleanup client-side beanvalidation (currently not working in CXF)

* add support for tags #4003

* fix instantiiation of method parameters

* move commonValidationFeature from bus to endpoint #4003
@jfiala
Copy link
Contributor

jfiala commented Oct 25, 2016

@wing328: I think this one is complete with the merge of #4003?

@wing328
Copy link
Contributor

wing328 commented Feb 15, 2017

@jfiala yup, closed via #4003

@peteryhwong please pull the latest master to give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants