Announcement Announcement Module
Collapse
No announcement yet.
FlexMobile-Spring-jpa :remote service call failed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlexMobile-Spring-jpa :remote service call failed

    hello
    i'm trying to build a flex mobile application that call a remote service from a java application.
    unfortunately i can't detect the cause of failure of call of remote service.
    this is the source code of java application


    DAO layer:1.AbstractJpaDAO.java


    package daos;

    import java.io.Serializable;
    import java.util.List;

    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    public abstract class AbstractJpaDAO< T extends Serializable > {

    private Class< T > clazz;

    @PersistenceContext
    EntityManager entityManager;

    public void setClazz( final Class< T > clazzToSet ){
    this.clazz = clazzToSet;
    }

    public T findOne( final Long id ){
    return entityManager.find( clazz, id );
    }
    public List< T > findAll(){
    return entityManager.createQuery( "from " + clazz.getName() )
    .getResultList();
    }

    public void save( final T entity ){
    entityManager.persist( entity );
    }

    public void update( final T entity ){
    entityManager.merge( entity );
    }
    public void delete( final T entity ){
    entityManager.remove( entity );
    }
    public void deleteById( final Long entityId ){
    final T entity = findOne( entityId );

    delete( entity );
    }
    }

    DAO layer:2. IGenericDAO.java

    package daos;
    import java.util.List;
    public interface IGenericDAO<T> {
    public void setClazz( final Class< T > clazzToSet );
    public T findOne( final Long id );
    public List< T > findAll();
    public void save( final T entity );
    public void update( final T entity );
    public void delete( final T entity );
    public void deleteById( final Long entityId );
    }

    DAO layer:3.GenericJpaDAO.java

    package daos;
    import java.io.Serializable;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Repository;
    @Repository
    public class GenericJpaDAO< T extends Serializable >
    extends AbstractJpaDAO< T > implements IGenericDAO< T >{
    //
    }

    Service layer
    1.UserService.java

    package service;
    import java.util.List;
    import org.springframework.beans.factory.annotation.Autow ired;
    import org.springframework.flex.remoting.RemotingDestinat ion;
    import org.springframework.flex.remoting.RemotingInclude;
    import org.springframework.stereotype.Service;
    import daos.IGenericDAO;
    import entities.User;
    @Service
    @RemotingDestination(channels = { "my-amf" })
    public class UserService {
    IGenericDAO<User> userdao;
    public IGenericDAO<User> getUserdao() {
    return userdao;
    }
    @Autowired
    public final void setUserdao(final IGenericDAO<User> userdao) {
    this.userdao = userdao;
    this.userdao.setClazz(User.class);
    }
    @RemotingInclude
    public void saveOneDao(User user) {
    userdao.save(user);
    }
    @RemotingInclude
    public List<User> getAllUser() {
    List<User> l = userdao.findAll();
    return l;
    }}

    XML Files:
    1.web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>TestMetier</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <!-- Att: dans param-value vous devez spécifier le chemain de fichier de configuration. dans notre cas
    /WEB-INF/applicationContext.mxml -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <listener>
    <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>
    <!-- Flex Spring Servlet *************************** -->
    <servlet>
    <servlet-name>flexspring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>flexspring</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
    </servlet-mapping>
    <!-- MessageBroker Servlet*************************** -->
    <servlet>
    <servlet-name>MessageBrokerServlet</servlet-name>
    <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
    <init-param>
    <param-name>services.configuration.file</param-name>
    <param-value>/WEB-INF/flex/services-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>MessageBrokerServlet</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
    </servlet-mapping>
    <!-- RDS Servlet *************************** -->
    <servlet>
    <servlet-name>RDSDispatchServlet</servlet-name>
    <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
    <init-param>
    <param-name>useAppserverSecurity</param-name>
    <param-value>false</param-value>
    </init-param>
    <load-on-startup>10</load-on-startup>
    </servlet>
    <servlet-mapping id="RDS_DISPATCH_MAPPING">
    <servlet-name>RDSDispatchServlet</servlet-name>
    <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
    </servlet-mapping>
    </web-app>

    XML Files:2.applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:flex="http://www.springframework.org/schema/flex" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schem...ing-tx-3.0.xsd
    http://www.springframework.org/schema/flex
    http://www.springframework.org/schem...g-flex-1.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!-- Ce tag permet de déclarer que vous allez travallez avec les annotations -->
    <context:annotation-config />
    <!-- Déclaration des packages où vous allez utilisez les annotations pour
    les prendre en considération -->
    <context:component-scan base-package="daos" />
    <context:component-scan base-package="service" />
    <!-- la source de donnéees DBCP -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbcostgresql://localhost:5432/test" />
    <property name="username" value="postgres" />
    <property name="password" value="root" />
    </bean>
    <bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="MobileProject_Spring_WEB" />
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.Hibernat eJpaVendorAdapter">
    <!-- <property name="showSql" value="true" /> -->
    <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
    <property name="generateDdl" value="true" />
    </bean>
    </property>
    <property name="loadTimeWeaver">
    <bean
    class="org.springframework.instrument.classloading .InstrumentationLoadTimeWeaver" />
    </property>
    </bean>
    <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean id="userDAO" class="dao.UserDAO">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
    <!-- le gestionnaire de transactions -->
    <tx:annotation-driven transaction-manager="txManager" />
    <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionM anager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <!-- traduction des exceptions -->
    <bean
    class="org.springframework.dao.annotation.Persiste nceExceptionTranslationPostProcessor" />
    <!-- persistence -->
    <bean
    class="org.springframework.orm.jpa.support.Persist enceAnnotationBeanPostProcessor" />
    <bean
    class="org.springframework.beans.factory.annotatio n.AutowiredAnnotationBeanPostProcessor" />
    <!-- Flex -->
    <flex:message-broker>
    <flex:remoting-service default-channels="my-amf" />
    </flex:message-broker>
    </beans>

    Attachment

    this photo show that the call of the remote method fail
    thinks in advance.
    Attached Files
    Last edited by elyes1111; Jun 13th, 2012, 06:22 PM.

  • #2
    Solved

    the bug is that the @autowired annotation was not funtional in other word the dao layer was not crossed.
    to solve this bug i have deleted many bean from the applicationContext.xml file that not useful for spring 3.0 such example declaring bean for dao layer.

    Comment

    Working...
    X