So I built what is an instant messaging bot using the Smack API and the Openfire XMPP server. Doing it is pretty simple of you read the documentation and Smack’s developer notes. The bot relies on a queue-like object that Smack gives you called a PacketCollector. All you need to do is log in to the server, and let the packet collector wait for incoming messages. Clearly, you need to respond to the messages and use thread tools to do the waiting and all, but in general, the effort is relatively straightforward.
Category: WebSphere
The Jetty web application server is great. It is just not very well document and when it is documented it is aimed for the very uninitiated. If you’re using Jetty, it is almost like an old boys club – ‘you made it’.
Still, it appears that Jetty and Tomcat are becoming much more similar in their way of doing things, with both using a somewhat proprietary, if you can say that on an open source project, configuration schemes. So how do you deploy a web application to Jetty?
So you have a Spring MVC web application and want to make sure that when the user enters a URL such as
http://www.myawesomedomain.com
he/she will see the home page of your application. How do you get Spring MVC’s RequestDispatcher servlet, which acts as the traffic cop and then some for your web application, to act as the default URL handler in the eyes of the web application? There are two good ways to do it, and two bad ones. Let’s start with the bad ones, of course:
- Redirect through meta tag: you add a meta-refresh element to the head element which causes the browser showing the page to go the ‘real’ home page url, such as /index.do
- You use JavaScript to force the page to redirect – this will also work but forces you to rely on client-side processes to get stuff done. For example:
window.location="index.do"
inside anindex.html
file.
Both are sub-prime because search engines are not too keen to follow such redirects, often time avoiding JavaScript altogether.
So what are the good ways:
- Using Apache’s mod-rewrite to mask the URL of your application, but that assumes you have a web server in front of your application
- Using the servlet API – which is what you read below
So how do you do it?
-
In the application’s
web.xml
file map the RequestDispatcher servlet to handle requests forindex.htm
, aside from handling the extension of your liking, say, *.do. You do this through theservlet-mapping
element. This should look like this:<servlet -mapping> </servlet><servlet -name>requestDispatcher</servlet> <url -pattern>*.do</url> </servlet -mapping> <servlet -mapping> </servlet><servlet -name>requestDispatcher</servlet> <url -pattern>/index.htm</url> </servlet -mapping>
-
Also in
web.xml
, set up a welcome file that may be requested by a browser when a user does not enter a specific page request, e.g.www.domain.com
. Most browsers at a minimum will automatically request, on behalf of the user,index.html
andindex.htm
.
So choose one, say index.htm
and set the <welcome-file>
element to look something like this:
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
This will make your application by default make requests for ‘/’ go to index.htm
.
index.htm
to the controller for the application’s home page. You do this in a Spring MVC beans xml file when specifying the URL mapper.For example:
<bean id="unAuthenticatedUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/index.do">homePageController</prop> <prop key="/index.htm">homePageController</prop> </props> </property> </bean>
This way the RequestDispatcher will know which control is actually going to load the information that will be displayed by the view for the home page.
And that’s it. No redirection. No nonsense.