Sample Java Function for Generating Workflow DCN

This WF-DCN sample illustrates WF-DCN without payload.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLEncoder;

public class HttpAuth
{
    /**
     * @param args
     * @throws MalformedURLException 
     */
    public static void main(String[] args) throws Exception 
    {
        URL url = null;
		
        String wfdcn_request = "{\"id\":\"dcntest_69\",\"op\":\":upsert\","
            + "\"subject\":\"dept_id = 1300\",\"to\":\"perf0111\","
            + "\"from\":\"SAP Leave WorkFlow\",\"read\":false,\"priority\":true,"
            + "\"body\":\",TaskID:, WIID:000001468382, USER:perf0111#END#\"}";

        url = new URL("HTTP", "10.42.39.149", 8081,
                "/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 = "s3pAdmin";
        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);
        }

    }
}