2013-03-20 73 views
1

- 嗨大家Sugarcrm - 通過REST無效的會話ID - 帖子太大?

我有一個奇怪的行爲與sugarcrm。 這裏我使用設置與REST的新條目代碼:

public SugarApi(String sugarUrl){ 
    REST_ENDPOINT = sugarUrl + "/service/v4/rest.php"; 
    json = new GsonBuilder().create(); 
    codec = new URLCodec(); 
    } 

SetEntryRequest req = new SetEntryRequest(sessionId, nameValueListSetEntry, myKind.getModuleName()); 
    String response = null; 
    try { 
     response = postToSugar(REST_ENDPOINT+"?method=set_entry&response_type=JSON&input_type=JSON&rest_data="+codec.encode(json.toJson(req))); 
    } catch (RemoteException e) { 
     System.out.println("Set entry failed. Message: " + e.getMessage()); 
     e.printStackTrace(); 
    } catch (EncoderException e) { 
     e.printStackTrace(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

其中postToSugar是:

public String postToSugar(String urlStr) throws Exception { 

URL url = new URL(urlStr); 
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
conn.setRequestMethod("POST"); 
conn.setDoOutput(true); 
conn.setDoInput(true); 
conn.setUseCaches(false); 
conn.setAllowUserInteraction(false); 
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 

if (conn.getResponseCode() != 200) { 
throw new IOException(conn.getResponseMessage()); 
} 

// Buffer the result into a string 
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
StringBuilder sb = new StringBuilder(); 
String line; 
while ((line = rd.readLine()) != null) { 
    sb.append(line); 
} 
rd.close(); 

conn.disconnect(); 
if(System.getenv("sugardebug") != null){ 
    System.out.println(sb.toString()); 
} 
return sb.toString(); 

} 

所以這個代碼工作正常時,後是小。 最大尺寸是:

{"id":"8c8801c5-ce3b-093c-ee77-514985c19fe1","entry_list":{"account_id":{"name":"account_id","value":"9b37913b-994b-9bc9-4fbf-500e771d845b"},"status":{"name":"status","value":"New"}, 
"description":{"name":"description","value":"Ceci est un test \/ TICKET A SUPPRIMER"},"priority":{"name":"priority","value":"P1"}, 
"name":{"name":"name","value":"test longueur post --------------"},"caseorigin_c":{"name":"caseorigin_c","value":"OnLineForm"},"case_chechindate_c":{"name":"case_chechindate_c","value":"2013-01-12"},"type":{"name":"type","value":"ErrorOnCancel"}}} 

但如果後期較長,服務器返回:

{"name":"Invalid Session ID","number":11,"description":"The session ID is invalid"} 

任何幫助,將不勝感激

+0

看起來您的會話在請求完成之前超時。 – Perception 2013-03-20 11:13:41

+0

我不這麼認爲,因爲如果我只在我的例子中添加一個字符到字段「description」或「name」(見上),我會得到這個錯誤。 (每次) – 2013-03-20 11:24:14

+0

那很不尋常。如果您有權訪問服務器端,請檢查日誌以查看錯誤輸出的請求的轉儲情況。 – Perception 2013-03-20 11:29:21

回答

0

我遇到了這個問題,要求我描述字段有新行字符的地方。我甚至urlencoded換行符,它仍然給我錯誤。據推測,Sugar的服務器上的apache在新行中破壞了請求,這意味着沒有找到sessionID。

我的解決方案是用%5Cn替換%0A%0D的所有發生。

%0A%0D是不同的換行字符和%5Cn變得\n這是在糖換行符。

我沒有其他API的無效字符的廣泛列表。