gabron
May 28th, 2009, 11:20 AM
I'm having a difficult time getting rc2 working with flex. I have experience with Flex, but I've never actually had to configure the remoting piece of it. I have an existing Spring project that utilizes spring mvc. I believe that I have the server side configured properly, I feel it might be a flex configuration at this point. My remote objects alway hit the fault handler and the trace on that doesn't produce anything helpful. I was wondering is someone has a bare bones flex and spring project setup that they might be able to post so I can have a look at how this is done. I will post some of the code below and maybe someone will see something obvious. Thanks in advance
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestCon textListener</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
application context.xml
<flex:message-broker services-config-path="/WEB-INF/config/flex/services-config.xml">
<flex:message-service default-channels="my-amf" />
</flex:message-broker>
services config
<services>
<service-include file-path="remoting-config.xml" />
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
remoting config.xml
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdap ter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</service>
annotated remote bean
@Service("userService")
@RemotingDestination(value = "userService", channels={"my-amf"})
public class UserServiceImpl implements UserService {
@Override
@RemotingInclude
public User findByUserName(String userName) {
System.out.println(userName);
return null;
}
@Override
@RemotingInclude
public User saveUser(User user) {
return null;
}
}
And here is the mxml file from the flex project. I have also added the java server information to the project and it validated.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private function handleClick(event:Event):void
{
var name:String = "testUserName";
roUser.findByUserName(name);
}
private function handleFindUserByName(event:ResultEvent):void
{
event.result as User;
}
private function handleCreateFault(event:FaultEvent):void
{
trace(event.message);
}
]]>
</mx:Script>
<mx:RemoteObject id="roUser" destination="userService" >
<mx:method name="saveUser" result="handleCreate(event)" fault="handleCreateFault(event)" />
<mx:method name="findByUserName" result="handleFindUserByName(event)" fault="handleCreateFault(event)" />
</mx:RemoteObject>
<mx:Button id="btn" label="Create" click="handleClick(event)" />
Any suggestions or sample projects would be appreciated. Thanks
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestCon textListener</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
application context.xml
<flex:message-broker services-config-path="/WEB-INF/config/flex/services-config.xml">
<flex:message-service default-channels="my-amf" />
</flex:message-broker>
services config
<services>
<service-include file-path="remoting-config.xml" />
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
remoting config.xml
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdap ter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</service>
annotated remote bean
@Service("userService")
@RemotingDestination(value = "userService", channels={"my-amf"})
public class UserServiceImpl implements UserService {
@Override
@RemotingInclude
public User findByUserName(String userName) {
System.out.println(userName);
return null;
}
@Override
@RemotingInclude
public User saveUser(User user) {
return null;
}
}
And here is the mxml file from the flex project. I have also added the java server information to the project and it validated.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
private function handleClick(event:Event):void
{
var name:String = "testUserName";
roUser.findByUserName(name);
}
private function handleFindUserByName(event:ResultEvent):void
{
event.result as User;
}
private function handleCreateFault(event:FaultEvent):void
{
trace(event.message);
}
]]>
</mx:Script>
<mx:RemoteObject id="roUser" destination="userService" >
<mx:method name="saveUser" result="handleCreate(event)" fault="handleCreateFault(event)" />
<mx:method name="findByUserName" result="handleFindUserByName(event)" fault="handleCreateFault(event)" />
</mx:RemoteObject>
<mx:Button id="btn" label="Create" click="handleClick(event)" />
Any suggestions or sample projects would be appreciated. Thanks