I want to use logger in my java web application.
I'm using JBossAS 6.0.0.final, cdi (weld), jsf ... etc. Seam solder proposes to use an abstract logger is not tying to a concrete implementation (slf4j, log4j, etc) using jboss-logging api.
In order to get this logger in your code will need to write
# Inject
org.jboss.logging.Logger log
seam-solder.jar has the producer for this logger.
package org.jboss.seam.solder.log;
...
class LoggerProducers
{
# Produces
org.jboss.logging.Logger produceLog (InjectionPoint injectionPoint) {}
}
When I deploying my application, I get an error
15:51:18,300 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=vfs:///C:/Java/jboss-6.0.0.Final/server/default/deploy/kamis-web-client.5.0.0-SNAPSHOT.ear_WeldBootstrapBean state=Create: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [#Default] at injection point [[field] #Inject private ru.kamis.suite.webclient.web.breadcrumbs.BreadcrumbsManager.log]
This is due to the seam-solder.jar has not META-INF/beans.xml file, and it is necessary for cdi container.
If to add beans.xml file in seam-solder.jar manually, then the application works WELL.
How to do without hacks?
To build my application I use maven, so my solution is not comfortable and NOT fine.
PS: Former weld-extensions project contained META-INF/beans.xml file in jar.
with seam-solder-3.0.0.Beta1 there should be no need to modify the jar
Related
I am trying to deploy an OSGI bundle in felix jetty. BootStrap is my class which extends HttpServlet.
I am getting the below Exception at deployment stage :
ins.server.servlet.HttpServlet30Dispatcher is not assignable from javax.servlet.http.HttpServlet
2018-07-11T07:46:55,044 WARN sure-rest-neo [] web-reactor - unavailable
javax.servlet.UnavailableException: Servlet class com.nokia.mdf.sure.neo.utils.Bootstrap is not a javax.servlet.Servlet
at org.eclipse.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:519) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:379) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) ~[jetty-util-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:874) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778) ~[jetty-server-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262) ~[jetty-servlet-9.3.10.v20160621.jar:9.3.10.v20160621]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520) ~[jetty-webapp-9.3.10.v20160621.jar:9.3.10.v20160621]
I have embedded all dependencies including the transitive ones. How to resolve this, which I assume is due to jar conflict ?
The problem is exactly with embedding dependencies. When you embed the javax.servlet package then your bundle will use the embedded class while jetty will use the class available from an exported package. So while these classes are named the same there are different instances in the classloaders which leads to exactly this kind of error.
To generally solve this you make sure that ideally only one bundle exports each package and all bundles that need it import the package. So the easiest solution is to not embed dependencies.
If that does not work for you then you can try to import and export the javax.servlet package in your bundle. This allows the OSGi environment to decide which package it will actually wire and avoid having the same class names with different instances in bundles.
I have a an ear file to be deployed on weblogic 12c.
I have following project structure :
1) prop-application which is an .ear file
2) prop-service which is a .jar file
3) prop-framework which is a .jar file
All are maven project.
- prop-service contains prop-framework as one of its maven dependency.
- prop-application which is an ear contains prop-service
so we can say : prop-application.ear = prop-service.jar + prop-framework.jar
prop-service.jar = more java codes + prop-framework.jar
Now there is a class in prop-framework as :
#Stateless(name = "ServiceCallerBean")
public class ServiceCallerBean implements ServiceCaller
#Local
public interface ServiceCaller
Requirement :
Now i want to lookup(call) this EJB from a from a class in *prop-service* i.e a local look. The point here is to note that prop-service.jar contains prop-framework.jar
Following is the jndi names generated by weblogic 12c server :
java:global/ProposalEngine/prop-service-0.0.1-SNAPSHOT/ServiceCallerBean.>
java:module/ServiceCallerBean.>
java:app/prop-service-0.0.1-SNAPSHOT/ServiceCallerBean.>
java:global/ProposalEngine/prop-service-0.0.1-SNAPSHOT/ServiceCallerBean!com.db.serviceframework.ejb.ServiceCaller.>
java:app/prop-service-0.0.1-SNAPSHOT/ServiceCallerBean!com.db.serviceframework.ejb.ServiceCaller.>
java:module/ServiceCallerBean!com.db.serviceframework.ejb.ServiceCaller.>
I can't use those jndi names which contains jar version(eg 0.0.1-SNAPSHOT) because jar version will keep on changing. But if i use any of the jndi names like java:module/ServiceCallerBean , then there lookup fails with javax.naming.NameNotFoundException: While trying to lookup error
I have tried even :
#EJB
ServiceCaller serviceCaller
in the required class in prop-service but serviceCaller comes out to be null here. Searched on this issue and found that we can use #EJB in only container managed classes, not in simple java class.
I have tried everything but noting seems to be working. So plz help me to solve this issue.
This blog contains a nice explanation of where the JNDI addresses come from. The prop-service-0.0.1-SNAPSHOT entry is taken from the name of the JAR or WAR, so you can use the Maven JAR plugin to change the final name of your JAR you should be able to remove the version number, like this.
I have an OSGi Bundle and a servlet. Now I want to access the bundle from the servlet. For that purpose I use the following in the servlet:
#Resource
BundleContext context
...
ServiceReference ref = context.getServiceReference("package.MyOSGiServiceInterface");
MyOSGiServiceInterface service = context.getService(ref);
The Problem is that my servlet doesn't know MyOSGiServiceInterface 'cause that is defined in the OSGiBundle. In Eclipse I added a reference to the bundle Project in my Build Path. But at runtime it obviously can't find it.
To solve that Problem I played around with
(in bundle manifest)
Export-Package: package-of-osgi-service-interface
(in servlet manifest)
Import-Package: package-of-osgi-service-Interface
Dependencies: ...,deployment.MyBundle
But I couldn't solve it.
Whats the missing step? How can I tell JBoss to add the package containing MyOSGiServiceInterface in OSGiBundle to the class path?
Thanks for answers!
(JBoss AS 7.1.1)
--> error message <--
Eventually I solved it. I had to put the right combination of settings together to reach my goal:
Deploy the bundle per: File - Export - "Deployable plug-ins and fragments" into folder: "jboss/standalone/deployments"
Bundle-Manifest:
Bundle-SymbolicName: TestBundle
Bundle-Version: 1.0.0
Export-Package: "package-which-includes-my-service"
Servlet-Manifest:
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.TestBundle:1.0.0
Import-Package: "package-which-includes-my-service"
Currently, to set up configuration for Pax Exam, I find that I need to include all dependencies. E.g. something like
#Configuration
public Option[] сonfig() {
MavenArtifactProvisionOption commonsDbcp = mavenBundle("commons-dbcp",
"commons-dbcp");
MavenArtifactProvisionOption commonsPool = mavenBundle("commons-pool",
"commons-pool");
...
return options(
felix(),
provision(commonsDbcp, commonsPool));
}
But since commons-dbcp depends on commons-pool, this feels like duplicate information. Is it possible for Pax Exam to figure out that commons-dbcp is needed without adding it explicitly?
Not really...
Not every Maven dependency of an OSGi bundle is an OSGi bundle.
A dependency may be an interface-only, and at run-time, you want to provision an implementation bundle instead.
Listing all bundles explicitly is the only safe way of provisioning your framework. At least, you can use the versionAsInPom() option method to avoid duplicating the artifact versions.
We have a Spring 3 MVC application and JUnit test cases for spring controllers. The Junit version is 4.8.1 which supports ContextConfiguration annotation.
Here is how I am adding context configuration in my test stub
#ContextConfiguration(locations = "file:WebContent/WEB-INF/myappconfig.xml")
I am able to run the junits locally, but when I am trying to run this with my ant build script, it throws an error java.lang.IllegalStateException: Failed to load ApplicationContext
I tried to set classpath element to the WebContent, then upto web-inf, nothing works out.
i'm using
#ContextConfiguration({ "classpath*:application-test.xml" })
and my application-test.xml resides under main/resources