wgm
Oct 21st, 2005, 08:34 AM
Hi,
I am trying to develop a project that can be accessed by both a web application and a WS application via axis. In this project, there is an object that can cache something and should be shared by both applications as defined by the spring config file. However, the test results indicate that this object cannot be shared.
Can anybody tell me if anything is wrong?
Thanks in advance,
Guanming
Some related code is attached:
Spring config file:
...
<bean id="biopaxService" class="org.reactome.servlet.BioPAXExporterService" singleton="true">
<property name="defaultDbName">
<value>${jdbc.defaultDbName}</value>
</property>
<property name="dbUser">
<value>${jdbc.dbUser}</value>
</property>
<property name="dbPwd">
<value>${jdbc.dbPwd}</value>
</property>
<property name="dbPort">
<value>${jdbc.dbPort}</value>
</property>
<property name="converter">
<ref bean="converter" />
</property>
</bean>
<bean id="exporterController" class="org.reactome.servlet.BioPAXExporterController">
<property name="service">
<ref bean="biopaxService" />
</property>
</bean>
...
WS Java code to use the service object:
public class BioPAXExporterWSEndpoint extends ServletEndpointSupport {
// The wrapped actual business object
private BioPAXExporterService service;
protected void onInit() {
service = (BioPAXExporterService) getWebApplicationContext().getBean("biopaxService");
}
public String getBioPAXModel(Long dbID) throws Exception {
System.out.println("Service in WS: " + service);
Document doc = service.getBioPAXModel(dbID);
// Need to convert doc to a String so that it can be consumed by WS client easily
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
StringWriter writer = new StringWriter();
outputter.output(doc, writer);
return writer.toString();
}
}
Web application Java Code:
public class BioPAXExporterController extends AbstractCommandController {
// To provide actual service
private BioPAXExporterService service;
public BioPAXExporterController() {
setCommandClass(BioPAXExporterCommand.class);
}
public void setService(BioPAXExporterService service) {
this.service = service;
}
protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
System.out.println("Service in servlet: " + service);
HashMap map = new HashMap();
BioPAXExporterCommand parameters = (BioPAXExporterCommand) command;
Long dbID = parameters.getDbID();
String dbName = parameters.getDbName();
Document biopaxModel = null;
if (dbName == null)
biopaxModel = service.getBioPAXModel(dbID);
else
biopaxModel = service.getBioPAXModel(dbName, dbID);
return new ModelAndView("biopaxView", "biopaxModel", biopaxModel);
}
}
I am trying to develop a project that can be accessed by both a web application and a WS application via axis. In this project, there is an object that can cache something and should be shared by both applications as defined by the spring config file. However, the test results indicate that this object cannot be shared.
Can anybody tell me if anything is wrong?
Thanks in advance,
Guanming
Some related code is attached:
Spring config file:
...
<bean id="biopaxService" class="org.reactome.servlet.BioPAXExporterService" singleton="true">
<property name="defaultDbName">
<value>${jdbc.defaultDbName}</value>
</property>
<property name="dbUser">
<value>${jdbc.dbUser}</value>
</property>
<property name="dbPwd">
<value>${jdbc.dbPwd}</value>
</property>
<property name="dbPort">
<value>${jdbc.dbPort}</value>
</property>
<property name="converter">
<ref bean="converter" />
</property>
</bean>
<bean id="exporterController" class="org.reactome.servlet.BioPAXExporterController">
<property name="service">
<ref bean="biopaxService" />
</property>
</bean>
...
WS Java code to use the service object:
public class BioPAXExporterWSEndpoint extends ServletEndpointSupport {
// The wrapped actual business object
private BioPAXExporterService service;
protected void onInit() {
service = (BioPAXExporterService) getWebApplicationContext().getBean("biopaxService");
}
public String getBioPAXModel(Long dbID) throws Exception {
System.out.println("Service in WS: " + service);
Document doc = service.getBioPAXModel(dbID);
// Need to convert doc to a String so that it can be consumed by WS client easily
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
StringWriter writer = new StringWriter();
outputter.output(doc, writer);
return writer.toString();
}
}
Web application Java Code:
public class BioPAXExporterController extends AbstractCommandController {
// To provide actual service
private BioPAXExporterService service;
public BioPAXExporterController() {
setCommandClass(BioPAXExporterCommand.class);
}
public void setService(BioPAXExporterService service) {
this.service = service;
}
protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
System.out.println("Service in servlet: " + service);
HashMap map = new HashMap();
BioPAXExporterCommand parameters = (BioPAXExporterCommand) command;
Long dbID = parameters.getDbID();
String dbName = parameters.getDbName();
Document biopaxModel = null;
if (dbName == null)
biopaxModel = service.getBioPAXModel(dbID);
else
biopaxModel = service.getBioPAXModel(dbName, dbID);
return new ModelAndView("biopaxView", "biopaxModel", biopaxModel);
}
}