When you use http://<host>:8000/dcn/DCNServlet, the user authentication is done by Unwired Server extracting the user information from the request parameter.
username=<username> password=<password>
Alternatively, you can use HTTP BASIC authentication instead of sending the username and password as part of the URL. To use HTTP BASIC authentication, the URL is http://<hostname>:<port>/dcn/HttpAuthDCNServlet, as this example illustrates:
URL url = new URL("http://<host>:8000/dcn/HttpAuthDCNServlet?cmd=dcn&package=<package_name>:<package_version>");
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.setDoOutput(true);
huc.setRequestMethod("POST");
final String login = "<login_name_of_user_with_DCN_role>";
final String pwd = "<password_of_user_with_DCN_role>";
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(login, pwd.toCharArray());
}
});
String dcnRequest = "{\"pkg\":\"<package_name>:<package_version>"\","
+ "\"messages\":[{\"id\":\"1\",\"mbo\":\"CustomerState\",\"op\":\":upsert\","
+ "\"cols\":{\"id\":\"1020\",\"fname\":\"Paul\",\"city\":\"Rutherford\"}}]}";
StringBuffer sb = new StringBuffer();
sb.append(dcnRequest);
OutputStream os = huc.getOutputStream();
os.write(sb.toString().getBytes());
os.close();
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream()));
System.out.println(huc.getURL());
huc.connect();
String line = br.readLine();
while (line != null)
{
System.out.print(line);
line = br.readLine();
}
You can also use the URL http://<hostname>:8000/dcn/HttpAuthDCNServlet if you do not want to send the DCN request as a request parameter but as an HTTP POST body instead.
If you are using HTTP BASIC authentication, the JSON encoded DCN request is always sent as the HTTP POST body.