java - Java 中的 AMF 客户端

标签 java blazeds amf

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

我正在尝试使用 BlazeDS 在 java 中获取这些值。 我一直用Charles web proxy进行调试,这是来自 the request 的屏幕截图和 the response :

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

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

谁能发现问题所在吗?

感谢您的阅读!

最佳答案

我最终使用了 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 的评论中提到的内容,看看您是否有权执行此类操作。

关于java - Java 中的 AMF 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1683823/

相关文章:

java - Flex Blaze DS 和 JPA - 延迟加载问题

java - 将文件从闪存传输到 java 时出现未知的 AMF 类型和其他错误

java - 如何使用dom解析器java解析xml中的相同名称标签?

java - 在java中解密在android应用程序中加密的字符串

java - 如何使用 BlazeDS 创建动态目的地

servlets - Grails Servlet 过滤器疯狂 : . ..ServletRequestAttributes 无法转换为 ..GrailsWebRequest

java - 如何获取 flex-messaging-client-android.jar?

java - InplaceSelect 适用于对象而不是字符串

java - jooq 不支持 json 值

java - BlazeDS 和 ColdFusion - jRun 内存使用量增加导致 java.lang.OutOfMemoryError : Java heap space