Skip to content

Commit

Permalink
changed respons mime type to application/ld+json
Browse files Browse the repository at this point in the history
  • Loading branch information
André Antakli committed Aug 8, 2024
1 parent 3a4517e commit 3cda5ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions ajanDemoService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const port = 4203;
const server = http.createServer(app);
let running = null;

let response = "<http://localhost:4203/post> <http://localhost:4203/ajan-demo-ns#message> <http://localhost:4203/ajan-demo-ns#Received> .";
let blocked = "<http://localhost:4203/post> <http://localhost:4203/ajan-demo-ns#message> <http://localhost:4203/ajan-demo-ns#Blocked> .";
let response = [{"@id":"http://localhost:4203/ajan-demo-ns#Received"},{"@id":"http://localhost:4203/post","http://localhost:4203/ajan-demo-ns#message":[{"@id":"http://localhost:4203/ajan-demo-ns#Received"}]}];
let blocked = [{"@id":"http://localhost:4203/ajan-demo-ns#Blocked"},{"@id":"http://localhost:4203/post","http://localhost:4203/ajan-demo-ns#message":[{"@id":"http://localhost:4203/ajan-demo-ns#Blocked"}]}];
const wss = new WebSocket.Server({ server });

app.use(bodyParser.text({ type: 'text/plain', limit: '50mb' }));
Expand All @@ -38,22 +38,22 @@ app.get('/initScene', (req, res) => {
wss.clients.forEach(client => {
client.send('{ "init": "true" }');
});
res.set('Content-Type', 'text/turtle');
res.send("<http://www.ajan.de/ajan-ns#Scene> <http://www.ajan.de/ajan-ns#init> true .");
res.set('Content-Type', 'application/ld+json');
res.send([{"@id":"http://www.ajan.de/ajan-ns#Scene","http://www.ajan.de/ajan-ns#init":[{"@value":true}]}]);
});

app.post('/pickUp', (req, res) => {
console.log(req.body);
let wssMessage = JSON.parse(req.body);
let action = createAction(wssMessage, "pickUp");
action.blockX = getActionSubject(wssMessage, "http://www.ajan.de/ajan-ns#Table");
action.asyncResponse = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \nPREFIX ajan: <http://www.ajan.de/ajan-ns#> \nPREFIX actn: <http://www.ajan.de/actn#> \nPREFIX strips: <http://www.ajan.de/behavior/strips-ns#> \n \n<" + action.blockX + "> strips:is ajan:Holding.";
action.asyncResponse = [{"@id": action.blockX,"http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Holding"}]},{"@id":"http://www.ajan.de/ajan-ns#Holding"}];
action.request = wssMessage;
let actionRequest = JSON.stringify(action);
wss.clients.forEach(client => {
client.send(actionRequest);
});
res.set('Content-Type', 'text/turtle');
res.set('Content-Type', 'application/ld+json');
res.send(response);
});

Expand All @@ -63,13 +63,13 @@ app.post('/stack', (req, res) => {
let action = createAction(wssMessage, "stack");
action.blockX = getActionSubject(wssMessage, "http://www.ajan.de/ajan-ns#Holding");
action.blockY = getActionSubject(wssMessage, "http://www.ajan.de/ajan-ns#Clear");
action.asyncResponse = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \nPREFIX ajan: <http://www.ajan.de/ajan-ns#> \nPREFIX actn: <http://www.ajan.de/actn#> \nPREFIX strips: <http://www.ajan.de/behavior/strips-ns#> \n \najan:Arm strips:is ajan:Empty . <" + action.blockX + "> strips:is ajan:Clear . \n<" + action.blockX + "> ajan:on <" + action.blockY + "> .";
action.asyncResponse = [{"@id":"http://www.ajan.de/ajan-ns#Arm","http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Empty"}]},{"@id": action.blockX,"http://www.ajan.de/ajan-ns#on":[{"@id": action.blockY}]},{"@id": action.blockY},{"@id":"http://www.ajan.de/ajan-ns#Clear"},{"@id":"http://www.ajan.de/ajan-ns#Empty"},{"@id": action.blockX,"http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Clear"}]}];
action.request = wssMessage;
let actionRequest = JSON.stringify(action);
wss.clients.forEach(client => {
client.send(actionRequest);
});
res.set('Content-Type', 'text/turtle');
res.set('Content-Type', 'application/ld+json');
res.send(response);
});

