How to set HTTP header when using Flex RemoteObject method?

I am running server side blazeds. I would like to filter http requests using the http header. My goal is to send additional parameters to the server without changing the signatures of my blazeds services.

On the client side, I use Flex RemoteObject methods.

With Flex WebService components, you can set an HTTP header using the httpHeaders property. I did not find anything like this in the RemoteObject class ...

+4
source share
8 answers

I could not change the HTTP request from flex, instead I can add my own headers in mx.messaging.messages.IMessage , which RemoteObject sends to the server, and there, expanding flex.messaging.services.remoting.adapters.JavaAdapter (used for access to Spring beans), he can read the header parameters and put them in HTTPRequest.

In the flexible part, I had to stretch mx.rpc.AsyncRequest : declares a new “title” to the property and overwrites the invoke method, which checks to see if a non-zero value exists for installing msg.headers.

and mx.rpc.remoting.mxml.RemoteObject : the constructor creates a new instance of our custom AsyncRequest and overwrites the old AsyncRequest and defines the setHeaders method, which sets the argument to the custom AsyncRequest .

com.asfusion.mate.actions.builders.RemoteObjectInvoker (optional: P): This reads the parameter declared in the Mate map RemoteObjectInvoker and places it in the RemoteObject header.

Hope this makes sense (with my apache english xDDD)

Bye Agur!

+2
source

This worked for me using BlazeDS and 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> 
+2
source

RemoteObject uses AMF as a 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 it on the server side using FlexLoginCommand (either standard for your container, or get your own). Lookup setCredentials and how you should handle this on both sides (client and server).

+1
source

I have a similar problem and I'm afraid that there is no easy way to set the HTTP header when using AMF. But I developed the following solution.

Flex uses HTTP to send AMF, but calls it through the browser interfaces, this allows you to set a cookie. Only in the document containing the application the following JavaScript is called

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

The browser should transfer it to the server, and you can filter it (the problem will be if the user turns off cookies).

You can call JavaScript functions from Flex much more (more here: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html ).

+1
source

You may be trying to reinvent the wheel. Is there a reason why you cannot use standard HTTP authentication?

0
source

The reason I also thought about using HTTP headers was because the server could “recognize” the flex client in the context of updating the service. On the server, I can always create a link / proxy that will allow different clients to use only one endpoint and the route to the correct adapter, depending on the version of the client. The question is on the client side. How the server identifies a flexible client token or "version." One way is, of course, authentication. But assuming no authentication is used?

0
source

We recently encountered the same problem, and 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 through the operation object through the mx_internal namespace.

0
source

You can debug $ GLOBALS in PHP to see this. I think it's in

 $GLOBALS['HTTP_RAW_POST_DATA']; 

or you can just do

 file_get_contents('php://input'); 
-1
source

Source: https://habr.com/ru/post/1276802/


All Articles