I am launching an embedded Jetty instance containing a single webapp. The webapp launches on start-up. I'd like to know how to detect if the Webapp's contextInitialized throws an exception.
When the webapp throws an exception, Server.start() doesn't and server.isRunning() returns true. Is there a way for me to listen for webapp exceptions from outside the container?
Answering my own question.
Setting WebAppContext.setThrowUnavailableOnStartupException(true) causes the server to propagate any webapp exceptions to Server.start(). I'm guessing one could also invoke WebAppContext.isFailed() after server start-up to check individual contexts.
I stumbled across this trying to make this work for a non-embedded solution. In case anyone is in a similar boat, the solution for that case is to create WEB-INF/jetty-env.xml with the following contents:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="throwUnavailableOnStartupException">true</Set>
</Configure>
The server will fail startup on an exception as expected.
Related
I have a multi module Maven Spring project and can't get webjars-locator-weblogic to work with it.
The webjars are reachable and the mapping is declared as:
<mvc:resources mapping="/webjars/**" location="classpath:META-INF/resources/webjars/" />
However, if i try to use the version agnostic link, the response is always 404. Have already tried with both webjar-locator and webjar-locator-weblogic dependencies with no success.
Have been using this exact same configuration with other servers and never had any issues.
What am i missing?
I integrated SBT in my existing application and able to run the application with sbt enabled. I deployed in my test server and it works fine but when I moved to the production, Since the context path of the application is different it breaks.
Ex: in test server my application url is
https://somedomian/SampleSbt
In production
htt....somedomain/serve/meth/SampleSbt
I'm getting error in firebug as
htt.....domain/sbt/js/sdk/sbt/ErrorTransport.js -> Forbidden
I tried changing the context path /my code path /managed-beans.xml and many ways but still it gives the same error
want to change the path from http.....somedomain/sbt/js/sdk/sbt/Errortransport.js to http.....somedomain/serv/meth/sbt/js/sdk/sbt/Errortransport.js
Can you try to add the servlet init parameter called "toolkitUrl" to the library servlet, defined in your application web.xml with value "%local_server%/somedomain/serv/meth/sbt".
So the modified library servlet declaration should look like -
<servlet>
<description>This servlet initializes the specified JavaScript library for use by the Social Business Toolkit.</description>
<display-name>Social Business Toolkit Library Servlet</display-name>
<servlet-name>LibraryServlet</servlet-name>
<servlet-class>com.ibm.sbt.jslibrary.servlet.LibraryServlet</servlet-class>
<init-param>
<param-name>toolkitUrl</param-name>
<param-value>%local_server%/somedomain/serv/meth/sbt</param-value>
</init-param>
</servlet>
After the discussion yesterday with Projjwal Saha, the issue should be resolved.
Can you update if it is, or let us know in case you still see the issue.
EDIT: I think I should clarify my intent...
I'm trying to simplify the development iteration cycle of write-code >> build WAR >> deploy >> refresh >> repeat. I'd like to be relatively independent of IDE (i.e., I don't want Eclipse or IntelliJ plug-ins doing the work). I want to be able to edit code/static files and build as needed into my WAR source directory, and just have run/debug setup as a command line call to a centralized Jetty installation.
Later I'd like to be able to perform the actual deployment using generally the same setup but with a packaged up WAR. I don't want to have my app code specific to my IDE or Jetty.
So perhaps a better way to ask this question is What have you found is the cleanest way to use Jetty as your dev/debug app server?
Say I want to have a minimal Jetty 7 installation. I want as minimal of XML configuration as possible, I just need the raw Servlet API, no JSP, no filtering, etc. I just want to be able to have some custom servlets and have static files served up if they exist. This will be the only WAR and it will sit as the root for a given port.
Ideally, for ease of deployment I'd like to have the Jetty directory just be the standard download, and my WAR / XML config be separate from these standard Jetty files. In my invocation of Jetty I'd like to pass in this minimal XML and go.
I'm finding that the documentation is all over the place and much of it is for Jetty 6 or specific to various other packages (Spring, etc.). I figure if I have this minimal configuration down then adding additional abstractions on top will be a lot cleaner. Also it will allow me to more cleanly deal with embedded-Jetty scenarios.
This SO question is an example scenario where this XML would be useful Jetty Run War Using only command line
What would be the minimal XML needed for specifying this one WAR location and the hosts/port to serve it?
Thanks in advance for any snippets or links.
Jetty has migrated to Eclipse. There is very subtle info on this. This also led in change in package name, which is another level of nuance. They did publish a util to convert Jetty6 setting to Jetty 7 setting, but again -- not very popular. I am dissapointed from Eclipse Jetty forum. Here is where you should look for documentation on Jetty 7 onwards http://wiki.eclipse.org/Jetty/Starting
I think this is the minimal jetty.xml taken from http://wiki.eclipse.org/Jetty/Reference/jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">\
<Configure id="Server" class="org.eclipse.jetty.server.Server">
</Configure>
But, I would rather like to start from a copy of $JETTY_HOME/etc/jetty.xml and would modify from there.
If you are Okay with $JETTY_HOME/webapps directory, you can set up the port by modifying this part
<Configure id="Server" class="org.eclipse.jetty.server.Server">
...
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="7777"/></Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
....
</Configure>
Else, I will modify context.xml the way explained here (for Jetty 7) How to serve webbapp A from portA and webapp B from portB
Also refer these pages:
http://wiki.eclipse.org/Jetty/Reference/jetty.xml
http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax
http://communitymapbuilder.org/display/JETTY/JNDI
....
Edit#1: sorry for wrong URL for webapp per connector. I have updated the link to How to serve webbapp A from portA and webapp B from portB to point to the doc that is meant for Jetty 7.
Update on 'how you deal with Jetty on various environments?'
Dev
We use Maven, so embeded Jetty works for us. We just run mvn clean install run:jetty and the port is configured in Maven's config file, namely pom.xml. This is not IDE dependent plus Jetty can easily be embedded using ANT, but I never tried.
Test
We have stand-alone Jetty running. I've configured port and tuned parameters, removed default apps (e.g. root.war etc) and created a context.xml with app specific ports and deployment directory. (Unfortunately, I have asked this question on Eclipse Jetty's mailing list and no one bothered to answer). This is one time setting.
For test builds/deployments, we have a build script that builds the WAR as per test env specs and then uploads it to test environment. After, that we invoke a shell script that (1)stops Jetty, (2) copies war file to myApp's webapp direactory and (3) restarts Jetty.
However, easier way to do this is by using Maven's Cargo plugin. The bad luck was that I was using Jetty 7.1.6 which was incompatible with Cargo. Later they fixed it, but I had got my job done by custom script.
Prod
Prod has almost same procedure as test, except. The tunings are done for higher security and load-balancing. But from deployment POV, there is nothing different from Test case to Prod.
Notice that I have not bothered about what XML files are and how many must be there. I have just used the ones that are my concerns -- jetty.xml and context.xml. Plus, I found it's much cleaner to use jetty.conf and jetty.sh for passing JVM params, custom XMLs and for starting and stopping.
Hope this helps.
On hot deployment:
Now, if you use Maven and use embedded Jetty. It just knows when the code is changed -- like "gunshot sniffer". In dev envt, you run Jetty, make changes, refresh page, and see your changes -- hot deployment. Find more here http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin look for scanIntervalSeconds
This doesn't fully answer your question, but in case it helps, here's some pretty minimal code using embedded Jetty 7 to fire up a server with one root servlet:
HandlerCollection handlers = new HandlerCollection();
ServletContextHandler root = new ServletContextHandler(handlers, "/", ServletContextHandler.NO_SESSIONS|ServletContextHandler.NO_SECURITY);
root.addServlet(new ServletHolder(new MyServlet()), "/*");
Server server = new Server(8080);
server.setHandler(handlers);
server.start();
See of course http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty.
If you are building with maven (which is IDE independent) then you should debug with the maven jetty plugin. Basically you run the app as "mvn jetty:run" on the commandline it all just works without having to do any redeployment. Most good IDEs how have maven support built in and lets you run/debug the app as a maven; meaning that maven is run which starts the jetty plugin which starts the app and you can debug it. Since everything is running out of the IDE source and bin folders you don't even need a jetty server install.
Here is a demo project which runs that way https://github.com/simbo1905/ZkToDo2/blob/master/commandline.build.and.run.txt and here is how to run it under eclipse https://github.com/simbo1905/ZkToDo2/blob/master/eclipse.indigo.build.and.debug.txt but any IDE which understands maven should work. Take a look at the pom.xml where it sets up the maven jetty plugin.
I would use Gradle and scan the build output folder every few seconds for changes in the build.
In a build.gradle file:
apply plugin: 'jetty'
...
jettyRun.doFirst {
// set system properties, etc here for bootstrapping
}
jettyRun {
httpPort = 8989
reload = 'automatic'
scanIntervalSeconds = 3
daemon = false
}
That's it. You can choose to have the IDE auto-build for you, and point at that directory. But you can also choose not to. This solution is not tied at all to an IDE.
I thought I'd update with what I now do. I've written a tiny command line app / Maven archetype which works like how I thought this all should have in the first place. The bootstrap app lets you launch your servlet container of choice (Jetty, Tomcat, GlassFish) by just passing it the path to the WAR and your port.
Using Maven, you can create and package your own instance of this simple app:
mvn archetype:generate \
-DarchetypeGroupId=org.duelengine \
-DarchetypeArtifactId=war-bootstrap-archetype \
-DarchetypeVersion=0.2.1
Then you launch it like this:
java -jar bootstrap.jar -war myapp.war -p 8080 --jetty
Here's the source for the utility and the archetype: https://bitbucket.org/mckamey/war-bootstrap
I am trying to upgrade my application from Weblogic 8.1 SP 6 to Weblogic 10.3. For this, I have installed Weblogic 10.3 and created a domain. WLS 10.3 started successfully from my domain.
I recomplied the code in Java 1.6 and deployed successfully with out any code changes.
I have deployed the application and trying to launch the application welcome (login) page.
Then I am seeing the below error :
Predefined Constants Object: com.abc.xyz272.businessclasses.PredefinedConstants#3d80183
DataSourceName='null'
sessionTimeOutLimit='36000'
00:39:31==>Servlet: getRemoteUser=null
00:39:31==>Servlet: getHeader=null
00:39:31==>count=0
<Oct 29, 2010 12:39:31 AM MDT> <Error> <HTTP> <BEA-101020> <[weblogic.servlet.internal.WebAppServletContext#2e28f75 - appName: 'mbqccrpt', name: 'xyzControllerServlet', context-path: '/xyzControllerServlet', spec-version: 'null'] Servlet failed with Exception
java.lang.NullPointerException
at com.abc.xyz272.servlets.xyzControllerServlet.processRequest(Unknown Source)
at com.abc.xyz272.servlets.xyzControllerServlet.doPost(Unknown Source)
at com.abc.xyz272.servlets.xyzControllerServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
Truncated. see log file for complete stacktrace
I have one more question. The application running on Weblogic 8.1 is using apache server as well for launching the Static pages. For upgrading the application in weblogic 10.3 do we require the apache server?
I can answer the 2nd part of your question.
The main purpose usually used for an Apache server fronting the Weblogic is to offload static contents such as images,HTMLs, JS, CSS files to the Apache web server. Only dynamic requests are passed on to the Weblogic, thus reducing traffic especially if across a firewall.
This is an architectural decision which does not depend on the version of Weblogic. Rather, this depends on certain concerns such as Clustering of the App servers (using Apache as a load balancer), Volume of static data since Apache serves static data quite fast - so why push that load onto Weblogic.
And regarding your NullPointerException, it seems to be because your datasource is not defined properly (it shows as null) but you are calling some operations on it
Few Weeks Back, I was also here on this page, filtering out the internet for a suitable solution for this very same problem spec-version: 'null'] Servlet failed with Exception, until the time when everything else didn't work except the solution which I found myself after a lot of effort.
I encountered this issue while migrating one application from Oracle's 10g App Server to Weblogic 10.3.5.
As per the legendary practice, while doing the migration, we had placed one weblogic.xml file in the /WEB-INF/ folder and that was the actual problem. I just replaced that incorrect weblogic.xml file with my own version of weblogic.xml file and things worked fine.
Even though the faulty weblogic.xml file had many other elements inside the root element for the reasons best known to the person who had initially placed it, in my version of this DD file I had only the root element. And so finally the problem was resolved. So it's worth to take this into consideration.
getRemoteUser() returning null:
As getRemoteUser() method is deprecated in Weblogic 10.3, it will return null when the application is accessed by users. To avoid this problem replace getRemoteUser() with thegetHeader(“proxy-remote-user”) method, to return the remote-user as a string.
String usr= request.getHeader("proxy-remote-user");
Issue with Servlet Path Mapping:
We have the following Servlet mapping in web.xml which was working
fine in Weblogic 8.1
<servlet-mapping> in web.xml
<servlet>
<servlet-name>ServletName</servlet-name>
<servlet-class>com.abc.servlets.servletname</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> ServletName </servlet-name>
<url-pattern>/*.*</url-pattern>
</servlet-mapping>
But after migrating to 10.3, the same Servlet mapping is not working as the request is going into the infinite loop while launching the application home page. Since the web application is using Servlet as a controller where all the requests hits the controller and then are forwarded to respective JSP’s. To avoid this problem we replaced url-pattern “/*” with “/” in the servlet-mapping as below.
<servlet-mapping>
<servlet-name> ServletName </servlet-name>
<url-pattern>/ServletName </url-pattern>
</servlet-mapping>
I am using Flex builder 3, BlazeDS, and Java with Spring and Hibernate framework. I using the remote object to load a string from spring's configuration files. But in testing, I found this fault event like this:
RPC Fault
faultString="java.lang.NullPointerException"
faultCode="Server.Processing"
faultDetail="null"
I have checked the configuration in remote-config.xml and services-config.xml. But it looks good. Some people have talked about this problem around the Internet and I think you can help me and them.
I am using these environment:
Flex Builder 3
BlazeDS 3.2.0
JBoss server
Full stacktrace:
[RPC Fault faultString="java.lang.NullPointerException" faultCode="Server.Processing" faultDetail="null"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at NetConnectionMessageResponder/statusHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:569]
at mx.messaging::MessageResponder/status()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:222]
The java.lang.NullPointerException indicates an error being thrown on the server. To debug this, active debug logging on BlazeDS in the services-config.xml file. You should see detailed debug information in the server console.
When using the BlazeDS/Spring integration take care that you will need to use a custom exception translator in order to obtain meaningful exceptions. Please read this document http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/ch02s08.html
In your case the error is not related to some configuration problems, it seems that is thrown inside your java method. Use a debugger in order to diagnose properly.