Showing posts from February, 2012

How To Find Good Articles To Read On Internet Without Wasting Time

The issue is, say you are interested to read articles on marketing or on a topic of your interest. You Googled and found some good blogs that contains articles on category of your choice. Say, you got 15 such sites. You have to visit 15 blogs daily to see whether they have published a new article. Which is very time wasting and boring if you discover nothing interesting from most of them. The solutions is RSS reader! Oooops what the hell it is? Don't worry, its very simple to use. Someone said, if we knew the pleasure of destination, a difficult journey becomes very easy. After you have configured the RSS reader, you will use RSS reader to subscribe to different sites/blogs, its only 6-8 seconds task. But as result, it pulls all new articles from that blog and shows you their titles at one page. From where you can read any articles. Assume how easy the life would be if you get 100 articles on different sites at one page. Let me demonstrate by example , say you love to read new stu

How to Get Spring Managed Service Instance Outside the Action Class in Struts2

In Struts 2, we can configure Spring to inject service instanced using Dependency Injection into Action classes. But sometime we need these service class instances in other components who are are Spring aware. For example you need AccountsService instance in StudentService class. For such purpose I have createds util class which can return me reference to any service instance at run time, in any class. I call is SpringContext, here is its definition: package com.bitspedia.util; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; public class SpringContext implements ApplicationContextAware { private static ApplicationContext CONTEXT; public void setApplicationContext(ApplicationContext context) throws BeansException { CONTEXT = context; } public static Object getBean(String beanName) { return CONTEXT.getBean(beanName); } } Now getting the r

How to Run a Code Immediately After the Web Application or Context is Deployed in Tomcat

If are writing a web app using Java (JSP or Servlets), sometime we want to execute a code section immediately after the application context has deployed. For examples to: Initialize Caching system Initialize some scheduling services Put some data is application scope that will be needed frequently. Before Servlets 2.4, such code was put in a normal Serlvet, which was configured in web.xml to run at startup. But in Servlets 2.4, there is explicit mechanism to do so. Here is how you can do it: Make a class MyListener that implements ServletContextListener Write the code you want to run only once (after the context is loaded, i.e. when the web application is deployed in Tomcat) in contextInitialized(ServletContextEvent cse) method. package mypackage; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class MyListener implements ServletContextListener { public void contextInitialized(ServletContextEvent cse)

How To Define Handlers Chain in JAX-WS Using LogicalHandler and SOAPHandler At Same Time

JAX-WS Handlers implement Interceptor Pattern and Chain of Responsibility Pattern, that means when a client sends a SOAP request to a service endpoint, the handles intercept the request, perform some processing and (optionally) forward request to next handler in the chain, until the actual service implementation process the request. A handler may process the request by itself by replying to the service client. It depends how you have implemented the handlers. JAX-WS provides two types of handlers i.e. LogicalHandler and SOAPHandler. In this article I will show have you can define both types of handlers in the a chain and how/when the runtime calls their life cycle method i.e. handleMessage() to provide them opportunity of processing the request. Generally handlers do not process the request, they only perform 'cross cutting concerns' tasks e.g. authentication, authorization, logging, accounting, validation, etc. Let us define a web service, which have only one method. We can al

How to Extract SOAP Header Information from a SOAP Message in JAX-WS class

Lets assume, you have username and password in your Inbound SOAP Message header. Here is how you can get these headers: String userName, password; for (Iterator it = soapMessageContext.getMessage().getSOAPHeader().examineAllHeaderElements(); it.hasNext(); ) { SOAPHeaderElement e = (SOAPHeaderElement); String eName = e.getElementName().getLocalName(); if (eName.equals("username")) { userName = e.getValue(); } else if (eName.equals("password")) { password = e.getValue(); } }

How To Get MessageContext In Service Implementation Class In JAX-WS

MessageContext is used to get almost all type of info associated with current SOAP request. In JAX-WS, this how you can get MessageContext in your service implementation class: @WebService public class TestingService { @Resource WebServiceContext wsc; @WebMethod public String sayHi(String name) { MessageContext mc = wsc.getMessageContext(); } } If you are thinking who set the WebServiceContext in our class, its runtime. Before the SOAP method is called. The runtime inject the WebServiceContext identifying by @Resource annotation. And from this WebServiceContext, we get MessageContext.