Quarkus Jax-rs clients with external interfaces - jax-rs

I started playing around with Quarkus and its REST client. According to the documentation a Jax-RS annotated interface should be created and annotated further with #RegisterRestClient.
My issue is that I already have the JaxRS interfaces for the services I need to connect to, in an artifact provided by the server, which I can just import. Is there a way to use an already created external Jax-RS interface to create a service with? It seems so wrong to copy-paste the code for a perfectly good interface, when it has been so nicely served for me.

There's RestClientBuilder, which allows programmatic usage of JAX-RS interfaces. Assuming the JAX-RS interface is called HelloClient, you can do this:
HelloClient client = RestClientBuilder.newBuilder()
.baseUri(URI.create("http://localhost:8080"))
.build(HelloClient.class);

Related

Using a JSON-API server library in a Ktor application

I have a Ktor application (in Kotlin) and would like the endpoints to be exposed according to the JSON:API specification. I understand my library options are between the Java server libraries for JSON:API, i.e. Katharsis (which gives code examples for Dropwizard, Spring Boot etc.) and Crnk (which gives example for Spring Boot). I have tried a bit with Katharsis but it's not clear to me how the ResourceRepositoryV2 class should be registered/exposed by the Ktor application.
Any examples or pointers?

what does Swagger server stub mean?

What does the term Server Stub mean in the context of the Swagger ecosystem? How is it used?
From a swagger tutorial:
With SwaggerHub, you can easily generate a server stub (an API implementation stub) for Node.js, ASP.NET, JAX-RS, and other servers
and frameworks. The server stub is a good starting point for
implementing your API – you can run and test it locally, implement the
business logic for your API, and then deploy it to your server.
https://app.swaggerhub.com/help/apis/generating-code/server-stub
and a stub is:
method stub or simply stub in software development is a piece of code used to stand in for some other programming functionality. A stub may simulate the behavior of existing code (such as a procedure on a remote machine, such methods are often called mocks) or be a temporary substitute for yet-to-be-developed code. Stubs are therefore most useful in porting, distributed computing as well as general software development and testing.
https://en.wikipedia.org/wiki/Method_stub
Stub the API means : create à mock to serve examples described in swagger file.
This mock can be formatted in specific languages/ framework
Server stubbing can be quite powerful depending on the backend platform and framework you plan to use for your API.
For example, you may choose Apache (common in Linux environments) or ASP.NET (common for IIS). The server "stubs" being generated will typically be a deployable library to that specific platform. What you typically get is:
Routing to your business logic. The framework will handle the HTTP specification, but actually mapping from a "controller" to your service layer is being handled by the code generator, based on your API specification.
Serialization and Deserialization of your models (applies to strongly-typed languages like Java/C#).
AuthN/AuthZ may be handled, to some degree, based on the framework's support for your API's chosen auth scheme.
tl;dr: A server stub is intended to be a ready-to-deploy application that routes HTTP requests to your actual business logic on the backend.
From my experience and peers, I found stub to be a mock function or a placeholder function where you can fill in the proper implementation later.

Creating a RESTful WebService without using Jersey or any other libs

okay you might say its a duplicate of this.
It might be but the answer is still yet to be found.
Isn't there any way we can make a RESTful web service without using jersey or for that matter any other libs?
I am searching for the past 5 days for the answer to this question!!
You should be able to accomplish this with servlets.
Create a servlet for each service or url that you expose to your service consumers.
Eg. For a user CRUD service, create a UserServlet and specify the mapping as /user/*.
Consumers of your service, will hit urls such as
http://yourdomain.com/user
http://yourdomain.com/user/23
for various RESTful operations.
Inside of the servlet, you should be able to extract the request parameters, form data, request headers and context information.
For a detailed discussion on how to design your restful api and best practices, search "Restful API Design". Here are a couple of links to get you started
https://blog.apigee.com/detail/api_design_third_edition_video_slides
https://blog.apigee.com/detail/slides_for_restful_api_design_second_edition_webinar/
If you want to use JAX-RS, which is a specification, you must use an implementation of this specification. Jersey is the Reference Implementation of JAX-RS but any other implementation is fine, too.
You can write a service with a RESTFul interface using plain Servlets. But why reinvent the wheel? You really don't want to do this. But if you must, read the Java EE Tutorial on Servlets. But a Servlet will not be RESTFul without further work. You can easily fall into the trap of writing a RPC-style service.

axis2 vs spring-ws vs jersey

My friend asked to explain me what's the difference between Spring, axis2 and Jersey. Here I listed down a few differences that I'm aware of. Please comment/respond if you know more differences
Spring webservices:
A java web application with a servlet configured in
web.xml(org.springframework.ws.transport.http.MessageDispatcherServlet).
You can use spring annotated POJOs for creating web services
Supports both RESTful and SOAP based web services.
Since it’s a web application you can use http authentication mechanisms
for enabling security
Axis2:
The webservice application is a .aar file that will be deployed in
axis2.war
Use AXIOM for using non-primitive type arguments to web service calls
You can use JSR181 annotations to create webservices
You can use spring-dependency injection using axis2 extensions.
Supports both RESTful and SOAP based web services.
I guess you have to use ws-security implementation for
providing security
to your web services>
They claim hot deployment of webservices works but I haven’t seen
it working.
Jersey:
A regular web application with a servlet configured in web.xml.
Write custom message readers/writers for using
non-primitive type arguments to web
service calls
Since it’s a web application you can use http authentication mechanisms
for enabling security
Supports only RESTful implementation of web services
I have seen hot deployment working may be because it’s a web application
and the container can do hot
deployment
I'm not familiar with Jersey and Axis, but I can tell you something about Spring-WS.
You cannot use Spring-WS for restful webservices. Spring-WS is intended to be used for contract first webservices. You can however use the features of Spring 3.x and Spring-MVC for REST services.
As for authorization, you can easily wire in any sort of security (with Spring-Security for instance).
I'm a big fan of the 'automatic' (de) marshalling features of Spring-WS. Just annotate your methods with the correct types and it'll know what to do.

WCF WinService with Plugins

I have a win32 application that uses client side plugins and uses a Win32 Service via TCP/IP. I would like to also dynamically load assemblies on the WCF service based on the addition of new plugins. Currently I have to add the the ServiceContract and OperationContract to the Services class and IService interface and then re-compile. Is there a way to dynamically load the WCF assemblies and not have to generate the class and interface references? Can these be moved out of the WCF Win32 service into external classes?
I was wondering about this as well, but came to the conclusion that this was not a question of whether or not its possible, but should you do it? Even if you could generate the contract definitions dynamically, you still need to notify the client of the change, they in turn would need to regenerate the proxy in order to interact with the new service definition, and then provide an implementation dynamically. A better approach is to redesign your service so it implements a particular strategy (read Strategy pattern). The contract remains static, but the implementation changes based on client input. That way your service can dynamically load modules without your client being aware of it.
HTH.
Steve