CXF (and interceptors) and 2.5 webapps - servlets

I've a very basic question. When and How will CXF kick in if my webapp is 2.5 or higher. The weblogic 10.3 that I'm running picks up the WS annotation defined in my web-app.
Until now I had web-app version 2.3. When I upgraded it to 2.5 in webapp XML, I noticed my interceptors are not getting kicked in because now weblogic is able to handle the annotation and CXF is out of picture (based upon stacktrace analysis).
Is my observation correct, or am I totally wrong? I just changed from:
<DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
to
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

I didnt want to mess with WL as we have more than one app running on the WL.So the simple solution was to use the handlers. See here: handlers_introduction.

You are right, changing Servlet version to 2.5 triggers autodiscovery of classes annotated with #WebService annotation.
To prevent this you have to tweak classloading policy. On Apache CXF site there is a good description: Apache CXF - WebLogic
According to this website you have two options:
"Put the geronimo-ws-metadata_2.0_spec-1.1.1.jar in the $Weblogic_Home/jdk_../jre/lib/endorsed folder." - this will affect whole server and might break other web services running on WebLogic
"Pack war in an ear, deploy the ear with weblogic-application.xml" - this way you change classloading policy for single EAR application, not for whole server.
I prefer to use solution based on weblogic-application.xml, as it is more portable.
However it didn't work for me immediately, I had to add additional library to EAR/WAR - geronimo-ws-metadata_2.0_spec-1.1.1.jar.
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
<version>1.1.1</version>
</dependency>
If you don't have yet EAR archive you have to create one. Assuming you are using maven:
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes -DarchetypeArtifactId=ear-jee5
And add your WAR project to dependencies.

Related

Embedded Tomcat without unpacking

What steps are required to make a executable war without unpacking the war. ( Similar to the way spring boot does). Basically want to wrap Embedded Tomcat into existing war and make it execurable.
Env: Spring mvc, Java 7, Webapp with web.xml
So far I have done following research:
How Spring boot creates Embedded container in TomcatEmbeddedServletContainerFactory, but all those WebApploader stuff I'm not able to understsnd.
Successfull in packaging a executable war just using spring boot maven plugin but not able to run without unpacking it.
Tomcat api class doesn't read app from war directly.
Have successfully tested embedded tomcat by extracting it in a particular location and calling addWebapp method.
I do not want to create a big fat jar using shade plugin.
Do not want to specify path like src/main as indicated on many examples on the internet.
Upgrading the app to spring boot web is not possible due to time and other dependencies.

java EE project encountered NoClassDefFoundError

I am working on a Java EE project with
jdk 1.8
wildfly 10.1.0 final
intellij idea 2016.3
The project has a web application module and an ejb module, and the structure is as follows:
And the two modules have already been deployed successfully
But when I tried to call the session bean, the ejb project went wrong and threw an error
Caused by: java.lang.NoClassDefFoundError: org/json/JSONArray
I use JSON in class DAOHelperImpl in the ejb module, and I've already add the dependency. I tried to put the jar in various packages such as /ejb/lib or /web/web/lib, but none of them are working.
What's wrong?
Move the jars libraries from /web/web/lib into
/web/web/WEB-INF/lib
By Convention the general folder for auto included jars is:
web-project-name/webContent/WEB-INF/lib
Read more here: https://blogs.oracle.com/alexismp/entry/web_inf_lib_jar_meta
I am not aware how IntelliJ handles Java EE projects.
In Eclipse the EAR and WAR are in separate projects and can be assigned to each other.
I think this error is raised due to my bad understanding of how this web application together with the ejb module works: I deploy the web module and the ejb module separately, and it seems that wildfly can only link to the lib of the web module.
The solution is to deploy only the web application to the server and add the ejb module to the web application.

Tomcat with in eclipse not recognizing the non web.xml app

I have created Spring MVC application without web.xml, completely using the java configuration but when I right click on the project I am not getting an option as Run on server which usually helps me to deploy my war into Tomcat 8.

Spring web app deploys on Gradle's embedded Jetty but not in standalone Jetty

I have built a small web app using Gradle. Things seemed to be going well using the embedded Jetty server, but not so well when I tried to copy the WAR file to a standalone server.
I used the gradle war plugin to assemble the war.
Running gradle jettyRunWar works fine.
Copying the war to the Jetty webapps folder and running Jetty fails with this exception:
java.lang.IllegalStateException: No such servlet servlet_name
But this very same servlet is found and used without issue in the embedded Jetty server.
The same issue happens if I manually copy the exploded war to the webapps directory.
The Spring web and Spring mvc libs are copied and present in the WEB-INF/libs directory, so it isn't an issue of not finding Spring (or is it?)
I'm using Jetty 9.1, and my web.xml file is configured for Servlets v3.
I'm also using Spring 3.2. The web app I'm writing is a RESTful service, using the #Controller annotations to route requests.
This should be as simple as copying the war over, but it seems not to be. At a bit of a loss at what to do here, any thoughts?
Thanks!
Sometimes the answer is staring you in the face...after posting I realized that I had my servlet-mapping before my servlet declaration. While this did not present an issue for the Gradle Jetty (not sure why), it made Jetty unhappy. Not sure why I changed the order to begin with...
In short, Jetty seemed to not find the servlet because it had not been declared yet.

Looking up EJBs on JBoss 7

I developed very simple Hello World EJB (3.x) which I deployed on JBoss 7.1.
I can successfully call this EJB from within a standalone application.
When trying to call it from a servlet I find the EJB.
I have package the EJB in a JAR and the servlet in a WAR.
It seems that this is the reason for the servlet not able to access the EJB.
Might that be true?
Once I package both, the EJB JAR and the servlet WAR into the same EAR it works.
As that the supposed behavior or can I make this work even without using EARs?
Maybe someone can shed some light into this.
I am pretty sure that I did not need to do these things on earlier JBoss version.
According to Java EE spec, deployed applications should be isolated, unless they are in the same EAR archive. So the behaviour you see is correct.
This is different from JBoss 4 or JBoss 5 default configuration, which did not have archives isolation (that was essentially a bad thing, but often quite convinient...).
EAR packaging is sort of annoying, but can be done automatically by IDE or Maven.
In addition, in case of Java EE v. 6, you might pack EJB components with local interface into WAR archive, which simplifies deployment.

Resources