Validating JAX-RS resources and methods (IBM JAX-RS implementation) using bean validation on Websphere Application Server 8.5.5 - jax-rs

I am using IBM JAX-RS implementation to develop my REST APIs. I am looking to include validation of resource method parameters using Bean Validation (annotations) support provided in JAX-RS 2.0. I know that Jersey implementation supports this feature (https://jersey.java.net/documentation/latest/bean-validation.html). Is there a similar support available with IBM JAX-RS implementation on WAS 8.5.5? If so could you please direct me to some tutorial on how to accomplish this?
I am specifically looking into enabling and configuring Bean Validation support along with its integration with IBM JAX-RS.

Yes, WebSphere (both traditional and Liberty) will support bean validation with JAX-RS. But I am not aware of any tutorials. The code in the Jersey document that you referenced will work with WebSphere's JAX-RS/BV implementation.
To enable JAX-RS and Bean Validation in Liberty, your server.xml must contain the following features:
<featureManager>
<feature>jaxrs-2.0</feature>
<feature>beanValidation-1.1</feature>
</featureManager>
As an alternative, you could include some feature that includes those features (like webProfile-7.0 or javaee-7.0, but that may get you more function than you want).
Then, if you have your application packaged as an EAR or WAR file, you can copy it into your server's dropins directory, start the server and you should be able to run the example (the default HTTP port is 9080).
This link provides additional information about developing and deploying JAX-RS applications in WebSphere Liberty:
http://www.ibm.com/support/knowledgecenter/was_beta_liberty/com.ibm.websphere.wlp.nd.multiplatform.doc/ae/twlp_dep_jaxrs.html
Hope this helps,
Andy

Related

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

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?

How can i implement a form-based authentication in JBoss EAP 7.0.7?

Hi I am new to JBoss EAP 7.0.7! I am trying to deploy an ear file which was previously deployed in JBoss EAP 6.3. In the login page, it uses a form-based authentication with j_security_check. In my jboss-web.xml, the security-domain is set with a valve with class-name org.apache.catalina.authenticator.SingleSignOn.
The application works in JBoss EAP 6.3. I tried to debug it and noticed that it invokes a method from SingleSignOn class as well as FormAuthenticator class.
The problem is that the application does not work when deployed in JBoss EAP 7.0.7. And when I debug it, it does not seem to invoke the SingleSignOn and FormAuthenticator methods. So how can I apply the same form-based authentication in JBoss EAP 7.0.7. (Note: I checked in the documentation and found out about the RH-SSO(Red Hat Single Sign On) but I cant download it.
Thanks in advance for your answer/suggestions.
Do the web applications bundled in your EAR require single sign-on? If not, you don't need to mess with single sign-on.
All you need is to configure a security domain, using one of the methods outlines in the documentation:
https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/how_to_configure_identity_management/
Using form authentication is just a matter of configuring web.xml and jboss-web.xml to use your security-domain name (i.e. realm-name). See: https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/how_to_configure_identity_management/#configuring_an_application_to_use_a_security_domain_with_certificate_based_authentication
While this example demonstrates certificate-based authentication - to configure form authentication, just use FORM instead, and add the requisite and elements (as defined by the servlet specification).

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.

How to choose between Jersey, Apache Wink and JBoss RESTEasy? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I just heard about Apache Wink, and I was wondering what differences it had compared to Jersey or JBoss RESTEasy. What can be done in one that the other two can't?
We've been using Jersey for some of our internal projects mostly for it's simplicity, but I can't really figure out what makes these other two any better that I would consider switching. Does anyone have any use-cases for which niche each of these fills?
JAX-RS Implementations
Jersey
Reference Implementation
Usually the most cutting edge
Supports true asynchronous (ie web sockets etc...) connections through either Atmosphere or 2.0 version.
Has support for Spring and standard injection containers (ie #Inject).
Glassfish bundles it.
Its much more modular than the other JAX-RS projects.
It has a kick ass URI Builder
Does not necessarily require servlet container.
Grizzly support
Netty support (very early).
Swagger support
Sort of missing OAuth 2.0 . You'll have to use other libraries.
Some MVC support through Viewables
Hosted on java.net (a minus as the site is terribly slow at times).
Licensing is based on CCDL 1.1 and GPL-v2. Please make sure you check Jersey licensing before you use it for commercial use
https://jersey.github.io/license.html
RestEasy
Much of the above but most notable supports view technologies (see HTMLEasy)
It does have asynchronous connection support
Cache support
EJB support (if your into that crap)
JBoss bundles it (I think)
Netty support
Arguably the best Spring integration (MVC handler).
Early Swagger support
More security support including early OAuth 2.0 support
Apache Wink (never used it)
I have no idea why this project exists.
Supposedly its high performance focused.
It has a client built on top of HttpUrlConnection (which is a minus... it should be pluggable like Spring RestTemplate).
Basically Wink was developed in house at some enterprise companies and then given to Apache.
Requires a servlet container.
Restlet
Very powerful but very complicated
Provides some low-level REST support
Does not require a servlet container
Apache CXF
Some interesting WADL support.
Reuse and or combine JAX-RS w/ JAX-WS
Security support
Integration w/ Spring albeit kind of nasty
Supposed Autogeneration of client stubs
Other RPC-like systems
Message Queues
RabbitMQ
ActiveMQ
Asynchronous RPC
Finagle -- from Twitter.
msgpack-rpc
My humble opinion
I know the OP asked for REST but if this is for internal communication seriously consider using either a message queue or some other asynchronous RPC (Finagle) instead of traditional REST if your requirements match those systems.
If it must be classic HTTP REST (external) I would choose between either RestEasy or Jersey as a bulk of the mind share is put into those two projects.
Also see: Rest clients for Java?
When choosing the implementation to use have this in mind: if you try to deploy a Jersey web service to JBOSS 7.1, it will not work. This error will occur:
Only one JAX-RS Application Class allowed
This is because REST Easy comes bundled with JBOSS as the default JAX-RS implementation. So, JBOSS will decide that that's the implementation you want to use and will not load another JAX-RS implementation (like Jersey). In order to fix this, you need to add the following lines to your web.xml file:
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
Link: https://community.jboss.org/message/744530
One of my favourite Jersey extensions is Viewables. Viewables allow you to bind your data easily to a JSP page to implement a true Model-View-Controller (MVC) architecture:
http://blogs.oracle.com/sandoz/entry/mvcj
If you're going to use JBoss 7.x you must use RestEasy, 'cause it's integrated in JBoss. To use Jersey with JBoss 7.x, you have to disable RestEasy and it is complicated!