2009-11-05 92 views
2

我正在使用BlazeDS java clientthis page獲取信息。 這個頁面有一個表格,當你選擇一個類型時,按鈕上的位置組合會被更新。Java中的AMF客戶端

我想用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 

任何人都可以發現有什麼問題嗎?

感謝您的閱讀!

+0

這是客戶端錯誤消息,是嗎?你可以發佈一些有趣的服務器端日誌嗎? – 2009-11-06 11:56:41

+0

我不訪問服務器。網絡不是我的。 – Macarse 2009-11-06 12:13:07

+1

如果您無法訪問服務器,那麼這是否意味着您無權進行此操作? **這個問題現在聞起來就像我的非法逆向工程。**邪惡。 – 2009-11-07 08:15:14

回答

4

我最終使用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具有兩個瓦爾:數據和標籤。 我試圖評論每一行以獲得更好的理解。 考慮到Stu在之前有關crossdomain.xml的評論中提到的內容,看看您是否有權執行此類操作。

+0

@Marcarse - 最近我問了一個問題在http://stackoverflow.com/questions/12552409/how-to-make-a-producer-consumer-java-client-for-blazeds,我想你的答案是接近的到我在java只客戶端的嘗試。基本上我需要一個AcknowledgeMes​​sage來響應CommandMessage ping,但正在接收ASObject。我覺得這需要獲得DSId,這是通過隨後的請求與jessionid發送。是否認爲有可能擁有純java客戶端作爲blazeds? – MikeW 2012-09-24 02:48:44

+0

@MikeW:對不起,但我不知道。我很久以前做了這個:( – Macarse 2012-09-24 13:38:46

+0

@Marcarse不用擔心:) – MikeW 2012-09-25 01:19:13