JAX-RS EJB container - jax-rs

I have an .jar application (using ejbs) deployed as part of an .ear archive.
Inside this .jar application I have classes annotated with #Path and #Stateless.
My question is: Are my JAX-RS resources going to be deployed inside an EJB container or inside WEB (Servlet) container? Do I need to define web.xml and to put servlet definition inside of it?

Are my JAX-RS resources going to be deployed inside an EJB container or inside WEB (Servlet) container?
It will be deployed to the servlet container of your EE server.
Do I need to define web.xml and to put servlet definition inside of it?
Not necessarily. You can configure a JAX-RS application simply by having an empty Application subclass annotated with #ApplicationPath1.
#ApplicationPath("/api")
public class RestApplication extends Application {}
If you want to use a web.xml, you can instead of this class. If you do want to, just look for a tutorial to show you how to do it. But this class is all that is needed for the most basic configuration.
Footnotes
See How to use Jersey as JAX-RS implementation without web.xml?

Related

Is there a way to register a JAX-RS Provider in Quarkus application.properties?

I'm trying to register a class that implements javax.ws.rs.core.Feature in my Quarkus application. I understand that using #Provider annotation on the class should do it but this class is contained in an external jar so that's not an option. I want to avoid having to extend javax.ws.rs.core.Application and return my Feature implementation from getClasses(). Is there a property I can set in application.properties to register this Feature implementation?
No, you can't do that.
However, you can make Quarkus look for #Provider classes in the external JAR. See this for more details

Quarkus Jax-rs clients with external interfaces

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);

InvalidOperationException: A named connection string was used, but the name was not found

I have two project one .net core web api and another class library where i have dbContext file. And i have created one separate class in class library to get data from database. But it's showing above error.
You will need to add the connection configuration to the main Web API project. Simply copy the relevant section from your class library config to your web api one.
The reason is simple, the solution will build, your class library becomes a dll and that dll is copied over to the web api's bin folder and is loaded from there.
The web api does not have the connection details in its configuration so you get this issue.

How to use Spring Rest Service with REST Component in Mule

Hi I am working with Mule Studio and I want to use Spring Rest Service with REST component in the Mule. So how can I access Spring REST features with REST Component I don't want to use Jersey way of creating REST service with Mule.
I just want to declare one REST controller with spring annotation that will automatically invoke.
Mules Rest Component is a Jersey implementation of JAX-RS which loads the resource classes so that they can be accesses as Rest URLs.
Spring Rest Controller is the Spring way of creating a Rest service which runs ona web-container.
If you want to run the SpringRestController based rest service on Mule you can package and deploy it directly on Mule standalone. Mule can run a web applicaiton as it contains an embedded Jetty container.
Unfortunately you cannot include a Spring RestController into the Mules's REST component(which is a Jersey implementation). Controller's purpose is not to serve as a component.
By the way in Mule also you just need to specify the annotations and provide the resource class to the REST component. Mule takes care of the rest.
Hope this helps.

How do I initialize my container when using the Common Service Factory

The Common Service Factory website specifies the following steps for its usage:
Download the latest release of the Common Service Factory library
Download the latest release of the Common Service Locator library and
the adapter for the IoC container that you are using
Add a reference to the CommonServiceFactory.dll, Microsoft.Practices.ServiceLocation.dll and the assembly that contains the adapter for your IoC container
Edit the .svc file for your service so that Service attribute
contains the Assembly-Qualified Name of the service type
In the .svc file, add the Factory attribute and provide the
Assembly-Qualified Name of on of the factories that are available
(ServiceHostFactory for SOAP services and WebServiceHostFactory for
RESTful services) in the Common Service Factory library
Configure your IoC and setup the Common Service Adapter
Enjoy using loosely coupled dependencies in your WCF services using
the IoC container you prefer
I just don't know where should I do the second to last step: Configure your IOC and setup the Common Service Adapter.
Does anyone has an example of how to use the Common Service Factory?
Thanks a lot.
You typically setup your container in the startup path of your application. For a ASP.NET application for instance, this would typically be the Application_Start event. After you created the container, you wrap the container into a Common Service Locator adapter for the given container and supply it to the ServiceLocator.SetLocatorProvider of the CSL project and you're done.
This is how it looks like when using Simple Injector:
var adapter =
new SimpleInjectorServiceLocatorAdapter(container);
ServiceLocator.SetLocatorProvider(() => adapter);