4

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.

On the client side, I am using Flex RemoteObject methods.

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...

bignose
  • 24,957
  • 12
  • 70
  • 100
Alexandre Victoor
  • 2,857
  • 2
  • 25
  • 27

8 Answers8

3

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>
Ronny Shibley
  • 1,622
  • 18
  • 23
3

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.

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.

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.

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.

I hope it will be understandable (with my apache english xDDD)

Bye. Agur!

hongo
  • 31
  • 2
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).

Verdant
  • 393
  • 2
  • 5
  • 7
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.

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

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).

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).

sth
  • 200,334
  • 49
  • 262
  • 354
Radek
  • 45
  • 1
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.

yiotix
  • 31
  • 4
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?

0

You might be trying to re-invent the wheel. Is there a reason you can't use the standard HTTP(s) authentication?

-1

You can debug the $GLOBALS in PHP to see that. I think this is in the

$GLOBALS['HTTP_RAW_POST_DATA'];

or you can simple do

file_get_contents('php://input');
Marcelo Rodovalho
  • 809
  • 15
  • 24