Link to home
Start Free TrialLog in
Avatar of RayAdverb
RayAdverb

asked on

Need help publishing a SOAP web service in Spring.

Hi all.

I'm doing some project work to learn web application development.  These projects are simulations of Human Resources systems.  One (Employee Management) is written in Struts/Spring with JDBC for database access.  The other (Talent Management System) uses Spring with Hibernate for database backing.

I have 2 different projects, the Talent Management System and the Employee Management System.  Talent Management System sends an object, representing a Performance Review, to the Employee Management System.  It uses SOAP to publish it.  Here is the code I have currently that generates the WSDL and publishes it:

//This exposes a SOAP based web service to send the PerformanceRating for
//an employee over to the Employee Management System
@WebService
public class SendPerformanceRatingWebService implements DisposableBean
{
	private static final Logger logger = Logger.getRootLogger();
	private PerformanceManagementDelegateInterface pmDelegate = new PerformanceManagementDelegate();
	
	private Endpoint ep = null;

	//Method is being sent over the SOAP service.
	@WebMethod
	@WebResult(partName="performanceRatingResponse")
	public PerformanceReview sendPerformanceRating(int givenEmployee)
	{
		PerformanceReview serveThis = 
				pmDelegate.getReviewForPerson(givenEmployee, new TMS_DAO_Impl());
		
		logger.debug("GOT A PERFORMANCE REVIEW\n" +serveThis.toString());
		
		return serveThis;
	}
	
	public static void main(String[] args)
	{
		logger.info("**********************************************");
		logger.info("PUBLISHING SEND PERFORMANCE RATING WEB SERVICE");
		logger.info("**********************************************");
		
		
		String endPointURL = 
				"http://localhost:9999/TalentManagementSystem/sendPerformanceWebService";

		try
		{
			ep = Endpoint.publish(endPointURL, new SendPerformanceRatingWebService());
		}
		catch(ServerRtException e)
		{
			logger.info("CANNOT PUBLISH.  WEB SERVICE IS ALREADY RUNNING",e);
		}
		
	}

Open in new window


Maybe you can see where this is going.  At present, the only way I can figure out to publish the web service is to open the SendPerformanceRatingWebService class in Eclipse and click the "Run" button to publish via execution of the main method.  It's not really a long term solution because you don't want to have to click some button to get your web service started.  You just want it to start when the rest of the program starts.

So I wired up a bean in my Spring XML configuration file.

	<!-- Bean for creating and destroying SOAP web service. -->
	<bean id="startWebServiceBean" name="startWebServiceBean"
		class="com.eintern.tms.webservice.SendPerformanceRatingWebService" scope="singleton">
	</bean>	

Open in new window


Then changed the code in SendPerformanceRatingWebService to get rid of the main method and instead have the constructor call a publishWebService() method.  

//This exposes a SOAP based web service to send the PerformanceRating for
//an employee over to the Employee Management System
@WebService
public class SendPerformanceRatingWebService implements DisposableBean
{
	private static int count = 0;
	
	
	private static final Logger logger = Logger.getRootLogger();
	private PerformanceManagementDelegateInterface pmDelegate = new PerformanceManagementDelegate();
	
	private Endpoint ep = null;
	
	public SendPerformanceRatingWebService() 
	{
		publishWebService();
	}


	//Method is being sent over the SOAP service.
	@WebMethod
	@WebResult(partName="performanceRatingResponse")
	public PerformanceReview sendPerformanceRating(int givenEmployee)
	{
		PerformanceReview serveThis = 
				pmDelegate.getReviewForPerson(givenEmployee, new TMS_DAO_Impl());
		
		logger.debug("GOT A PERFORMANCE REVIEW\n" +serveThis.toString());
		
		return serveThis;
	}
	
	private void publishWebService()
	{
		logger.info("**********************************************");
		logger.info("PUBLISHING SEND PERFORMANCE RATING WEB SERVICE");
		logger.info("**********************************************");
		
		
		String endPointURL = 
				"http://localhost:9999/TalentManagementSystem/sendPerformanceWebService";

                logger.debug("COUNT:\t" +count++)

		try
		{
			logger.debug("INSIDE TRY BLOCK");
       			ep = Endpoint.publish(endPointURL, new SendPerformanceRatingWebService());
 		}
		catch(ServerRtException e)
		{
			logger.info("CANNOT PUBLISH.  WEB SERVICE IS ALREADY RUNNING",e);
		}
		
	}

Open in new window


I keep getting Stack Overflow Errors.  Which means there's something I'm not getting about how this bean wiring process works.  It runs about 4000 times (very quickly too -- only taking a few seconds for all 4000 executions).  It reaches the body of that Try block every time..  But it seems like maybe it's also unpublishing the web service.  Because 1) The try block keeps executing and the exception is never thrown and 2) even if I try to thwart the Stack Overflow Errors by inserting a return statement after only a few executions, the webservice is still not published and the WSDL is still not available.

What am I getting wrong?  How can I publish my web service without manual execution of the method?
Avatar of RayAdverb
RayAdverb

ASKER

Ok so far I think I realized what's happening and it seems like kind of a dumb mistake.  My constructor is calling the publish method, which then calls the constructor when it tries to publish, which then calls publish method.... and so on hence there is the recursive function causing my stack overflow problems.  

Previously I wasn't getting the constructor involved in the publishing process beyond the implicit invocation when the object is created.  I think I need a new approach.
ASKER CERTIFIED SOLUTION
Avatar of RayAdverb
RayAdverb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial