JBoss stateless session bean as web service url - java

On JBoss 5.1.0, when I have an EJB3 stateless session bean exposed as a web service using the #WebService annotation in a jar it gets deployed successfully to the following url:
http://localhost:8080/SessionTest/MyBean
However, if I package the ejb jar in an EAR file it get's deployed to the following url:
http://localhost:8080/TestEAR-SessionTest/MyBean
i.e. Ear name - jar name as the context instead of just jar name.
Is there a way to specify the context that should be used (i.e. SessionTest) so that it is consistent regardless of whether it is deployed as a standalone ebj jar or in an EAR?

You can use #WebContext( contextRoot = "/webservices" ) to set the context root to a fixed location.
There are more options, that are described in the FAQ document.

Related

Using SpringExtension with Tomcat and Hibernate web app

We are trying to use spring-test's SpringExtension to write integration tests for our Spring and Hibernate-based Tomcat web application. Our sessionFactory bean configuration has the property configured mappingJarLocations with a sample value as /WEB-INF/lib/company-common*.jar which contains hibernate mapping files. In both actual deployment and Eclipse dev deployment, this works fine as the docBasePath (in Servlet environment) is appended to this pattern and the files are getting resolved. But this is not the case while running JUnit test cases either in a local or a CI environment.
We tried our best to use the provided support by having few overridden implementations of WebTestContextBootstraper, GenricXmlWebContextLoader, XmlWebApplicationContext, and WebDelegatingSmartContextLoader but had to finally give up as we cannot override the final method org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(MergedContextConfiguration) to provide the custom implementation of XmlWebApplicationContext. Our current approach is to manually create the application context and use it in the tests.
Here is the project structure:
Project_WebApp
|--src/**
|--WebContent/**
|--pom.xml
When the app is packaged as Project_WebApp.war, the dependencies are inside WEB-INF/lib from the root of extracted war. When deployed as a webapp in Tomcat using Eclipse, the dependencies are copied to <Eclipse_Workspace_Dir>/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/Project_WebApp/WEB-INF/lib. In both cases, the dependencies are available at <Resource_Base_Path>/WEB-INF/lib and Resource_Base_Path has no relation to Project_WebApp base directory.
Questions:
Did any one use SpringExtension in a scenario similar to above? If so can you suggest any alternative approaches?
Instead of /WEB-INF/lib/company-common*.jar, we tried a classpath-based pattern but didn't work as the obtained class path resources don't match the pattern. Is there anything else to try here?

Multiple applications sharing common EJB JAR in TomEE

I have an EJB jar DetailsLookup.jar which needs to be shared by two consumer applications - VehicleMake.war and VehicleModel.war
I have placed the EJB jar file under <catalina_base>/lib and both the war file under <catalina_base>/webapps
When I deploy only one of the WAR files, the deployment is successful, but with 2 WAR files I get the error as below. It seems, TomEE is trying to deploy the EJB for every consumer application instead of deploying it only once
Caused by: org.apache.openejb.DuplicateDeploymentIdException: Application cannot be deployed as it contains deployment-ids which are in use: app: D:\apache-tomcat\instance1\webapps\VehicleModel
DetailsLookup
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:790)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:756)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1308)
... 32 more
I have also noticed that when I deploy only VehicleMake.war, the JNDI name for my EJB has the application context path also appended (which says that the EJB is deployed per project and not common)
Expected JNDI name:
global/DetailsLookup!com.my.company.details.service.DetailsLookup
Actual JNDI name:
global/VehicleMake/DetailsLookup!com.my.company.details.service.DetailsLookup
Can anyone help me to identify what the issue is with deploying EJB and if I need to change any configurations to deploy it as a common EJB instead of application specific?
In conf/system.properties, you can change the name of deployed artifacts to avoid collisions.
Try adding this line:
openejb.deploymentId.format = {appId}/{ejbJarId}/{ejbName}

stateless ejb in WAR > package to EAR > local ejb call

I have an ear which contains 2 war files and each war contains stateless ejb and jersey rest classes. The interfaces locate in commons.jar file. The EAR structure looks like this:
EAR
-- /lib/commons.jar
-- rest-1.war
-- stateless-ejb-1.java
-- jersey-rest-1.java
-- rest-2.war
-- stateless-ejb-2.java
-- jersey-rest-2.java
I am trying to use stateless-ejb-1 from stateless-ejb-2 with #Inject annotation but I get a CDI deployment failure:WELD-001408: Unsatisfied dependencies error during deployment time. When I use #EJB in stateless-ejb-2 then the ear is deployed but I get a remote lookup error while calling jersey-rest-2.
This are my method call chains:
jersey-rest-1 > stateless-ejb-1: works fine
jersey-rest-2 > stateless-ejb-2 > stateless-ejb-1: I get an ejb-1 lookup error
I do not want to use remote ejb call because everything is packaged in the same ear (I would like to use #Inject instead of #EJB) but it does not work.
I guess that if I pack stateless-ejb-1.java to a jar and put it under EJB/lib than it will work. But I do not want to create a new module in my project just to pack this one file to separated jar file.
What is the solution?
You need to move stateless-ejb-1 into an ejb-jar module in the EAR.
Classes in different WAR files are never visible to each other, even when built into an EAR file.

Error in Bluemix Liberty when injecting a simple CDI managed bean into a servlet

When injecting a simple CDI managed bean into a servlet (starting from the generated code sample "SimpleServlet"), when accessing the servlet, Bluemix Liberty logs this error :
"SimpleServlet cannot be injected as class
wasdev.sample.servlet.SimpleServlet is not in a bean archive."
This is so even when a beans.xml file with discovery "all" is used.The target looks like this
Reason for Error :
The error is due to not having a beans.xml in the built application war i.e. JavaHelloWorldApp.war
Currently, for performance reasons, the beans.xml file is always required in order to use CDI on Bluemix.
Solution :
Copied the bean.xml inside the /src/main/webapp/WEB-INF/beans.xml then built the code.
This made sure that the bean.xml is packaged into the war file i.e. JavaHelloWorldApp.war and the error is resolved.
To verify bean.xml is deployed correctly to Bluemix, select the java application on Bluemix console, click and open the java application dashboard. Select Runtime, select Files tab, browse and verify that the bean.xml is deployed correctly inside WEB-INF as shown in the snapshot below.

Migrating Application from WAS 6.1 to WAS 8.5

I am migrating applications from WAS 6.1 to WAS 8.5. Existing application works fine in WAS 6.1 but in WAS 8.5 while connecting to a bpm wsdl url, I am getting the following exception. The jar is present in WEB-INF/lib
java.lang.NoClassDefFoundError: org.apache.woden.resolver.URIResolver
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
at org.apache.axis2.deployment.ModuleDeployer.deploy(ModuleDeployer.java:65)
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136)
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:815)
at org.apache.axis2.deployment.RepositoryListener.loadClassPathModules(RepositoryListener.java:222)
at org.apache.axis2.deployment.RepositoryListener.init2(RepositoryListener.java:71)
at org.apache.axis2.deployment.RepositoryListener.<init>(RepositoryListener.java:64)
at org.apache.axis2.deployment.DeploymentEngine.loadFromClassPath(DeploymentEngine.java:177)
at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:135)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:151)
at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:144)
Switch the class loader to local first, parent last.
In application configuration go to:
Class loading and update detection
Change class loader order to local first
Save changes
Restart application server
For using third party Web service engine you need to set class loader to parent last and disable annotation scanning:
Set the DisableIBMJAXWSEngine property in the META-INF/MANIFEST.MF of
a WAR file or EJB module to true
See documentation for more details:
Using a third-party JAX-WS web services engine

Categories

Resources