Back Forum Reply New

Flex BlazeDS Spring Java Hibernate Conf

mons.CommonsMultipartResolverquot;gt;
lt;/beangt;

lt;!-- Dispatches requests mapped to a MessageBroker --gt;
lt;bean class=quot;org..flex.servlet.MessageBrokerHandlerAdapterquot; /gt;

lt;import resource=quot;applicationContext-monitoring.xmlquot; /gt;

lt;import resource=quot;applicationContext-hibernate.xmlquot; /gt;

lt;!-- Généré --gt;
lt;import resource=quot;applicationContext-domains.xmlquot; /gt;

lt;import resource=quot;applicationContext-dao.xmlquot; /gt;

lt;import resource=quot;applicationContext-controllers.xmlquot; /gt;
lt;!-- Fin Généré --gt;

lt;import resource=quot;applicationContext-services.xmlquot; /gt;

lt;/beansgt;
flex-servlet.xml

Code:
lt;beans ...gt;
lt;flex:message-broker services-config-path=quot;/WEB-INF/flex/services-config.xmlquot;gt;
lt;flex:remoting-service default-channels=quot;my-amfquot; /gt;
lt;/flex:message-brokergt;
lt;/beansgt;
and services-config.xml

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;services-configgt;   lt;channelsgt;       lt;channel-definition id=quot;my-amfquot;class=quot;mx.messaging.channels.AMFChannelquot;gt;lt;endpoint     class=quot;flex.messaging.endpoints.AMFEndpointquot;    ucl=quot;{context.root}/messagebroker/amfquot;/gt;       lt;/channel-definitiongt;   lt;/channelsgt;
   lt;securitygt;       lt;login-command class=quot;flex.messaging.security.TomcatLoginCommandquot;server=quot;Tomcatquot;/gt;   lt;/securitygt;   lt;servicesgt;       lt;service id=quot;remoting-servicequot;class=quot;flex.messaging.services.RemotingServicequot;gt;lt;adaptersgt;    lt;adapter-definition id=quot;java-objectquot;        class=quot;flex.messaging.services.remoting.adapters.JavaAdapterquot;        default=quot;truequot;/gt;lt;/adaptersgt;lt;default-channelsgt;    lt;channel ref=quot;my-amfquot;/gt;lt;/default-channelsgt;
lt;destination id=quot;sampleDestinationquot;gt;    lt;propertiesgt;        lt;sourcegt;com.kleegroup.proto.ui.controller.flexsample.FlexSampleControllerImpl
lt;/sourcegt;
lt;scopegt;sessionlt;/scopegt;    lt;/propertiesgt;lt;/destinationgt;       lt;/servicegt;   lt;/servicesgt;
lt;/services-configgt;

The Java controller class is as follows:

Code:
@Controller
@RequestMapping(FlexSampleController.ADDRESS)
public class FlexSampleControllerImpl extends AbstractController implements FlexSampleController {

@RequestMapping(method = RequestMethod.GET)
@ModelAttribute(AbstractFlexSampleModel.MODEL_NAME)
public ModelAndView initModelAndView() {
final FlexSampleModel model = new FlexSampleModel();
return forward(DEFAULT_VIEW, model);
}

@Inject
private LigneService ligneService; lt;- this is the service i need to use which is null when called by Flex

public final Collectionlt;LigneBusgt; getLigneBusList() {
final Collectionlt;LigneBusgt; result = ligneService.getLigneBusList();
return result;
}
}
The @Inject annotation on the LigneService enables it to be instantiated by Spring automatically.  This is what is lost in the remoting call.

Thanks in advance for your insight
Best regards
Pier

I see a number of different mistakes in your configuration:

1) You do not need to explicitly define a MessageBrokerHandlerAdapter bean.  Using the lt;flex:message-brokergt; tag handles that.

