setting the ContextPath in Jetty running under ServiceMix (OSGI) - jetty

Here is my brief background of environment.
I am trying to convert a myapp WAR to an OSGi compliant by making the MANIFEST.MF as shown below, and wanted to deploy this war in ServiceMix an OSGi based container.
MANIFEST.MF
Manifest-Version: 2.0
Bundle-SymbolicName: myapp
Bundle-Version: 2.1.dev
Bundle-Name: Jetty.myapp
Bundle-Vendor: ABC
Created-By: 1.6.0_25-b06 (Sun Microsystems Inc.)
Bundle-ClassPath: .,WEB-INF/lib, WEB-INF/classes, xforms/xsltforms
Web-ContextPath: myapp
Webapp-Context: myapp
Import-Package: javax.servlet
Built-By: root
Project-Name: ABC_PRJ
Project-Version: 2.1.dev
Project-Build: ${DSTAMP}
SVN-Revision: ${svn.revision}
The ContextPath is getting set to null, where should I set the contextPath and how? You may observe the 'null' string in the FileNotFound Exception.
log:
java.io.FileNotFoundException: null/WEB-INF/myForms-config.xml (No such file or
directory)
My web.xml in myapp is :
<contextPath>/</contextPath>
<context-param>
<param-name>myForms.configfile</param-name>
<param-value>WEB-INF/myForms-config.xml</param-value>
</context-param>
Is it the problem with myapp or jetty or serviceMix? Any Clue?

You need to set the web-contextpath via the Manifest and not via the web.xml
for more information take a look at Pax-Web

Related

Jetty deployment: Unable to compile class for JSP

I tried to deploy to and run Jetty from an Ant-script, but get the following error:
[jetty.run] 2016-06-25 09:16:54.333: Starting web application null
[jetty.run] [main] WARN org.eclipse.jetty.annotations.ServletContainerInitializersStarter -
[jetty.run] javax.servlet.ServletException: Not running on Jetty, WebSocket+CDI support unavailable
[jetty.run] at org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer.onStartup(WebSocketCdiInitializer.java:49)
[jetty.run] at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140)
[jetty.run] at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:63)
[jetty.run] at
...
It work without deployment, but with the war-file this happens. What is corrupt?
UPDATE:
Added
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
to web.xml andweld jars to lib. Now I get this:
java.lang.reflect.InvocationTargetException
[jetty.run] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[jetty.run] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[jetty.run] at ...
[jetty.run] Caused by: java.lang.IllegalStateException: Nothing to bind for name BeanManager
UPDATE 2:
Ok, I didn't need the extra things in my web.xml. Instead I had forgot to add
<typedef name="webApp" classname="org.eclipse.jetty.ant.AntWebAppContext" classpathref="classpath" loaderref="jetty.loader"/>
to build.xml. I can now deploy and run jetty, but can't process JSP files:
[jetty.run] [qtp1387380406-14] WARN org.eclipse.jetty.servlet.ServletHandler -
[jetty.run] org.apache.jasper.JasperException: Unable to compile class for JSP
[jetty.run] at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600) ...
Why is this so?
Remove the various jetty cdi jar files from your project.
Those are designed specifically for jetty-distribution use, and are inappropriate for embedded-jetty.
Use the weld jars directly in your war file, along with the various recommended configurations that the weld project documentation tell you about.

How to deploy static content on root context with jetty runner (standalone jar)

