Java 中的 AMF 客户端

发布于 2024-08-09 16:37:13 字数 1910 浏览 2 评论 0原文

我正在使用 BlazeDS java 客户端此页面。 此页面中间有一个表单,当您选择类型时,按钮上的位置组合会更新。

我正在尝试使用 BlazeDS 在 java 中获取这些值。 我一直在使用 Charles Web proxy 进行调试,这是来自 请求响应

到目前为止,我的代码如下:

        // Create the AMF connection.
        AMFConnection amfConnection = new AMFConnection();

        // Connect to the remote url.
        String url = "http://orlandoinfo.com/flex2gateway/";
        try
        {
            amfConnection.connect(url);
        }
        catch (ClientStatusException cse)
        {
            System.out.println(cse);
            return;
        }

        // Make a remoting call and retrieve the result.
        try
        {
//          amfConnection.registerAlias("flex.messaging.io.ArrayCollection", "flex.messaging.io.ArrayCollection");
            amfConnection.call("ColdFusion.getLocations", new Object[] {"consumer", "attractions", "ATTR"});

        }

        catch (ClientStatusException cse)
        {
            System.out.println(cse);
        }
        catch (ServerStatusException sse)
        {
            System.out.println(sse);
        }

        // Close the connection.
        amfConnection.close();

当我运行它时,我得到一个:

ServerStatusException 
    data: ASObject(15401342){message=Unable to find source to invoke, rootCause=null, details=null, code=Server.Processing}
    HttpResponseInfo: HttpResponseInfo 
    code: 200
    message: OK

任何人都可以发现问题所在吗?

感谢您的阅读!

I am using BlazeDS java client to get info from this page.
This page has a form in the middle that when you select a type, the location combo on the button gets updated.

I am trying to use BlazeDS to get those values in java.
I have been using Charles web proxy to debug, and this are the screenshots from the request and the response:

My code so far is the following:

        // Create the AMF connection.
        AMFConnection amfConnection = new AMFConnection();

        // Connect to the remote url.
        String url = "http://orlandoinfo.com/flex2gateway/";
        try
        {
            amfConnection.connect(url);
        }
        catch (ClientStatusException cse)
        {
            System.out.println(cse);
            return;
        }

        // Make a remoting call and retrieve the result.
        try
        {
//          amfConnection.registerAlias("flex.messaging.io.ArrayCollection", "flex.messaging.io.ArrayCollection");
            amfConnection.call("ColdFusion.getLocations", new Object[] {"consumer", "attractions", "ATTR"});

        }

        catch (ClientStatusException cse)
        {
            System.out.println(cse);
        }
        catch (ServerStatusException sse)
        {
            System.out.println(sse);
        }

        // Close the connection.
        amfConnection.close();

When I run it I get a:

ServerStatusException 
    data: ASObject(15401342){message=Unable to find source to invoke, rootCause=null, details=null, code=Server.Processing}
    HttpResponseInfo: HttpResponseInfo 
    code: 200
    message: OK

Can anyone spot what's wrong?

Thanks for reading!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝對不後悔。 2024-08-16 16:37:13

我最终使用了 Charles Web Proxy。嗅探 AMF 参数并使用 -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888 运行我的代码,

我比较这两个调用并进行修改以使其看起来相似。
工作代码如下所示:

String url = "http://www.theGateWayurl.com";
// Generates the connection to the amf gateway.
AMFConnection amfConnection = new AMFConnection();

// Must register the class that this library will use to load the
// AMF object information.
// The library will read AMF object variables and use setters from
// the java bean stated in this line.
AMFConnection.registerAlias("", new LabelData().getClass().getName());

