【问题标题】:AMF client in JavaJava 中的 AMF 客户端
【发布时间】:2009-11-05 21:38:16
【问题描述】:

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

我正在尝试使用 BlazeDS 在 java 中获取这些值。 我一直在用Charles web proxy调试,这是the requestthe 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

谁能发现问题所在?

感谢阅读!

【问题讨论】:

  • 这是客户端错误消息,是吗?你能从服务器端日志中发布任何有趣的东西吗?
  • 我无法访问服务器。网络不是我的。
  • 如果您无权访问服务器,是否意味着您没有权限进行此操作? 这个问题现在对我来说就像非法逆向工程。邪恶。
  • @Stu:我检查了 robots.txt,我不认为这是不允许的。也许我没有这样做的权限,但我认为复制 AMF 参数就像复制 HTTP POST。 (我删除了我的最后一条评论,因为当我重新阅读它时,它听起来很冒犯。)
  • 检查 ToC。就是这样的东西所在的地方。如果您不确定,请写下它们。并检查crossdomain.xml。你的网站在里面吗?坦率地说,你的比喻 HTTP POST 并不成立。如果用户永远不会到达那里,那么在 orlandoinfo.com 中拥有自己的带有 HTTP POST 的网站是不明智的。它与链接不同。如果您没有查询 API 的权限,那么您基本上是在窃取其他人的内容。如果你的案子是合法的,我会继续提供帮助......但在这一点上听起来真的很狡猾。

标签: java blazeds amf


【解决方案1】:

我最终使用了 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 在之前的 cmets 中提到的关于 crossdomain.xml 的内容,看看你是否有权做这种事情。

【讨论】:

  • @Marcarse - 最近我在 stackoverflow.com/questions/12552409/… 上提出了一个问题,我认为您的回答与我在仅 Java 客户端的尝试很接近。基本上我需要一个 AcknowledgeMes​​sage 来响应 CommandMessage ping 但正在接收 ASObject。我觉得这是获取通过 jessionid 后续请求发送的 DSId 所必需的。是否认为可以为 blazeds 提供纯 Java 客户端?
  • @MikeW:对不起,我不知道。我很久以前就这样做了:(
猜你喜欢
  • 2011-02-21
  • 1970-01-01
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 2017-10-04
  • 2011-10-14
  • 1970-01-01
  • 2019-04-24
相关资源
最近更新 更多