Hi there,
I've tested integrate Struts 1.3 + XFire 1.26 + Spring 2.5 + JPA followed tutorials and examples that I've found by googling.
Finally, almost done but there are still some probs needed help.
Here is my config:
web.xml
applicationContext.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" > <!-- contexts --> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml </param-value> </context-param> <!-- listerners --> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- servlets --> <servlet> <servlet-name>xfire</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- mappings --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <!-- filter --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- welcome file list --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
persistence.xml (place both src/META-INF and WEB-INF)Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" > <!-- config JPA capabilites --> <bean id="loadTimeWeaver" class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /> <bean id="vendorAdapter" class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"> <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.oracle.OraclePlatform" /> <property name="showSql" value="false" /> <property name="generateDdl" value="false" /> </bean> <bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"> <property name="persistenceXmlLocations"> <list> <value>classpath*:/META-INF/persistence.xml</value> </list> </property> <property name="loadTimeWeaver" ref="loadTimeWeaver" /> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceUnitName" value="DTKBPU" /> <property name="jpaVendorAdapter" ref="vendorAdapter" /> <property name="persistenceUnitManager" ref="persistenceUnitManager" /> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- DAOs --> <bean name="userDAO" class="vn.kbnn.dtkb.system.dtos.UserDAO"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans>
struts-config.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="DTKBPU" transaction-type="JTA"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <jta-data-source>jdbc/dtkb</jta-data-source> <class>vn.kbnn.dtkb.system.dtos.User</class> <properties> <property name="toplink.logging.level" value="INFO" /> </properties> </persistence-unit> </persistence>
LoginAction extends DispatchActionSupport and have a call to method of UserServiceCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans /> <global-exceptions /> <global-forwards /> <action-mappings type="vn.kbnn.framework.web.XActionMapping"> <action path="/prelog" parameter="PRELOG" type="vn.kbnn.dtkb.system.web.actions.LoginAction"> <set-property property="loginRequire" value="false"/> <forward name="cookied" redirect="false" path="/login.do"/> <forward name="notcookied" redirect="false" path="/login.jsp"/> </action> <action path="/logout" parameter="LOGOUT" type="vn.kbnn.dtkb.system.web.actions.LoginAction"> <set-property property="loginRequire" value="false"/> <forward name="success" redirect="false" path="/login.jsp"/> <forward name="failure" redirect="false" path="/failures/failure.jsp"/> </action> <action path="/login" parameter="LOGIN" type="vn.kbnn.dtkb.system.web.actions.LoginAction"> <set-property property="loginRequire" value="false"/> <forward name="success" redirect="false" path="/main.jsp"/> <forward name="error" redirect="false" path="/login.jsp"/> <forward name="failure" redirect="false" path="/failures/failure.jsp"/> </action> </action-mappings> <message-resources parameter="vn.kbnn.dtkb.web.ApplicationResources" /> </struts-config>
Code:private ActionForward login(ActionMapping _actionMapping, ActionForm _actionForm, HttpServletRequest _httpServletRequest, HttpServletResponse _httpServletResponse) { Service serviceModel; HttpSession httpSession; httpSession = _httpServletRequest.getSession(); serviceModel = new AnnotationServiceFactory().create(UserServiceImpl.class); try { User paraUser = (User)getMaster("vn.kbnn.dtkb.system.dtos.User", _httpServletRequest); try { IUserService userService = (IUserService) new XFireProxyFactory().create( serviceModel, "http://localhost/DTKB/services/UserService?wsdl"); User user = userService.login(paraUser); httpSession.setAttribute(Constant.USER_SESSION_KEY, user); if (user.getId() != "") { return _actionMapping.findForward("success"); } else { return _actionMapping.findForward("error"); } } catch (MalformedURLException murle) { _httpServletRequest.setAttribute(Constant.ERROR_MESSAGE_REQUEST_KEY, murle.getMessage()); return _actionMapping.findForward("failure"); } } catch (Exception e) { _httpServletRequest.setAttribute(Constant.ERROR_MESSAGE_REQUEST_KEY, e.getMessage()); return _actionMapping.findForward("failure"); } }


Reply With Quote