Update:
I've noticed that if I'don't deploy the WAR file i can do it as Joakim Erdfelt says, i'll investigate what changes I've done to the war that causes the failure at root context.
I know how to deploy static content to any context :
sudo java -cp jetty-runner-9.2.13.v20150730.jar org.eclipse.jetty.runner.Runner --port 80 MYAPP.war --path /context1 site/MyStaticWebSite
//will deploy mysite in
//127.0.0.1/context1/index.html
but I want to deploy it in the root
127.0.0.1/index.html
And there's no reference in the docs nor in google.
https://webtide.com/downloads/
If I do :
sudo java -cp jetty-runner-9.2.13.v20150730.jar org.eclipse.jetty.runner.Runner --port 80 MYAPP.war --path / site/MyStaticWebSite
I get :
2015-11-11 21:05:27.498:INFO::main: Logging initialized #121ms
2015-11-11 21:05:27.513:INFO:oejr.Runner:main: Runner
2015-11-11 21:05:27.618:INFO:oejs.Server:main: jetty-9.2.13.v20150730
Nov 11, 2015 9:05:34 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
2015-11-11 21:05:35.323:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#33833882{/,file:/tmp/jetty-0.0.0.0-80-MYAPP.war-_-any-4618238315169821839.dir/webapp/,AVAILABLE}{file:/home/ubuntu/MYAPP.war}
2015-11-11 21:05:35.744:WARN:oeja.AnnotationConfiguration:main: ServletContainerInitializers: detected. Class hierarchy: empty
2015-11-11 21:05:35.871:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext#200a570f{/,file:site/MyStaticWebSite/,AVAILABLE}{/root/MyStaticWebSite/}
2015-11-11 21:05:35.872:WARN:oejsh.RequestLogHandler:main: !RequestLog
2015-11-11 21:05:35.890:INFO:oejs.ServerConnector:main: Started ServerConnector#2504eefd{HTTP/1.1}{0.0.0.0:80}
2015-11-11 21:05:35.891:INFO:oejs.Server:main: Started #8517ms
And root webpage shows the following:
First, upgrade!
9.1.0.M0 is an unstable/beta milestone build.
Use something a bit more recent and stable (how about 9.2.13.v20150730 of jetty-runner?)
If you want it deployed on the root context, use --path / (not --path /context1)
Update:
Ah, you have 2 webapps, and Jersey in the mix, didn't realize.
WebApp 1: context:/ path:MYAPP.war
WebApp 2: context:/ path:site/MyStaticWebSite
No you can't have both on the same context path, that's not supported by the servlet spec.
This is because every webapp MUST terminate once it is entered.
Scenario:
So since the context path is /, both webapps will match
First one entered will service the request
If a servlet has a matching url-pattern, that servlet is called
If no servlet matches, then the DefaultServlet is used.
DefaultServlet will look for a static resource matching the url-pattern/pathInfo
If no static resource matches, then DefaultServlet produces an error.
That webapp must produce a response. There is no opportunity to skip the webapp and move into the next one.
However, this behavior is further complicated by Jersey, its default configuration takes over all static resource serving itself, never allowing Jetty to even have the opportunity to serve those static resources.
What you'll need to do.
your MYAPP.war must have the static resources.
if you have "external" static resources, those must be served by something in MYAPP.war - either a formal servlet that does it, or something in Jersey. Suggestion is to set that external behavior up at a different url-pattern like /external/* or /static/*, not /*.
I've finally found how I could do it,
Instead of:
sudo java -cp jetty-runner-9.2.13.v20150730.jar org.eclipse.jetty.runner.Runner --port 80 MYAPP.war --path / site/MyStaticWebSite
Do:
sudo java -cp jetty-runner-9.2.13.v20150730.jar org.eclipse.jetty.runner.Runner --port 80 --path /MYAPP MYAPP.war --path / site/MyStaticWebSite
MYAPP was deploying itself to /MYAPP context as specified in web.xml but didn't allow to deploy any content in the root context, by spec.
Then the problem was that /MYAPP couldn't be reached, but /MYAPP/MYAPP could, that was because the web.xml was saying to deploy the service into /MYAPP so I had to change it
from:
<servlet-mapping>
<servlet-name>MY_SERVLET_NAME</servlet-name>
<url-pattern>/MYAPP/*</url-pattern>
</servlet-mapping>
to:
<servlet-mapping>
<servlet-name>MY_SERVLET_NAME</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Now it works.

error when deploying Java WS in Jboss 6.3.0 EAP

I am migrating an application with Java WS from Jboss 5.1.0 to Jboss 6.3.0 EAP. It works fine with Jboss 5.1.0 but I am getting error while deploying the same in Jboss 6.3.0 EAP.
14:42:10,887 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deploy
ment.unit."my-app.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."dtm-banking.
war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "dtm-banking.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [jboss-a
s-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-ms
c-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.F
inal-redhat-1.jar:1.1.5.Final-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_60]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_60]
Caused by: javax.xml.ws.WebServiceException: java.lang.reflect.UndeclaredThrowableException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:371)
at org.jboss.wsf.stack.cxf.deployment.EndpointImpl.doPublish(EndpointImpl.java:66)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539)
at org.jboss.wsf.stack.cxf.configuration.NonSpringBusHolder.configure(NonSpringBusHolder.java:118)
at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.startDeploymentBus(BusDeploymentAspect.java:137
)
at org.jboss.wsf.stack.cxf.deployment.aspect.BusDeploymentAspect.start(BusDeploymentAspect.java:69)
at org.jboss.as.webservices.deployers.AspectDeploymentProcessor.deploy(AspectDeploymentProcessor.java:74)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [jboss-a
s-server-7.4.0.Final-redhat-19.jar:7.4.0.Final-redhat-19]
... 5 more
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy371.visitLabel(Unknown Source)
at org.apache.cxf.jaxws.WrapperClassGenerator.createWrapperClass(WrapperClassGenerator.java:213)
at org.apache.cxf.jaxws.WrapperClassGenerator.generate(WrapperClassGenerator.java:122)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.generatedWrapperBeanClass(JaxWsServiceFactoryBean.java:6
83)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.getExtraClass(JaxWsServiceFactoryBean.java:653)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBea
n.java:484)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBe
an.java:550)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java
:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
Caused by: java.lang.NoSuchMethodException: org.objectweb.asm.MethodWriter.visitLabel(org.objectweb.asm.Label)
at java.lang.Class.getMethod(Class.java:1665) [rt.jar:1.7.0_60]
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:85)
... 28 more
I understand Jboss 6.3.0 EAP uses CXF implementation for webservice, but I am looking for simple Java WS to use the standard Java EE environment.
tried the following in jboss-deployment-structure.xml
<exclude-subsystems>
<subsystem name="webservices" />
</exclude-subsystems>
this got rid of the exception at deployment time but I get a Classcast exception when invoking the wsdl for the service
http://localhost:8080/myapp/myservice?wsdl
JBWEB000235: Allocate exception for servlet MyWebService: java.lang.ClassCastException: com.example.webservice.endpoint.DataService cannot be cast to javax.servlet.Servlet
any idea?
The problem is bundling asm.jar in your deployment.
Try remove it and add this to your jboss-deployment-structure.xml:
<jboss-deployment-structure>
<deployment>
<dependencies>
...
<module name="asm.asm" />
...
</dependencies>
</deployment>
</jboss-deployment-structure>
See more: https://developer.jboss.org/message/823745
The answer that fixed things for me was:
I had the same problem. Adding jboss-deployment-structure.xml only
work for WAR files. If I depolyed the WAR inside an EAR I got the
error back. So I added
<global-modules>
<module name="asm.asm" slot="main"/>
</global-modules>
to the current jboss configuration, ie standalone-full.xml The it
work fine for me.
So if anyone stumbles upon this question, give it a try.
Rifer this page too.
https://access.redhat.com/solutions/690353
The above Error is thrown when for given class particular method not
found. Hence user is packaging asm jar in their application and class
"org.objectweb.asm.MethodWriter" which contains in a jar does not have
method "public void visitLabel(org.objectweb.asm.Label);" hence
getting "java.lang.NoSuchMethodException".

jetty 9 symlink to exploded war

I've just upped to Jetty 9 from 8 and have an odd issue. My development environment is an exploded war, so I simply drop a symlink (ROOT) into my jetty/webapps directory pointing to my exploded war. This worked just fine for Jetty 8, but seems to fail for Jetty 9.
First, the symlink is now 'root', per the documentation. But when I hit my server '/' it gives me a 404 and this:
Error 404 - Not Found.
No context on this server matched or handled this request.
Contexts known to this server are:
/war ---> o.e.j.w.WebAppContext#613714d3{/war,file:/home/george/git/s/web_app/war/,AVAILABLE}{/home/george/git/s/web_app/war}
meaning that I can find my application served under '/war' instead of just '/'. Wacky.
This is due to a host of changes, mainly pointing at the use of Java 7 and requirements for the more recent Servlet specs.
Easy enough to fix for your situation tho.
Don't use OS symlinks.
Create a file called ${jetty.home}/webapps/mywebapp.xml with the following contents
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/home/george/git/s/web_app/war/</Set>
</Configure>
All done, you are now essentially using a Jetty Deployable XML Descriptor which sets the contextPath to / (aka Servlet Spec Root) and pointing to the war that you want to deploy.

Log level in Jboss as 7 classloaders

How do I change the log level for the classloaders in Jboss as 7?
As a side note;
I have found information on how to do this in Jboss 5 and below but since the classloading and logging has completely changed in Jboss 7 I cant figure out how to do it.
https://community.jboss.org/wiki/EnableClassloaderLogging
Add the following to JAVA_OPTS in your start up script.
-verbose:class
And the following to your Jboss config file (standalone.xml for example).
<profile>
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<logger category="org.jboss.as.deployment">
<level name="DEBUG"/>
</logger>
</subsystem>
</profile>