Java 如何使用abdera将状态更新发布到ibm connections?
如何使用abdera将状态更新发布到ibm connections 我正在尝试使用空闲代码将状态发布到ibm连接Java 如何使用abdera将状态更新发布到ibm connections?,java,ibm-connections,apache-abdera,Java,Ibm Connections,Apache Abdera,如何使用abdera将状态更新发布到ibm connections 我正在尝试使用空闲代码将状态发布到ibm连接 public class PostStatusUpdate { public void postStatus(String username, String password, String feedURL) throws MalformedURLException, URISyntaxException { try{ Abdera abdera = new Abd
public class PostStatusUpdate {
public void postStatus(String username, String password, String feedURL) throws MalformedURLException, URISyntaxException {
try{
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
AbderaClient.registerTrustManager();
RequestOptions options = client.getDefaultRequestOptions();
URL url = new URL(feedURL);
String realm = url.getProtocol() + "://" + url.getHost();
client.usePreemptiveAuthentication(true);
try {
client.addCredentials(realm, null, null, new UsernamePasswordCredentials(username, password));
} catch (URISyntaxException e) {
e.printStackTrace();
}
Parser parser = abdera.getParser();
String urlText = "https://greenhouse.lotus.com/connections/opensocial/basic/rest/ublog/@me/@all";
String message = "Hai This is Tes Content Fron Nithin!";
Entry status = abdera.newEntry();
status.addCategory("http://www.ibm.com/xmlns/prod/sn/type", "entry", null);
status.addCategory("http://www.ibm.com/xmlns/prod/sn/message-type", "status", null);
message = StringEscapeUtils.escapeHtml4(message);
status.setContent(message);
ClientResponse response = client.put(urlText, status);
if (response.getType() == ResponseType.SUCCESS) {
System.out.println("I have posted status");
} else {
System.out.println("I failed");
}
}catch(Exception e){
System.out.println("Exception E -->"+e);
}
}
}
请帮忙。我不相信Abdera支持JSON 您可以从cURL中获取示例
curl --request POST -u "userid:password" -H "Content-Type: application/json" -d "{\"content\": \"A new microblog POST\",}" https://<SERVER>/connections/opensocial/basic/rest/ublog/@me/@all
`该微博仅基于json,不基于atom。但是我如何使用此API更新消息?..@paulbastide使用前面评论中链接的REST API您可以提供一个如何使用REST API的示例。我提到的上述代码是否需要对其进行任何修改?这里有一个示例:。PS:该示例使用XML,而不是json。关键是——正如Paul Bastide所说——您需要使用REST API。我尝试执行上述代码,但无法更新状态。代码没有任何错误,但状态没有更新。
url = new URL(apiUrl);
HttpsURLConnection httpCon = (HttpsURLConnection) url
.openConnection();
httpCon.setDoOutput(true);
// Create via POST
String METHOD = "POST";
httpCon.setRequestMethod(METHOD);
String contentType = "application/json";
String auth = //build Basic auth here
httpCon.setRequestProperty("User-Agent", "curl/7.37.1");
httpCon.setRequestProperty("Content-Type", contentType);
httpCon.setRequestProperty("Authorization", auth);
String eventJson = "{\"content\":\"test\"}"; //"{\"content\" : \"A new microblog\" }";
System.out.println("" + eventJson);
DataOutputStream out = new DataOutputStream(
httpCon.getOutputStream());
out.write(eventJson.getBytes());
out.flush();
out.close();
InputStream is = httpCon.getInputStream();
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String response = writer.toString();
System.out.println(response);
System.out.println("The Response Code is "
+ httpCon.getResponseCode());