Using RequestContextListener in jetty 9 - spring

I'm using jetty container for application which needs certain attributes to be bound to request. I'm using RequestContextListener in web.xml:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
User class:
#Scope("request")
class User {
// some code
}
When deploying war on jetty, it fails with exception : java.lang.IllegalStateException: No thread-bound request found. And on issuing any calls to the server, it results in error 503. On the other hand, it works fine on tomcat. Tomcat gives errors on deployment but subsequent calls go through fine. Looks like it is an issue with jetty. I'm using stable-9 version of jetty (http://download.eclipse.org/jetty/ : jetty-distribution-9.2.10.v20150310) Any suggestions on how do resolve this with jetty?

Related

How to edit web.xml context param in Websphere console

I have made a web application to be deployed in the Websphere server but i came up with a problem.
I have 20 servlets that use a common parameter so i have this declared on web.xml:
<context-param>
<param-name>filePath</param-name>
<param-value>C:\logs.txt</param-value>
</context-param>
I want this parameter to be easily edited in the Websphere console but doesn't work. I know this works on Tomcat but is there anything equivalent on websphere?
Thanks
You should edit web.xml only on the server, there is know interface for it in the Console, as I remember.
You can find this file here:{WAS_ROOT}/profiles/profilename/config/cells/cellname/applications/enterpriseappname/deployments/deployedname/webmodulename
Link to the documentation:
http://www-01.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/tweb_jsfengine.html

websphere 7 shows full error to customer on web app deployment/starting error

i have deployed my web application in WebSphere 7. this application is build using spring and jsp servlets. some times when it get deployed due to errors it shows the following attached image like errors.
i have handled my web application errors as follows, by redirecting the errors to spring controller.
<error-page>
<error-code>500</error-code>
<!--Internal server error -->
<location>/error.p?message=500</location>
</error-page>
<error-page>
<error-code>403</error-code>
<!--Forbidden -->
<location>/main.p</location>
</error-page>
but it only works when the web application is successfully deployed. when deployment error happens WebSphere shows full error message like above.
is there any way to hide this error page and add custom error page in websphere when such deployment errors happens?
If you have an Apache server (or other) in front of your WebSphere, you may use it to redirect error 500 on a custom static web page.
Since you're using Spring, if this error can occur often, you can try to use lazy bean initialization on the remoteOMSConnectorWS (See LazyInitTargetSource). This would delay bean instantiation until its first use, most likely after webapp complete startup. In this case, your error configuration from web.xml could be used.

Setup bootstrup file in java web application

I read about bootstrapping here. How can I setup bootstrup file in my web application written with jsf,spring and hibernate.Is it necessary to setup bootstrup file in my application?
Java web applications are "bootstrapped" by the web container in which they are run (e.g. Tomcat) and you don't have to do it yourself.
However, if you want to add additional operations to be executed when the application is started up (and/or clean-up operations to be executed when the application is shut down), the servlet API provides the "context listener" mechanism.
Basically, you have to create a class that implements javax.servlet.ServletContextListener which has 2 methods, contextInitialized and contextDestroyed, that are executed when the application is started up, respectively shut down.
You must then add configure this class in web.xml, with something like that :
<listener>
<description>My Context listener</description>
<display-name>My Context listener</display-name>
<listener-class>
com.acme.myapp.MyContextListener
</listener-class>
</listener>
(Or in JEE6 you could use the javax.servlet.annotation.WebListener annotation instead of XML)
Google is you friend for the details, but here are some links to start with :
http://www.roseindia.net/servlets/ServletContextListener-example.shtml
http://docs.oracle.com/javaee/5/tutorial/doc/bnafi.html

How to register listener without web.xml

Im currently working on a grizzly, spring and jersey project and i have encountered:
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
... 32 more
Based on the stacktrace (and also by the results when i google), i should register a listener in the web.xml
<web-app ...>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
</web-app>
So my question is, how will i register the listener to the grizzly server given that i dont have a web.xml?
Without seeing more of your code, my guess would be to use a ServletHandler - check out the example source in the top of the Javadocs for this class:
org.glassfish.grizzly/servlet.ServletHandler
A normal spring application would have a listener registered for context startup, and then the dispatch servlet for most other things, so you should be able to amend the example code to do this.
Something like (totally untested):
sa.setServlet(new org.springframework.web.servlet.DispatcherServlet());
sa.addListener(org.springframework.web.context.ContextLoaderListener.class.getName());
sa.addContextParameter("contextConfigLocation", "beans.xml");
sa.setServletPath("/*");

HTTP Status 404 - /gwtspring/com.javacodegeeks.gwtspring.Application/Application.html

I have problem: HTTP Status 404 - /gwtspring/com.javacodegeeks.gwtspring.Application/Application.html I tried to write spring gwt aplication according to tutorial: http://www.javacodegeeks.com/2010/07/gwt-2-spring-3-jpa-2-hibernate-35.html. I dont know how I public client resources for example css, html, js, pictures. I have Tomcat 7.0. Cient resources are in sub directory, where tomcat blocking readning.![enter image description here][1]
Assuming you have your static resources in a root-folder called "res", you could do it like this. In your web.xml, add a servlet mapping BEFORE the springGwtRemoteServiceServlet mapping like
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/res/*</url-pattern>
</servlet-mapping>
That maps all requests to /res/* to the tomcat "default" servlet instead of passing it the the GWT servlet. Other servlet-engines have similar capabilities, but they may not call the default servlet "default".

Resources