-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Axis2 Integration
PostPosted: Fri Oct 21, 2005 10:47 am 
Newbie

Joined: Fri Oct 21, 2005 10:17 am
Posts: 2
Location: Graz, Austria
I'm currently implementing an Axis2 webservice with (already existing) Hibernate 3.05 layer for data storage.

a)putting a Listener into Axis2/WEB-INF/web.xml

<!-- Listener is fired when the application is ready to start -->
<listener>
<listener-class>org.mistral.benchmarking.webapp.StartupContextListener</listener-class>
</listener>

b)putting the hibenate .jar's into Axis/WEB_INF/lib/

c)putting the Listener class into Axis/WEB-INF/classes/org/..../webapp/
It basically starts up Hibernate at Axis2 context initialisation (when tomcat starts the Axis2.war)
public final class StartupContextListener implements ServletContextListener {

public Logger logger;

public void contextInitialized(ServletContextEvent event)
{
ServletContext context = event.getServletContext();
String realPath = context.getRealPath("/");
String configFile = "WEB-INF/classes/bm-system.properties";
String logfile = realPath + "/logs/" + "benchmarking.html";

logger = HtmlLoggerFactory.createHtmlLogger(StartupContextListener.class, logfile);

//get properties
try{
BenchmarkingSystemProperties.getInstance().load(new FileInputStream(realPath + configFile));
logger.info("loaded benchmarking system properties from " + realPath + configFile);
} catch(Exception e){
logger.info("could not load benchmarking system properties from " + realPath + configFile);
}
if(context.getServletContextName() == "Apache-Axis2")
logfile = "benchmarking_service.html";
//Torque.init(realPath + configFile);

//init benchmarking system
try{
logger.info(context.getServletContextName() + " context is initialized. startup Benchmarking...");
//***init HibernateUtil Singleton***
Benchmarking.init();
logger.info(context.getServletContextName() + " context is initialized. Benchmarking ready.");
} catch (Exception e) {
logger.error(e.getMessage());
}
}

public void contextDestroyed(ServletContextEvent event)
{
ServletContext context = event.getServletContext();
logger.info(context.getServletContextName() + " context is destroyed.");
}
}

d)using the HibernateUtil Singleton in the Axis2 webservice class
e)now i've the problem that the already created b) Singleton is null again, when calling HibernateUtil.getInstance() from the Axis2 webservice method (different classloader,...?)

Has anyone done this? Would be nice to know for both Hibernate and Axis2 communities, i think.
I'll post the solution, when i know it.

Martin Ebner


Top
 Profile  
 
 Post subject: cxt
PostPosted: Fri Oct 21, 2005 5:46 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It is not specific to Axis2 but:

this servlet gets loaded before anything else via load on startup
Code:
<servlet>
      <servlet-name>appInit</servlet-name>
      <servlet-class>com.sourcelabs.sash.demo.abuilder.opc.web.WebAppContextInitializer</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>


Code:
public class WebAppContextInitializer extends HttpServlet {

  public void init() throws ServletException {
    super.init();
    OPCApplicationCxt._setupContext( "opc" );
    getServletContext().setAttribute( "appContext",OPCApplicationCxt.getCxt() );
  }
}




the context is Spring context and all the service POJOs are wrapped in transaction interceptors to implement hibernateSession-per-businessTransaction strategy

Axis binding class simply delegates calls to the wrapped POJOs

[code]
public class PurchaseOrderService implements PurchaseOrderIntf {


public String submitPurchaseOrder( PurchaseOrder poObject ) throws POException, RemoteException{

public POStatus getPurchaseOrderStatus( String id ) throws RemoteException{
return OPCApplicationCxt.getPurchaseOrderServiceLogic().getPurchaseOrderStatus( id );
}

public PurchaseOrder getPurchaseOrder( String id ) throws POException, RemoteException{
return OPCApplicationCxt.getPurchaseOrderServiceLogic().getPurchaseOrder( id );
}

}

[/code
]

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: lazy
PostPosted: Fri Oct 21, 2005 5:48 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Oh, and do not forget to set 'lazy=false' in mappings for the strategy.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: it works:)
PostPosted: Fri Oct 21, 2005 7:50 pm 
Newbie

Joined: Fri Oct 21, 2005 10:17 am
Posts: 2
Location: Graz, Austria
thanks for your advise regarding hibernate use, and startup servlet, kgignatyev.
i've written an ant script, that packages my hibernate persistance into the Axis2 webapp and deploys it.

http://www.sbox.tugraz.at/home/m/martine/axis2-hibernate/build.xml

Now it works fine.
ServletContextListener works as well.

Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.