I am running blazeds on the server side. I would like to filter http requests using an http header. My goal is to send extra parameters to the server without changing the signatures of my blazeds services.
我在服务器端运行blazeds。我想使用http标头过滤http请求。我的目标是在不改变我的blazeds服务签名的情况下向服务器发送额外的参数。
On the client side, I am using Flex RemoteObject methods.
在客户端,我使用Flex RemoteObject方法。
With Flex WebService components, it is possible to set an http header using the property httpHeaders. I have not found anything similar on the RemoteObject class...
使用Flex WebService组件,可以使用属性httpHeaders设置http标头。我没有在RemoteObject类上发现任何类似的东西......
8 个解决方案
#1
2
I couldnt modify http request from flex, instead I can add custom headers to the mx.messaging.messages.IMessage
that RemoteObject
sends to the server and there, extending flex.messaging.services.remoting.adapters.JavaAdapter
(used for accessing Spring beans), it's posible to read the header parameters and put them into the HTTPRequest.
我无法修改flex的http请求,而是可以将自定义标头添加到RemoteObject发送到服务器的mx.messaging.messages.IMessage中,并扩展flex.messaging.services.remoting.adapters.JavaAdapter(用于访问Spring bean) ),读取头参数并将它们放入HTTPRequest是可行的。
In the flex part, I had to extend mx.rpc.AsyncRequest
: declares a new property "header" and overwrites invoke method that checks if there is a not null value for set the msg.headers.
在flex部分中,我不得不扩展mx.rpc.AsyncRequest:声明一个新属性“header”并覆盖invoke方法,该方法检查是否存在用于设置msg.headers的not null值。
and mx.rpc.remoting.mxml.RemoteObject
: the constructor creates a new instance of our custom AsyncRequest and overwrite old AsyncRequest
and it defines a setHeaders
method that set the argument to the custom AsyncRequest
.
和mx.rpc.remoting.mxml.RemoteObject:构造函数创建自定义AsyncRequest的新实例并覆盖旧的AsyncRequest,它定义了一个setHeaders方法,该方法将参数设置为自定义AsyncRequest。
com.asfusion.mate.actions.builders.RemoteObjectInvoker
(extra :P): this one reads the param declared in the Mate's map RemoteObjectInvoker
and puts in the RemoteObject
header.
com.asfusion.mate.actions.builders.RemoteObjectInvoker(extra:P):这个读取在Mate的映射RemoteObjectInvoker中声明的param并放入RemoteObject头。
I hope it will be understandable (with my apache english xDDD)
我希望这是可以理解的(用我的apache英文xDDD)
Bye. Agur!
#2
2
This worked for me using BlazeDS and Spring-Flex 1.5.2
这对我使用BlazeDS和Spring-Flex 1.5.2很有用
Flex:
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 Spring-Flex:
public class FlexJavaCustomAdapter extends JavaAdapter{
@Override
public Object invoke(Message message) {
String locale = (String) message.getHeader("com.foo.locale");
return super.invoke(message);
}
}
dispatcher-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>
#3
1
RemoteObject uses AMF as the data channel, and is managed in a completely different way than HttpService or WebService (which use Http). What you can do, is call setCredentials(username,password)
and then capture this on the server side using the FlexLoginCommand (either the standard one for your container, or derive your own). Lookup setCredentials
and how you should handle this on both sides (client and server).
RemoteObject使用AMF作为数据通道,并以与HttpService或WebService(使用Http)完全不同的方式进行管理。您可以做的是调用setCredentials(用户名,密码),然后使用FlexLoginCommand(您的容器的标准版本或者自己派生)在服务器端捕获它。查找setCredentials以及如何在双方(客户端和服务器)上处理此问题。
#4
1
I have similar problem, and I afraid there is no simple way to set HTTP header when using AMF. But I've designed following solution.
我有类似的问题,我担心在使用AMF时没有简单的方法来设置HTTP头。但我设计了以下解决方案。
Flex uses HTTP to transfer AMF, but invokes it through browser interfaces, this allows you to set cookie. Just in document containing application invoke following JavaScript
Flex使用HTTP传输AMF,但通过浏览器界面调用它,这允许您设置cookie。只是在包含应用程序的文档中调用JavaScript
document.cookie="clientVersion=1.0;expires=2100-01-01;path=/";
Browser should transfer it to server, and you can filter (problem will be if the user will have cookies turned off).
浏览器应该将其传输到服务器,并且您可以过滤(如果用户将关闭cookie,则会出现问题)。
Much more you can invoke JavaScript functions from Flex (more is here: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html).
您可以从Flex调用JavaScript函数(更多信息来自http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html)。
#5
0
You might be trying to re-invent the wheel. Is there a reason you can't use the standard HTTP(s) authentication?
您可能正试图重新发明*。您是否有理由不能使用标准HTTP(s)身份验证?
#6
0
A reason I was thinking too to use http headers was for the server to be able to 'recognize' the flex client in the a context of service versionning. On the server I can always build an indirection/proxy that would allow the different clients to only use 1 end point and route to the right adapter depending on the client version. The question is on the client side. How would the server identify the flex client token or 'version'. One way is certainly via authentication. But, assuming there is not authentication involved?
我也在考虑使用http标头的原因是服务器能够在服务版本控制的上下文中“识别”Flex客户端。在服务器上,我总是可以构建一个间接/代理,允许不同的客户端只使用1个端点并根据客户端版本路由到正确的适配器。问题出在客户端。服务器如何识别Flex客户端令牌或“版本”。一种方法肯定是通过身份验证。但是,假设没有涉及身份验证?
#7
0
We recently run into the same issue and this is how we added our custom headers without creating a subclass:
我们最近遇到了同样的问题,这就是我们在不创建子类的情况下添加自定义标头的方式:
var operation:AbstractOperation = _remoteSession.getOperation('myRemoteOperation');
var async:AsyncRequest = operation.mx_internal::asyncRequest;
async.defaultHeaders = {my_header:'my_value'};
The AsyncRequest object is actually accessible via the operation object via the mx_internal namespace.
AsyncRequest对象实际上可以通过操作对象通过mx_internal命名空间访问。
#8
-1
You can debug the $GLOBALS in PHP to see that. I think this is in the
您可以在PHP中调试$ GLOBALS来查看它。我认为这是在
$GLOBALS['HTTP_RAW_POST_DATA'];
or you can simple do
或者你可以简单地做
file_get_contents('php://input');
#1
2
I couldnt modify http request from flex, instead I can add custom headers to the mx.messaging.messages.IMessage
that RemoteObject
sends to the server and there, extending flex.messaging.services.remoting.adapters.JavaAdapter
(used for accessing Spring beans), it's posible to read the header parameters and put them into the HTTPRequest.
我无法修改flex的http请求,而是可以将自定义标头添加到RemoteObject发送到服务器的mx.messaging.messages.IMessage中,并扩展flex.messaging.services.remoting.adapters.JavaAdapter(用于访问Spring bean) ),读取头参数并将它们放入HTTPRequest是可行的。
In the flex part, I had to extend mx.rpc.AsyncRequest
: declares a new property "header" and overwrites invoke method that checks if there is a not null value for set the msg.headers.
在flex部分中,我不得不扩展mx.rpc.AsyncRequest:声明一个新属性“header”并覆盖invoke方法,该方法检查是否存在用于设置msg.headers的not null值。
and mx.rpc.remoting.mxml.RemoteObject
: the constructor creates a new instance of our custom AsyncRequest and overwrite old AsyncRequest
and it defines a setHeaders
method that set the argument to the custom AsyncRequest
.
和mx.rpc.remoting.mxml.RemoteObject:构造函数创建自定义AsyncRequest的新实例并覆盖旧的AsyncRequest,它定义了一个setHeaders方法,该方法将参数设置为自定义AsyncRequest。
com.asfusion.mate.actions.builders.RemoteObjectInvoker
(extra :P): this one reads the param declared in the Mate's map RemoteObjectInvoker
and puts in the RemoteObject
header.
com.asfusion.mate.actions.builders.RemoteObjectInvoker(extra:P):这个读取在Mate的映射RemoteObjectInvoker中声明的param并放入RemoteObject头。
I hope it will be understandable (with my apache english xDDD)
我希望这是可以理解的(用我的apache英文xDDD)
Bye. Agur!
#2
2
This worked for me using BlazeDS and Spring-Flex 1.5.2
这对我使用BlazeDS和Spring-Flex 1.5.2很有用
Flex:
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 Spring-Flex:
public class FlexJavaCustomAdapter extends JavaAdapter{
@Override
public Object invoke(Message message) {
String locale = (String) message.getHeader("com.foo.locale");
return super.invoke(message);
}
}
dispatcher-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>
#3
1
RemoteObject uses AMF as the data channel, and is managed in a completely different way than HttpService or WebService (which use Http). What you can do, is call setCredentials(username,password)
and then capture this on the server side using the FlexLoginCommand (either the standard one for your container, or derive your own). Lookup setCredentials
and how you should handle this on both sides (client and server).
RemoteObject使用AMF作为数据通道,并以与HttpService或WebService(使用Http)完全不同的方式进行管理。您可以做的是调用setCredentials(用户名,密码),然后使用FlexLoginCommand(您的容器的标准版本或者自己派生)在服务器端捕获它。查找setCredentials以及如何在双方(客户端和服务器)上处理此问题。
#4
1
I have similar problem, and I afraid there is no simple way to set HTTP header when using AMF. But I've designed following solution.
我有类似的问题,我担心在使用AMF时没有简单的方法来设置HTTP头。但我设计了以下解决方案。
Flex uses HTTP to transfer AMF, but invokes it through browser interfaces, this allows you to set cookie. Just in document containing application invoke following JavaScript
Flex使用HTTP传输AMF,但通过浏览器界面调用它,这允许您设置cookie。只是在包含应用程序的文档中调用JavaScript
document.cookie="clientVersion=1.0;expires=2100-01-01;path=/";
Browser should transfer it to server, and you can filter (problem will be if the user will have cookies turned off).
浏览器应该将其传输到服务器,并且您可以过滤(如果用户将关闭cookie,则会出现问题)。
Much more you can invoke JavaScript functions from Flex (more is here: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html).
您可以从Flex调用JavaScript函数(更多信息来自http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html)。
#5
0
You might be trying to re-invent the wheel. Is there a reason you can't use the standard HTTP(s) authentication?
您可能正试图重新发明*。您是否有理由不能使用标准HTTP(s)身份验证?
#6
0
A reason I was thinking too to use http headers was for the server to be able to 'recognize' the flex client in the a context of service versionning. On the server I can always build an indirection/proxy that would allow the different clients to only use 1 end point and route to the right adapter depending on the client version. The question is on the client side. How would the server identify the flex client token or 'version'. One way is certainly via authentication. But, assuming there is not authentication involved?
我也在考虑使用http标头的原因是服务器能够在服务版本控制的上下文中“识别”Flex客户端。在服务器上,我总是可以构建一个间接/代理,允许不同的客户端只使用1个端点并根据客户端版本路由到正确的适配器。问题出在客户端。服务器如何识别Flex客户端令牌或“版本”。一种方法肯定是通过身份验证。但是,假设没有涉及身份验证?
#7
0
We recently run into the same issue and this is how we added our custom headers without creating a subclass:
我们最近遇到了同样的问题,这就是我们在不创建子类的情况下添加自定义标头的方式:
var operation:AbstractOperation = _remoteSession.getOperation('myRemoteOperation');
var async:AsyncRequest = operation.mx_internal::asyncRequest;
async.defaultHeaders = {my_header:'my_value'};
The AsyncRequest object is actually accessible via the operation object via the mx_internal namespace.
AsyncRequest对象实际上可以通过操作对象通过mx_internal命名空间访问。
#8
-1
You can debug the $GLOBALS in PHP to see that. I think this is in the
您可以在PHP中调试$ GLOBALS来查看它。我认为这是在
$GLOBALS['HTTP_RAW_POST_DATA'];
or you can simple do
或者你可以简单地做
file_get_contents('php://input');