DCN Constructor for SUP 2.1.3

How to create a simple DCN Message in Java.

The following Java Class helps create the DCN Message



import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;

public class DCNConstructor {

/**
 * @param args
 * @throws MalformedURLException
 */
public static void main(String[] args) throws Exception {
URL url = null;

String wfdcn_request = "{\"id\":\"dcntest_69\",\"op\":\":upsert\"," + "\"subject\":\"Server-119,CA\",\"to\":\"supAdmin\"," + "\"from\":\"SUP101\",\"read\":false,\"priority\":true," + "\"body\":\",TaskID:, WIID:000001468382, USER:perf0111#END#\"}";
// String wfdcn_request = "{\"id\":\"dcntest_69\",\"op\":\":upsert\"," + "\"subject\":\"Server-119,CA\",\"to\":\"perf0111\"," + "\"from\":\"SUP101\",\"read\":false,\"priority\":true," + "\"body\":\",TaskID:, WIID:000001468382, USER:perf0111#END#\"}";

// url = new URL("HTTP", "10.42.39.149", 8000, "/dcn/HttpAuthDCNServlet?cmd=wf&security=admin&domain=default"); // replace the IP address with your system host name
url = new URL("HTTP", "Ripper-PC", 8000, "/dcn/HttpAuthDCNServlet?cmd=wf&security=admin&domain=default");

HttpURLConnection con = null;

con = (HttpURLConnection) url.openConnection();

con.setDoOutput(true);
con.setRequestMethod("POST");

final String login = "supAdmin"; 
final String pwd = "yourpassword"; // replace this with the password for your SUP system
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(login, pwd.toCharArray());
}
});

StringBuffer sb = new StringBuffer();
sb.append(wfdcn_request);
OutputStream os = con.getOutputStream();
os.write(sb.toString().getBytes());
os.flush();
os.close();

StringBuffer xmlResponse = new StringBuffer();

int returnCode = con.getResponseCode();
if (returnCode != 200) {
String rspErrorMsg = "Error getting response from the server (error code " + returnCode + ")" + con.getResponseMessage();
System.out.println(rspErrorMsg);

} else {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
xmlResponse.append(line).append("\n");
}
System.out.println("xmlResponse: " + xmlResponse);
}

}
}




Comments

Popular posts from this blog

How to create Component-preload.js files for Fiori Applications

Building Cost Effective Enterprise Mobile Applications

How to create a new user in Open DS LDAP server for Sybase Unwired Platform