如何使用Flex RemoteObject方法设置HTTP标头?

问题描述:

我在服务器端运行blazeds。我想用http头过滤http请求。我的目标是向服务器发送额外的参数,而不更改我的blazeds服务的签名。如何使用Flex RemoteObject方法设置HTTP标头?

在客户端,我使用Flex RemoteObject方法。

使用Flex WebService组件,可以使用属性httpHeaders来设置http标头。我还没有在RemoteObject类上找到类似的东西...

您可能试图重新发明车轮。有没有理由不能使用标准的HTTP验证?

+0

不,我不能使用HTTP身份验证,我有一个非常特殊的需求。 – 2008-09-17 20:12:29

RemoteObject使用AMF作为数据通道,并以与HttpService或WebService(使用Http)完全不同的方式进行管理。 你可以做的是调用setCredentials(username,password),然后使用FlexLoginCommand(或者是你的容器的标准版本,或者派生自己的版本)在服务器端捕获它。 查找setCredentials以及如何在双方(客户端和服务器)上处理此问题。

+3

RemoteObject调用通过HTTP进行,只是内容以Action Message Format(AMF)编码。 – 2009-03-20 20:37:18

我一直在想使用http头的一个原因是服务器能够在服务版本化环境中“识别”flex客户端。 在服务器上,我始终可以构建一个间接/代理,以允许不同的客户端仅使用1个端点并根据客户端版本路由到正确的适配器。 问题出在客户端。服务器如何识别Flex客户端令牌或'版本'。一种方法当然是通过身份验证。但是,假设没有涉及认证?

我有类似的问题,我怕使用AMF时没有简单的方法来设置HTTP头。但我设计了以下解决方案。

Flex使用HTTP传输AMF,但通过浏览器界面调用它,这允许您设置Cookie。就在包含应用程序调用下面的JavaScript

文件
document.cookie="clientVersion=1.0;expires=2100-01-01;path=/"; 

浏览器应该将其传送到服务器,并可以过滤(问题将是,如果用户将不得不关闭Cookie)。

更多你可以从Flex调用JavaScript函数(更多在这里:http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html)。

我不能从柔性修改HTTP请求,而不是我可以添加自定义页眉到mx.messaging.messages.IMessageRemoteObject发送到服务器,并在那里,延长flex.messaging.services.remoting.adapters.JavaAdapter(用于访问春豆),它是更多钞票来读取头参数,并把它们进入HTTPRequest。

在flex部分中,我不得不扩展mx.rpc.AsyncRequest: 声明了一个新的属性“header”并覆盖了invoke方法,该方法检查是否存在用于设置msg.headers的非空值。

mx.rpc.remoting.mxml.RemoteObject: 的构造函数创建我们的自定义AsyncRequest的一个新实例,并覆盖旧AsyncRequest,它定义了一个setHeaders方法的参数设置为自定义AsyncRequest

com.asfusion.mate.actions.builders.RemoteObjectInvoker(额外的:P): 这一个读取大副地图RemoteObjectInvoker宣布帕拉姆,并在RemoteObject头放。

我希望这将是可以理解的(与我的Apache英语XDDD)

再见。阿古尔!

你可以在PHP中调试$ GLOBALS来查看。 我认为这是在

$GLOBALS['HTTP_RAW_POST_DATA']; 

,或者你可以简单的做

file_get_contents('php://input'); 

最近,我们遇到了同样的问题,这是我们增加了我们的自定义标题,而无需创建一个子类:

var operation:AbstractOperation = _remoteSession.getOperation('myRemoteOperation'); 
var async:AsyncRequest = operation.mx_internal::asyncRequest; 
async.defaultHeaders = {my_header:'my_value'}; 

AsyncRequest对象实际上可以通过操作对象通过mx_internal命名空间访问。

这为我工作用的BlazeDS和Spring-Flex的1.5.2

软硬度:

use namespace mx_internal; 

var service:RemoteObject = new RemoteObject(destination); 
var operation:Operation = service[functionName]; 
operation.asyncRequest.defaultHeaders = {company:'company'}; 

var token:AsyncToken = operation.send(); 

的Java弹簧软硬度:

public class FlexJavaCustomAdapter extends JavaAdapter{ 
    @Override 
    public Object invoke(Message message) { 
     String locale = (String) message.getHeader("com.foo.locale"); 
     return super.invoke(message); 
    } 
} 

调度-servlet.xml中

<bean id="customAdapter" class="org.springframework.flex.core.ManageableComponentFactoryBean"> 
      <constructor-arg value="com.codefish.model.flex.FlexJavaCustomAdapter"/> 
     </bean> 

     <flex:message-broker id="_messageBroker" services-config-path="classpath*:/com/codefish/resources/spring/services-config.xml" > 
       <flex:remoting-service default-adapter-id="customAdapter" 
      default-channels="my-amf, my-secure-amf" /> 
     </flex:message-broker> 
</bean>