Expand All @@ -79,13 +79,13 @@ app.post('/unStack', (req, res) => {
let action = createAction(wssMessage, "unStack");
action.blockX = getActionSubject(wssMessage, "http://www.ajan.de/ajan-ns#Clear");
action.blockY = getActionObject(wssMessage, "http://www.ajan.de/ajan-ns#on");
action.asyncResponse = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \nPREFIX ajan: <http://www.ajan.de/ajan-ns#> \nPREFIX actn: <http://www.ajan.de/actn#> \nPREFIX strips: <http://www.ajan.de/behavior/strips-ns#> \n \n<" + action.blockX + "> strips:is ajan:Holding . \n<" + action.blockY + "> strips:is ajan:Clear .";
action.asyncResponse = [{"@id": action.blockX,"http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Holding"}]},{"@id": action.blockY,"http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Clear"}]},{"@id":"http://www.ajan.de/ajan-ns#Clear"},{"@id":"http://www.ajan.de/ajan-ns#Holding"}];
action.request = wssMessage;
let actionRequest = JSON.stringify(action);
wss.clients.forEach(client => {
client.send(actionRequest);
});
res.set('Content-Type', 'text/turtle');
res.set('Content-Type', 'application/ld+json');
res.send(response);
});

Expand All @@ -94,13 +94,13 @@ app.post('/putDown', (req, res) => {
let wssMessage = JSON.parse(req.body);
let action = createAction(wssMessage, "putDown");
action.blockX = getActionSubject(wssMessage, "http://www.ajan.de/ajan-ns#Holding");
action.asyncResponse = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \nPREFIX ajan: <http://www.ajan.de/ajan-ns#> \nPREFIX actn: <http://www.ajan.de/actn#> \nPREFIX strips: <http://www.ajan.de/behavior/strips-ns#> \n \najan:Arm strips:is ajan:Empty . \n<" + action.blockX + "> strips:is ajan:Table . \n<" + action.blockX + "> strips:is ajan:Clear .";
action.asyncResponse = [{"@id":"http://www.ajan.de/ajan-ns#Arm","http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Empty"}]},{"@id": action.blockX,"http://www.ajan.de/behavior/strips-ns#is":[{"@id":"http://www.ajan.de/ajan-ns#Table"},{"@id":"http://www.ajan.de/ajan-ns#Clear"}]},{"@id":"http://www.ajan.de/ajan-ns#Clear"},{"@id":"http://www.ajan.de/ajan-ns#Empty"},{"@id":"http://www.ajan.de/ajan-ns#Table"}];
action.request = wssMessage;
let actionRequest = JSON.stringify(action);
wss.clients.forEach(client => {
client.send(actionRequest);
});
res.set('Content-Type', 'text/turtle');
res.set('Content-Type', 'application/ld+json');
res.send(response);
});

Expand Down
8 changes: 4 additions & 4 deletions app/components/services/demo-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function myMessageHandler(event) {
console.log(action.request);
that.set("requestMsg", JSON.stringify(action.request, null, 2));
console.log(action.asyncResponse);
that.set("responseMsg", action.asyncResponse);
that.set("responseMsg", JSON.stringify(action.asyncResponse, null, 2));
console.log(action);
if (action.init) initScene();
else if (action.action == "pickUp") {
Expand Down Expand Up @@ -388,13 +388,13 @@ function setTriplestoreField() {
}

function sendResponse(action) {
console.log(action.asyncResponse);
console.log(JSON.stringify(action.asyncResponse));
console.log(action.requestURI);
return $.ajax({
url: action.requestURI,
type: "POST",
contentType: "text/turtle",
data: action.asyncResponse,
contentType: "application/ld+json",
data: JSON.stringify(action.asyncResponse),
}).catch (function (error) {
console.log(error);
});
Expand Down
4 changes: 2 additions & 2 deletions app/templates/components/services/demo-service.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<div id="demo-service-content">
<div id="requestMsg">
<h6><i class="arrow alternate circle blue down icon"></i>Async Request <span>Content-Type: application/ld+json</span></h6>
<h6><i class="arrow alternate circle blue down icon"></i>Request <span>Content-Type: application/ld+json</span></h6>
<textarea class="demoMsg" rows="31">{{requestMsg}}</textarea>
</div>
<div id="demo-playground">
Expand All @@ -48,7 +48,7 @@
</div>
</div>
<div id="responseMsg">
<h6><i class="arrow alternate circle green up icon"></i>Response <span>Content-Type: text/turtle</span></h6>
<h6><i class="arrow alternate circle green up icon"></i>Response <span>Content-Type: application/ld+json</span></h6>
<textarea class="demoMsg" rows="31">{{responseMsg}}</textarea>
</div>
</div>
Expand Down

0 comments on commit 3cda5ad

Please sign in to comment.