2) When using Spring BlazeDS, you should not need the lt;securitygt; section, nor the lt;servicesgt; section in services-config.xml.  The explicit definition of the Controller as a RemotingDestination using the non-Spring BlazeDS configuration is the thing that is causing the Controller to be instantiated outside of Spring's control.  You should be using either Spring's @RemotingDestination, or lt;flex:remoting-destinationgt;.

3) Unless you're trying to use the new RESTful AMF support in 1.5.0.M2 (which is not the common case, and I see no sign of it in your configuration), it really doesn't make sense to be calling @Controller classes from Flex.  You would typically call your service class directly instead.

I would recommend starting here to get an understanding of how Spring BlazeDS works:
2009/06...ntegration-10/

There are several other good learning resources in the quot;Articles and Tutorialsquot; section of spring-flex

Thank you Jeremy for your very quick response.  i've already made some changes per your recommendations.

Originally Posted by jeremyg4842) When using Spring BlazeDS, you should not need the lt;securitygt; section, nor the lt;servicesgt; section in services-config.xml.  The explicit definition of the Controller as a RemotingDestination using the non-Spring BlazeDS configuration is the thing that is causing the Controller to be instantiated outside of Spring's control.  You should be using either Spring's @RemotingDestination, or lt;flex:remoting-destinationgt;.

i was able to get it to work with the @RemotingDestination annotation, but not with the xml configuration.
Originally Posted by jeremyg4843) Unless you're trying to use the new RESTful AMF support in 1.5.0.M2 (which is not the common case, and I see no sign of it in your configuration), it really doesn't make sense to be calling @Controller classes from Flex.  You would typically call your service class directly instead.

I have removed the @Controller annotation actually but am still calling this class from Flex as we tend to prefer having a first layer on top of the service class to manage business rules and whatnot.

Thank you very much again for your help

forgot to ask an other question, this time on the Flex side.
I've defined my remote object as such:

Code:
var channels:ChannelSet = new ChannelSet();
var simpleChannel:Channel = new AMFChannel(quot;my-amfquot;, quot;flexsample/messagebroker/amfquot;);
channels.addChannel(simpleChannel);

ro = new RemoteObject(quot;flexSampleServicequot;);
ro.channelSet = channels;
is there a way to not have the channel definition hardcoded?  this is important as the application will be used on several different platforms.

is there a way to not have the channel definition hardcoded?Code:
var simpleChannel:Channel = ServerConfig.getChannel(quot;amfChannelquot;);thanx.
unfortunately when i do this, it tells me
'Channel 'amfChannel' does not exist in the configuration.'

when i look up serverConfigData and the xml,
Code:
var serverConfigData:XML = ServerConfig.serverConfigData;
var xml:XML = ServerConfig.xml;
i get null for the former and lt;services/gt; for the latter

so i'm guessing it's not able to retrieve the configuration correctly?

unfortunately when i do this, it tells me
'Channel 'amfChannel' does not exist in the configuration.'

You have quot;amfChannelquot; defined in services-config.xml file right?Code:

lt;channel-definition id=quot;amfChannelquot; class=quot;mx.messaging.channels.AMFChannelquot;gt;
lt;endpoint ucl=quot;flexsample/messagebroker/amfquot; class=quot;flex.messaging.endpoints.AMFEndpointquot; /gt;
lt;/channel-definitiongt;IIRC, you have to actually compile against services-config.xml in order for ServerConfig.getChannel to work, don't you?  Meaning you would have to recompile the .swf anytime you want to change the AMF channel config.  This is why I generally recommend externalizing the configuration using Spring ActionScript (or any of the other Flex DI options).  

There is a nice example of this that someone wrote up here not too long ago that might be helpful:
showthread.php?t=95754

@amiladomingo yes
i've actually been using the id quot;my-amfquot; in reality, as per the config in services-config.xml in the original post.  don't know why i put amfChannel in the Flex code.
Regardless, it's quot;my-amfquot; in the definition on the server side and in the call on the flex side

FYI, forgot to mention i'm working with Flex 3, not 4.  in case that might have any impact

Thanks Jeremy, gonna check that out.
¥
Back Forum Reply New