- This topic has 2 replies, 2 voices, and was last updated 16 years ago by gallaxe.
-
AuthorPosts
-
gallaxeMemberHello,
I tried to create a Web Service using Spring with Ibatis support. I use MyEclipse
7.0 M2.CalculatorService example is running fine (without Ibatis).
I created a LoginService which has to find out whether a user exists in a database.
My steps were the following:1. Create a Web Service project.
2. Add Spring capabilities.
3. Add Jax-WS libraries (if not I got errors when deploying to Tomcat, although it is
MyEclipse Tomcat and I believed there were no need to do this manually).4. Created some classes:
– User with some props like loginName and password
– UserDao extends SqlMapClientDaoSupport
with a method
public User getUser(String login, String pass) {
Map parameterMap = new HashMap<String, String>();
parameterMap.put(“log”, login);
parameterMap.put(“pw”, pass);
return (User)getSqlMapClientTemplate().queryForObject(“getUser”);
}– LoginService
private UserDao userDao;
private User user;public LoginService() {
super();
}public boolean isUserAvailable(String login, String passwd) {
return getUser(login, passwd) != null;
}public User getUser(String login, String passwd) {
return userDao.getUser(login, passwd);
}public void setUserDao(UserDao userDao) {
this.userDao= userDao;
}5. Create a Web Service from class LoginService
(Clicking “generate WSDL file” in the wizard causes an error “Unable to create
JAXBContext” like some other people described in the forum.)The file “applicationContext.xml” looks like:
<bean id=”dataSource” class=”org.apache.commons.dbcp.BasicDataSource” destroy-method=”close”>
<property name=”driverClassName” value=”someDriverr”/>
<property name=”url” value=”someUrl”/>
<property name=”username” value=”someUsername”/>
<property name=”password” value=”somePassword”/>
</bean><bean id=”sqlMapClient” class=”org.springframework.orm.ibatis.SqlMapClientFactoryBean”>
<property name=”configLocation” value=”WEB-INF/sqlmap-config.xml”/>
<property name=”dataSource” ref=”dataSource”/>
</bean><bean id=”userDao”
class=”UserDao”>
<property name=”sqlMapClient” ref=”sqlMapClient”/>
</bean>This caused an error “org.apache.commons.dbcp.BasicDataSource” Class not found,
so I had to try adding some libraries until I found that I had to add
“Spring Persistence JDBC Library”.6. After creating the Web Service I have a folder “.apt_generated” and a class
“LoginServiceDelegate” with the methodspublic boolean isUserAvailable(String login, String passwd) {
return loginService.isUserAvailable(login, passwd);
}public User getUser(String login, String passwd) {
return loginService.getUser(login, passwd);
}public void setUserDao(UserDao userDao) {
loginService.setUserDao(userDao);
}7. Deploying that Web Service to MyEclipse Tomcat causes the error:
(some more messages)
……………….
org.springframework.jdbc.support.SQLExceptionTranslator is an interface, and JAXB can’t handle interfaces.
this problem is related to the following location:
at org.springframework.jdbc.support.SQLExceptionTranslator
at public synchronized org.springframework.jdbc.support.SQLExceptionTranslator org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator()
at org.springframework.jdbc.support.JdbcAccessor
at org.springframework.orm.ibatis.SqlMapClientTemplate
at public final org.springframework.orm.ibatis.SqlMapClientTemplate org.springframework.orm.ibatis.support.SqlMapClientDaoSupport.getSqlMapClientTemplate()
at org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
at UserDao
at private UserDao jaxws.SetUserDao.arg0
at jaxws.SetUserDao
org.springframework.jdbc.support.SQLExceptionTranslator does not have a no-arg default constructor.
this problem is related to the following location:
at org.springframework.jdbc.support.SQLExceptionTranslator
at public synchronized org.springframework.jdbc.support.SQLExceptionTranslator org.springframework.jdbc.support.JdbcAccessor.getExceptionTranslator()
at org.springframework.jdbc.support.JdbcAccessor
at org.springframework.orm.ibatis.SqlMapClientTemplate
at public final org.springframework.orm.ibatis.SqlMapClientTemplate org.springframework.orm.ibatis.support.SqlMapClientDaoSupport.getSqlMapClientTemplate()
at org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
at UserDao
at private UserDao jaxws.SetUserDao.arg0
at jaxws.SetUserDaoat com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:438)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:286)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)I tried the following: commented out the method “setUserDao” from LoginServiceDelegate.
Deploying then to Tomcat works fine and I can test LoginService.isUserAvailable if this is
implemented likereturn login.equals”bla” correctly, but not with the actual implementation
return getUser(login, passwd) != null;
This causes a NullPointerException on userDao. Why? I thought Springs DI had to create
this object, because it is in applicationContext.xml defined.How can I get the Web Service work correctly?
Much text, I know, but I think it is needed to understand the problem.
Hope, someone can help me, thanks very much!
Gerhard.
Loyal WaterMemberMoving to Off Topic >> Software Development.
gallaxeMemberHello,
I could not solve the problem, but found out, that MyEclipse does not support Spring Web Services.
So I tried the following approach (without using Ibatis, very simple example):– Created a Web Service Project called WsTest using the wizard.
– Created a class test.TestClass and a class test.TestStub.TestStub has the following method:
public int mult(int arg1, int arg2) { return arg1 * arg2; }
TestClass looks like:
public class TestClass { // testStub I expected to be invoked by Springs DI private TestStub testStub; public TestClass() { } // Following method just to see if the Web Service works public int add(int arg1, int arg2) { return arg1 + arg2; } // Following method uses testStub, which should be initialized by // Springs DI. public int mult(int arg1, int arg2) { return testStub.mult(arg1, arg2); } // Following method just to test class TestStub public int multNeg(int arg1, int arg2) { testStub = new TestStub(); return (-1) * testStub.mult(arg1, arg2); } }
– added Spring Capabilities with Library Spring 2.5 Core
and Spring 2.5 Web (without the latter I got errors).applicationContext.xml I put in the folder WebRoot/WEB-INF
It looks like:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="testStub" class="test.TestStub"> </bean> </beans>
– Created a Web Service using the wizard from TestClass, marked
“create wsdl”.– Deployed the Web Service to MyEclipse Tomcat.
– Got an error, added the JAX-WS 2.1 libraries and redeployed.
– With Web Service Explorer found the Web Service and tried
TestClass.add worked fine
TestClass.mult failed with NullPointer
TestClass multNeg worked fine.It seems to me that Spring did not the DI with the TestStub class.
I think Spring itself was not initialized.So I searched the Web to find a solution. In this forum I found in a
thread JSF and Spring to add some stuff to the web.xml. I did this and
web.xml looks like<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <servlet> <description>JAX-WS endpoint - TestClassService</description> <display-name>TestClassService</display-name> <servlet-name>TestClassService</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>TestClassService</servlet-name> <url-pattern>/TestClassPort</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener></web-app>
– I created the Web Service new and redeployed it to the Tomcat server.
– Starting the server I got the following (within some other) lines:
…..
INFO: Starting Servlet Engine: Apache Tomcat/6.0.13
23.10.2008 11:39:45 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
23.10.2008 11:39:45 com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
23.10.2008 11:39:47 com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
INFO: WSSERVLET14: JAX-WS servlet initializing
…Seems, that Spring was initialized
– Testing the Web Service with the Explorer (after getting the WSDL new)
caused the same picture as before.testClass.add works ok
testClass.mult (which uses testStub.mult which should be initialized by Spring DI) caused the error:
23.10.2008 11:40:39 com.sun.xml.ws.server.sei.EndpointMethodHandler invoke
SCHWERWIEGEND: null
java.lang.NullPointerException
at test.TestClass.mult(TestClass.java:17)
at test.TestClassDelegate.mult(TestClassDelegate.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)Much text, I know, but can anyone help me? I assume the error is in one of the configuration files web.xml
or applicationContext.xml, but what is wrong?Greetings, Gerhard.
-
AuthorPosts