Witam,
próbuje zintegrować JSF z Flexem. Niestety z marnym skutkiem. Albo czegoś nie rozumiem albo źle się za to zabieram.
Stworzyłem sobie prostą aplikacje www, dodałem biblioteki flexa oraz frameworka JSF. Web xml:

<?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">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    
    <listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>

    <!-- 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>
    
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>
 

Następnie utworzyłem prosty kontroler:

public class UsersControler implements Serializable{
    public UsersControler(){
        users.add("user1");
        users.add("user2");
        users.add("user2");
    }
    private List<String> users = new ArrayList<String>();
    public List getUsers() {
        return users;
    }
    public String getName(){
        return users.get(0);
    }
}

Dla którego stworzyłem beana w faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
    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-facesconfig_2_0.xsd">
        <managed-bean>
            <managed-bean-name>usersService</managed-bean-name>
            <managed-bean-class>controlers.UsersControler</managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
        </managed-bean>
</faces-config>

Dla takiej konfiguracji strona w JSF wyświetla mi się bez problemu(widzę user1, user2, user3). Jeśli chodzi o flexa to zrobiłem wg tego: http://stackoverflow.com/questions/2361546/accessing-jsf-bean-from-blazeds-client małą "fabryczkę":

public class BeanFactory implements FlexFactory {

private static final String SOURCE = "source";

public void initialize(String id, ConfigMap configMap) {}

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
    BeanFactoryInstance instance = new BeanFactoryInstance(this, id, properties);
    instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
    System.out.println(instance.toString());
    return instance;
}

public Object lookup(FactoryInstance inst) {
    BeanFactoryInstance factoryInstance = (BeanFactoryInstance) inst;
    return factoryInstance.lookup();
} 

static class BeanFactoryInstance extends FactoryInstance {
    BeanFactoryInstance(BeanFactory factory, String id, ConfigMap properties) {
        super(factory, id, properties);
    }

        @Override
    public String toString() {
        return "BeanFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
    }

        @Override
    public Object lookup() {
        HttpServletRequest hsr = FlexContext.getHttpRequest();
        String beanName = getSource();

        try
        {
            Object o = hsr.getSession().getAttribute(beanName);
            return o;
        }
        catch (Exception e)
        {
            ServiceException se = new ServiceException();
            String msg = "Java Bean '" + beanName + "' does not exist.";
            se.setMessage(msg);
            se.setRootCause(e);
            se.setDetails(msg);
            se.setCode("Server.Processing");
            throw se;
        }
    }
}}

Następnie skonfigurowałem remoting-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
    class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

 <!--   <destination id="usersService">
        <properties>
            <source>controlers.UsersControler</source>
            <scope>application</scope>
        </properties>
    </destination> -->
    
<destination id="usersService">
        <properties>
            <factory>beanFactory</factory>
            <source>usersService</source>
            <scope>session</scope>
        </properties>
 </destination>
  </service>

Oraz services-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
    <services>
        
        <service-include file-path="remoting-config.xml" />
        <service-include file-path="proxy-config.xml" />
        <service-include file-path="messaging-config.xml" />

    	<!-- 
    	Application level default channels. Application level default channels are 
    	necessary when a dynamic destination is being used by a service component
    	and no ChannelSet has been defined for the service component. In that case,
    	application level default channels will be used to contact the destination.
        -->   
        <default-channels>
           <channel ref="my-amf"/>
        </default-channels>
    
	</services>


    <security>
        <security-constraint id="sample-users">
            <auth-method>Custom</auth-method>
            <roles>
                <role>sampleusers</role>
            </roles>
        </security-constraint>

		<login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>        
        <!-- Uncomment the correct app server
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
        <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
        <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>        
        -->
    </security>

    <channels>
    
        <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
        </channel-definition>
    
        <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>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
            	<add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>

        <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
        </channel-definition>

        <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
            <properties>
            	<add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="per-client-qos-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/qosamfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-millis>500</polling-interval-millis>
            </properties>
        </channel-definition>

    </channels>

    <logging>
        <!-- You may also use flex.messaging.log.ServletLogTarget -->
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>true</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>

    <system>
        <redeploy>
            <enabled>true</enabled>
            <watch-interval>20</watch-interval>
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>            
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
        </redeploy>
    </system>
    
    <factories>
        <factory id="beanFactory" class="factories.BeanFactory"/>
    </factories>

</services-config>

Pliki proxy-config.xml oraz messaging-config.xml zostawilem bez zmian tak jak były w samplach blazeDS. Podczas uruchomienia tomcata dosstaje informację:

2011-07-03 10:13:05 org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-1.6.0.25/jre/lib/amd64/server:/usr/lib/jvm/java-6-sun-1.6.0.25/jre/lib/amd64:/usr/lib/jvm/java-6-sun-1.6.0.25/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2011-07-03 10:13:05 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8400
2011-07-03 10:13:05 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1504 ms
2011-07-03 10:13:05 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
2011-07-03 10:13:05 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
2011-07-03 10:13:08 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.0.4 (FCS b09) for context '/WebApplication1'
2011-07-03 10:13:10 com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring jndi:/localhost/WebApplication1/WEB-INF/faces-config.xml for modifications
BeanFactory instance for id=usersService source=usersService scope=request
2011-07-03 10:13:14 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8400
2011-07-03 10:13:14 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
2011-07-03 10:13:14 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/90  config=null
2011-07-03 10:13:14 org.apache.catalina.startup.Catalina start
INFO: Server startup in 9292 ms
2011-07-03 10:13:17 org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started
2011-07-03 10:13:19 com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.0.4 (FCS b09) for context '/WebApplication1'
2011-07-03 10:13:20 com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring jndi:/localhost/WebApplication1/WEB-INF/faces-config.xml for modifications
BeanFactory instance for id=usersService source=usersService scope=request

Chodzi mi o ostatnią linijkę tak jak by instancja fabryki się tworzyła ale zasięg request ? Tego nie rozumiem skoro wszędzie mam session. Chyba, że to dotyczy właśnie tej fabryki nie wiem ...
Podczas uruchomienia samej aplikacji w przeglądarce dostaję komunikat:

[MessagingError message='Destination 'usersService' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']
Couldn't establish a connection to 'usersService'

Jeśli chodzi a aplikację flexa:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   xmlns:valueObjects="valueObjects.*"
			   width="700" height="700" initialize="init()">
	<fx:Script>
		<![CDATA[

                        import flash.utils.describeType;
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

protected function user_faultHandler(event:FaultEvent):void
{
   Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail,"Error");
}

protected function init():void
{
   getUsersResult.token = usersService.getUsers();
}
protected function getUsersResult_resultHandler(event:ResultEvent):void
{		
  users=event.result as ArrayCollection;
}
		]]>
	</fx:Script>

<fx:Declarations>
   <s:RemoteObject id="usersService" destination="usersService" 
        showBusyCursor="true" fault="user_faultHandler(event)"/>
   <s:CallResponder id="getUsersResult" result="getUsersResult_resultHandler(event)"/>
    <s:ArrayCollection id="users"/>
</fx:Declarations>
			<s:Label id="emailLabel" text="{users}"/>
</s:Application> 

I niestety to nie działa. Prosił bym o jakąś podpowiedź albo nakierowanie na właściwy trop. Z góry dziękuje.