

{"exposed":true}{}schema_name = "ShutStorage";namespace shuttler;
@Schema: 'ShutStorage'
context shut {
Entity flagHolder{
key id: Integer;
flag:Integer;
};
};service{
"shuttler::shut.flagHolder" as "flagHolder";
}This XML file does not appear to have any style information associated with it. The document tree is shown below.
<service xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app" xml:base="https://jdatap1942288904trial.hanatrial.ondemand.com:443/shuttler/accessShuttler.xsodata/">
<workspace>
<atom:title>Default</atom:title>
<collection href="flagHolder">
<atom:title>flagHolder</atom:title>
</collection>
</workspace>
</service>

<Button text="Shut Down SYSTEM" id="__button1" press="onShutDownPress"/>onShutDownPress: function () {
//var oModel=this.getView().getModel("sales");
// console.log(oModel);
var oModel = new sap.ui.model.odata.ODataModel("/HANAXS/shuttler/accessShuttler.xsodata");
oModel.setUseBatch(false);
oModel.read("/flagHolder(1)", null, null, true, jQuery.proxy(function(data) {
console.log(data.flag);
if(data.flag=="0")
{
var oEntry = {};
oEntry.flag = "1";
oModel.update('/flagHolder(1)', oEntry, null, function(){
alert("Update successful");
},function(){
alert("Update failed");});
}
else
{
alert("Your system is already shut down");
}
}));
}
import org.apache.commons.codec.binary.Base64;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONArray;
import org.json.JSONObject;
public class ShutProcessor {
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) {
try{
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try{
ShutProcessor sP=new ShutProcessor();
sP.sendGet();
}catch(Exception e){}
}
}, 0, 50000);
//System.out.println("Using proxy: " + host + ":" + port);
//String shutdownCmd = "shutdown -s";
// Process child = Runtime.getRuntime().exec(shutdownCmd);
}
catch(Exception e)
{
System.out.println("error"+e.getLocalizedMessage());
e.printStackTrace();
}
}
private void sendPut(URL obj) throws Exception
{
String url = "https://jdatap1942288904trial.hanatrial.ondemand.com/shuttler/accessShuttler.xsodata/flagHolder(1)";
System.out.println("\nSending 'PUT' request to URL : " + url);
URL obj1 = new URL(url);
String req="<a:entry xmlns:a="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><a:author><a:name/></a:author><a:content type="application/xml"><m:properties><d:flag>0</d:flag></m:properties></a:content></a:entry>";
HttpURLConnection con = setUsernamePassword(obj1);
con.setRequestProperty("Content-Type", "application/atom+xml");
con.setRequestProperty("Content-Length", Integer.toString(req.getBytes().length));
con.setRequestProperty("Accept", "application/atom+xml,application/atomsvc+xml,application/xml");
con.setRequestProperty("Content-Type", "application/atom+xml");
con.setDoOutput(true);
con.setRequestMethod("PUT");
OutputStreamWriter out = new OutputStreamWriter(
con.getOutputStream());
out.write(req);
out.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());
}
private void sendGet() throws Exception {
String url = "https://jdatap1942288904trial.hanatrial.ondemand.com//shuttler/accessShuttler.xsodata/flagHolder(1)/flag?$format=json";
URL obj = new URL(url);
HttpURLConnection con = setUsernamePassword(obj);;
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JSONArray jsonArray = new JSONArray("["+response.toString()+"]");
System.out.println(jsonArray);
JSONObject rec = new JSONObject(response.toString());
String flg = rec.getJSONObject("d").getString("flag");
if(flg.equalsIgnoreCase("1"))
{ this.sendPut(obj);
String shutdownCmd = "shutdown -s";
Process child = Runtime.getRuntime().exec(shutdownCmd);
}
}
private HttpURLConnection setUsernamePassword(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
String authString = "<HANA_Instance_username>" + ":" + "<HANA_Instance_password>";
String authStringEnc = new String(Base64.encodeBase64(authString.getBytes()));
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
return urlConnection;
}
}You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 20 | |
| 19 | |
| 13 | |
| 13 | |
| 12 | |
| 12 | |
| 11 | |
| 10 |