I am developing a web application using JSF 2.3. I need to create a Servlet which makes an HTTP connection to an URL and get a JSON object and process it. There are many third party APIs available for this sake, but I am more interested in using HttpClient which comes default in JDK11 onwards.
But the problem I face here is, I cannot use HttpClient without modularizing i.e. defining it as a requirement in module-info.java for my application. And, if I define module-info.java I can't get servlet classes reference resolved in my code. javax.* dependencies and other third party dependencies are not resolved. All the required libraries are present. So my question is
Q1. How can I use HttPClient in a Java web application with servlets, and JSF framework?
Q2. How do I resolve third party dependencies in a moduler java application?
I am using Payara server 5, JDK-11, RHEL 7.9
Related
I am using aws sdk package to access aws api from web application deployed in a websphere application. During build the application doesn't throws any compile time issue. After deployment it throws java.lang.NoSuchFieldError: org/apache/http/conn/ssl/AllowAllHostnameVerifier.INSTANCE
I read some post, it says about jar conflict. Its taking the default httpclient jars from IBM. I want to point my code to take my version of httpclient which I have given in lib folder. Can someone help me to point my code to pick my version of jars added manually.
In order to make your app use its own version of something that's included in the server, you'll need to use parent-last class loader delegation. Assuming the Apache HTTP client is in your web module's WEB-INF/lib directory, you'll want to make that change to the web module's class loader setting (this doc is specifically from 8.5.5 but should work on any version from the last decade or so): https://www.ibm.com/docs/en/was-nd/8.5.5?topic=loading-configuring-web-module-class-loaders
Note that parent-last delegation comes with its own set of risks, as there are some things that don't play well with the server if you try and use a version in your app (the Servlet API is one of the more notable ones). If you try this but run into things like ClassCastExceptions or LinkageErrors, you may instead want to put the HTTP client into an isolated shared library (selecting the "use an isolated class loader for this shared library" option) and associate the shared library with your web module or application: https://www.ibm.com/docs/en/was-nd/8.5.5?topic=servers-managing-shared-libraries
All that said, the simplest solution might just be to update your server. An APAR several years ago (PI50993, included in fixpack 8.5.5.9) removed the application visibility to the server's version of the Apache HTTP client. Moving to a recent fixpack would probably resolve the issue as well.
I had an application running in Webphere 6 and JDK 1.6. Now I'm trying to migrate it to Whephere Application Server 8.5. I get a problem related to libraries used to consume SOAP Services (Im using CXF). The problem is that Webphere in this version, has its own libraries to do this (AXIS2). I followed IBM recomendations
'Using a third-party JAX-WS web services engine'
-https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.nd.doc/ae/twbs_thirdparty.html-
IT DOESN'T WORK FOR ME
However, I found that someone solved it removing a file from the META-INF AXIS2 library in Websphere. (javax.xml.ws.spi.Provider) =====IT WORKED===== But now I'm having other derived problems
org.springframework.web.util.NestedServletException: Handler processing failed;
nested exception is java.lang.NoSuchMethodError
org/apache/ws/commons/schema/XmlSchemaCollection.read(Lorg/w3c/dom/Document;Ljava/lang/String;)Lorg/apache/ws/commons/schema/XmlSchema;
(loaded from file:/usr/IBM/WebSphere/AppServer/plugins/org.apache.axis2.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader#41aaaf6e)
called from class org.apache.cxf.common.xmlschema.SchemaCollection (
loaded
from file:/usr/IBM/WebSphere/AppServer/profiles/AppServer01/installedApps/CLDC462Cell01/MyApp.ear/myapp.war/WEB-INF/lib/cxf-core-3.1.5.jar
by
com.ibm.ws.classloader.CompoundClassLoader#5344aede
Your app is picking up some Apache classes from the WebSphere libraries rather than from your application, and the version in WebSphere is incompatible with the app's version of CXF. This means that you're going to need to add a jar containing an appropriate version of org.apache.ws.commons.schema.XmlSchemaCollection to your application. I presume that you're running with PARENT_LAST delegation in your web module already, given that you're using your own web services implementation, but if not, that will be necessary as well.
I just started developing with Java EE and JSF 2.x. Till now I'm very proud of my small applications with Connection to databases and ldap.
Now I need to connect to our Application API via some exteral jar libraries(C:\Program\A\lib1.jar, C:\Program\A\lib2.jar) so that I can add / change things / settings via JSF Webpages over Application API.
I have no idea how to solve this.
Any idea or helpful explanation or tutorial how to do that? (I'm using Wildfly 10.1) and I'm not using Maven.
Putting the jar files as dependency leads to a ClassNotFound exception.
It would be very helpful to get an example on how to add and accesses external jar libraries.
I am developing an web application using rest web services.
I am using netbeans.
After creating the web application wizards, for creating web service
1. new-> RESTful web service from patterns -> simple root resource
2. after filling class name, package and all details, netbeans has usually option for
Use Jersey Specific Feature
In my office PC this option is there. I have install the same version of netbeans at home PC, but I am not seeing the above Use Jersey Specific feature option.
I have tried with adding jersey-core-1.13.bundle in the library as found it while googling around, but it didn't work.
I am using netbeans 7.3.1 and JavaEE 7
How should I do the same?
Hi this use jersey feature option is coming in specific configurations of jersey/JEE/Netbean. It's referenced as a bug on netbeans. It's well explained in a netbean post. Please take a look at netbean reference bug
NETBEAN BUG EXTRACT :
It's working as designed. We support REST configuration by using javax.ws.rc.core.Application subclass only.
The "Use Jersey Specific features" panel(section) was removed for
JavaEE 7 we applications, or in JavaEE 6 when Jersey 2.0 is detected
on classpath.
Thus, the use cases are the following:
1.JavaEE 7 (JAX-RS 2.0):
- javax.ws.rc.core.Application subclass configuration
JavaEE 6 + Jersey 2.0 on classpath (e.g. GlassFish 4 or Tomcat with Jersey 2.0)
javax.ws.rc.core.Application subclass configuration
JavaEE 6 + Jersey 1.x on classpath (e.g. GlassFish 3.1)
javax.ws.rc.core.Application subclass configuration or
Jersey specific configuration using web.xml
Note: this is the only case, when "Use Jersey Specific features" panel
is available
JavaEE 5 + Jersey 2.0 on classpath
Jersey specific configuration using web.xml
The general approach with REST is to get rid of Jersey specific stuff
as most as possible, and use rather JAX-RS only.
Ken, could you please update the tutorial, and remove the "Use Jersey
specific features" section (bottom wizard panel in step 5). Also the
next panel in step 5 ("Rest Resources Configuretion" panel) was
removed, and is not available anymore.
enjoy :)
In application where it requires Spring 2.0 jar and wants to interface with webservice but client.jar provided by webservice host require spring3.0 jar.. so is there any way to implement both versions of Spring?