try {
    // Do the connection.
    amfConnection.connect(url);

    // This page requires a certain headers to function.
    // The Content-type is used to sniff with Charles Web Proxy.
    amfConnection.addHttpRequestHeader("Content-type", "application/x-amf");
    // The Referer is used by the webpage to allow gathering information.
    amfConnection.addHttpRequestHeader("Referer", "http://orlandoinfo.com/ws/b2c/sitesearch/customtags/comSearch.swf");

    // The rest of the HTTP POST sent by this library is wrapped
    // inside a RemotingMessage.
    // Prepare the msg to send.
    RemotingMessage msg = new RemotingMessage();

    // The method called in the server.
    msg.setOperation("getLocations");

    // Where the request came from. Similar to referer.
    msg.setSource("ws.b2c.sitesearch.components.myService");

    // The destination is a needed parameter.
    msg.setDestination("ColdFusion");

    // Create the body with the parameters needed to call the
    // operation set with setOperation()
    msg.setBody(new Object[] {"consumer", "attractions"});

    // This is needed but not used.
    msg.setMessageId("xxxxxxxxxx");

    // Send the msg.
    AcknowledgeMessage reply = (AcknowledgeMessage) amfConnection.call("null", msg);

    // Parse the reply from the server.
    ArrayCollection body = (ArrayCollection) reply.getBody();
    for (Object obj : body) {
        LabelData location = (LabelData) obj;
        // Do something with the info.
    }

} catch (ClientStatusException cse) {
    // Do something with the exception.

} catch (ServerStatusException sse) {
    // Do something with the exception.
} finally {
    amfConnection.close();
}

LabelData 只是一个带有两个变量的 java bean:Data 和 Label。
我尝试对每一行进行注释以便更好地理解。
考虑一下 Stu 在之前关于 crossdomain.xml 的评论中提到的内容,看看您是否有权执行此类操作。

I ended up using Charles Web Proxy. Sniffing AMF parameters and running my code with -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888

I compare both calls and modify to look alike.
The working code looks like this:

String url = "http://www.theGateWayurl.com";
// Generates the connection to the amf gateway.
AMFConnection amfConnection = new AMFConnection();

// Must register the class that this library will use to load the
// AMF object information.
// The library will read AMF object variables and use setters from
// the java bean stated in this line.
AMFConnection.registerAlias("", new LabelData().getClass().getName());

try {
    // Do the connection.
    amfConnection.connect(url);

    // This page requires a certain headers to function.
    // The Content-type is used to sniff with Charles Web Proxy.
    amfConnection.addHttpRequestHeader("Content-type", "application/x-amf");
    // The Referer is used by the webpage to allow gathering information.
    amfConnection.addHttpRequestHeader("Referer", "http://orlandoinfo.com/ws/b2c/sitesearch/customtags/comSearch.swf");

    // The rest of the HTTP POST sent by this library is wrapped
    // inside a RemotingMessage.
    // Prepare the msg to send.
    RemotingMessage msg = new RemotingMessage();

    // The method called in the server.
    msg.setOperation("getLocations");

    // Where the request came from. Similar to referer.
    msg.setSource("ws.b2c.sitesearch.components.myService");

    // The destination is a needed parameter.
    msg.setDestination("ColdFusion");

    // Create the body with the parameters needed to call the
    // operation set with setOperation()
    msg.setBody(new Object[] {"consumer", "attractions"});

    // This is needed but not used.
    msg.setMessageId("xxxxxxxxxx");

    // Send the msg.
    AcknowledgeMessage reply = (AcknowledgeMessage) amfConnection.call("null", msg);

    // Parse the reply from the server.
    ArrayCollection body = (ArrayCollection) reply.getBody();
    for (Object obj : body) {
        LabelData location = (LabelData) obj;
        // Do something with the info.
    }

} catch (ClientStatusException cse) {
    // Do something with the exception.

} catch (ServerStatusException sse) {
    // Do something with the exception.
} finally {
    amfConnection.close();
}

The LabelData is just a java bean with with two vars: Data and Label.
I tried to comment every line for a better understanding.
Take into account what Stu mention in previous comments about crossdomain.xml to see if you have the rights to do this kind of things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文