curl -v -S -u devuser:devuser123 -F 'notification={"applicationId":"3","schemaId":"65536","topcId":"1","type":"USER"};type=application/json' -F file=@notification.json "http://192.168.1.102:8080/kaaAdmin/rest/api/sendNotification"
{
"id" : "597369b2ef540e0716903660",
"applicationId" : "3",
"schemaId" : "65536",
"topicId" : "1",
"nfVersion" : 3,
"lastTimeModify" : 1500735922556,
"type" : "USER",
"body" : "GEhlbGxvIHdvcmxkIQ==",
"expiredAt" : 1501340722555,
"secNum" : 5
* Curl_http_done: called premature == 0
private void sendPost() throws Exception {
url = "http://192.168.1.102:8080/kaaAdmin/rest/api/sendNotification";
String boundary = "*****" + System.currentTimeMillis() + "********";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Connection", "Keep-Alive");
//con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes())));
con.setDoOutput(true);
con.setDoInput(true);
File uploadFile = new File("/Users/castle/Downloads/notification.json");
DataOutputStream outputStream = new DataOutputStream(con.getOutputStream());
FileInputStream inputStream = new FileInputStream(uploadFile);
byte[] buffer = new byte[4096];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.write("notification={\"applicationId\":\"3\",\"schemaId\":\"65536\",\"topicId\":\"1\",\"type\":\"USER\"};type=application/json;charse=UTF-8".getBytes());
outputStream.flush();
inputStream.close();
outputStream.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
I changed a notification like 'JSONObject jsonObject = new JSONObject(new DTO(appID,schemaId,topicId,type));' or 'con.setRequestProperty("norification","param")', but is doesn't work.
The error message is :
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 415 for URL: http://192.168.1.102:8080/kaaAdmin/rest/api/sendNotification
I don't have a clue how to use a Java code to send a notification, please help me, Thank you!