Skip to content

Commit 9e80bfd

Browse files
author
Jonathan
committed
Pre final test for REST
1 parent 8894a11 commit 9e80bfd

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

src/ca/concordia/cse/gipsy/ws/rest/MainRestJavaClient.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ca.concordia.cse.gipsy.ws.rest;
22

3-
import ca.concordia.cse.gipsy.ws.rest.GeneratorConfiguration;
43
import java.util.Scanner;
54

65
/**
@@ -57,21 +56,21 @@ public static void main(String[] args) {
5756
private static GeneratorConfiguration getGenConfiguration(Scanner scan) {
5857
GeneratorConfiguration config = new GeneratorConfiguration();
5958

60-
System.out.println("Value for number of concepts:");
59+
System.out.println("Value for number of concepts (integer):");
6160
config.setNumberOfConcepts(scan.nextLine());
6261

63-
System.out.println("Value for number of services:");
62+
System.out.println("Value for number of services (integer):");
6463
config.setNumberOfServices(scan.nextLine());
6564

66-
System.out.println("Value for is solvable:");
65+
System.out.println("Value for is solvable (true or false):");
6766
boolean isSolvable = scan.nextBoolean();
6867

6968
config.setSolvableProblem(isSolvable);
7069

71-
// if (isSolvable) {
72-
// System.out.println("Value for solutions list (separate with ,):");
73-
// config.setSolutionsList(scan.nextLine());
74-
// }
70+
if (isSolvable) {
71+
System.out.println("Value for solutions list (integers separated by ,):");
72+
config.setSolutionsList(scan.nextLine());
73+
}
7574

7675
return config;
7776
}

src/ca/concordia/cse/gipsy/ws/rest/RestGenerator.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import javax.ejb.Stateless;
77
import javax.ws.rs.Consumes;
88
import javax.ws.rs.GET;
9+
import javax.ws.rs.POST;
910
import javax.ws.rs.PUT;
11+
import javax.ws.rs.DELETE;
1012
import javax.ws.rs.Path;
1113
import javax.ws.rs.PathParam;
1214
import javax.ws.rs.Produces;
@@ -42,14 +44,14 @@ public Response generate(String jsonInput) {
4244
try {
4345
GeneratorConfiguration config = ob.readValue(jsonInput, GeneratorConfiguration.class);
4446

45-
//instance.setNumberOfConcepts(config.getNumberOfConcepts());
46-
//instance.setNumberOfServices(config.getNumberOfServices());
47-
//instance.setSolvableProblem(config.isSolvableProblem());
47+
instance.setNumberOfConcepts(config.getNumberOfConcepts());
48+
instance.setNumberOfServices(config.getNumberOfServices());
49+
instance.setSolvableProblem(config.isSolvableProblem());
4850

49-
// if (config.isSolvableProblem()) {
50-
// instance.setSolutionsList(config.getSolutionsList());
51-
// instance.setCompleteSolutionDepth();
52-
// }
51+
if (config.isSolvableProblem()) {
52+
instance.setSolutionsList(config.getSolutionsList());
53+
instance.setCompleteSolutionDepth();
54+
}
5355

5456
instance.start();
5557

@@ -102,9 +104,32 @@ private Response generateGetResponse(String fileName) {
102104
response = Response.ok(toReturn, MediaType.TEXT_PLAIN);
103105
response.header("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
104106
} else {
105-
response = Response.status(Response.Status.BAD_GATEWAY);
107+
response = Response.status(Response.Status.NOT_FOUND);
106108
}
107109

108110
return response.build();
109111
}
112+
113+
/*
114+
For the methods that aren't allowed
115+
*/
116+
@PUT
117+
@POST
118+
@DELETE
119+
@Path("gen/{fileType}")
120+
public Response notImplementedGetFile() {
121+
return Response.status(Response.Status.METHOD_NOT_ALLOWED).build();
122+
}
123+
124+
/*
125+
For the methods that aren't allowed
126+
*/
127+
@GET
128+
@POST
129+
@DELETE
130+
@Path("gen")
131+
public Response notImplementedGenFiles() {
132+
return Response.status(Response.Status.METHOD_NOT_ALLOWED).build();
133+
}
134+
110135
}

src/ca/concordia/cse/gipsy/ws/rest/RestJSClient.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</head>
77
<body>
88
<script type="text/javascript">
9+
const restAPIURL = 'http://localhost:8080/WSC-Gen/resources/restGenerator';
10+
911
function makeRequest(verb, url, body, toCallOnSuccess) {
1012
document.getElementById("error").innerHTML = "";
1113
document.getElementById("status").innerHTML = "";
@@ -52,32 +54,33 @@
5254
solutionsList: solutionsListParsed
5355
};
5456

55-
makeRequest('PUT', 'http://localhost/gen', parameters, function() {
57+
makeRequest('PUT', restAPIURL + '/gen', parameters, function() {
5658
document.getElementById("status").innerHTML = "Successfully sent the generation request to the server.";
59+
document.getElementById("divGetFiles").style.display = 'block';
5760
});
5861
}
5962

6063
function getWSDL() {
61-
makeRequest('GET', undefined, 'http://localhost:8080/WSC-Gen/resources/restGenerator/wsdl', function() {
62-
window.open('http://localhost:8080/WSC-Gen/resources/restGenerator/wsdl', '_blank');
64+
makeRequest('GET', restAPIURL + 'gen/wsdl', undefined, function() {
65+
window.open(restAPIURL + 'gen/wsdl', '_blank');
6366
});
6467
}
6568

6669
function getWSLA() {
67-
makeRequest('GET', undefined, 'http://localhost/wsla', function() {
68-
window.open('http://localhost/wsla', '_blank');
70+
makeRequest('GET', restAPIURL + 'gen/wsla', undefined, function() {
71+
window.open(restAPIURL + 'gen/wsla', '_blank');
6972
});
7073
}
7174

7275
function getOWL() {
73-
makeRequest('GET', undefined, 'http://localhost/owl', function() {
74-
window.open('http://localhost/owl', '_blank');
76+
makeRequest('GET', restAPIURL + 'gen/owl', undefined, function() {
77+
window.open(restAPIURL + 'gen/owl', '_blank');
7578
});
7679
}
7780

7881
function getBPEL() {
79-
makeRequest('GET', undefined, 'http://localhost/bpel', function() {
80-
window.open('http://localhost/bpel', '_blank');
82+
makeRequest('GET', restAPIURL + 'gen/bpel', undefined, function() {
83+
window.open(restAPIURL + 'gen/bpel', '_blank');
8184
});
8285
}
8386

@@ -103,7 +106,7 @@ <h3>Parameters for the Generator</h3>
103106
<input id="isSolvable" type="text" onkeyup="changedValue"/>
104107
<input id="solutionListDepths" style="display: none;" type="text"/>
105108
<button type="button" onclick="generateFiles()">Generate Files</button>
106-
<div>
109+
<div id="divGetFiles" style="display: none;">
107110
<button type="button" onclick="getWSDL()">Download WSDL</button>
108111
<button type="button" onclick="getWSLA()">Download WSLA</button>
109112
<button type="button" onclick="getOWL()">Download OWL</button>

src/ca/concordia/cse/gipsy/ws/rest/RestJavaClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ca.concordia.cse.gipsy.ws.rest;
22

3-
import ca.concordia.cse.gipsy.ws.rest.GeneratorConfiguration;
43
import java.io.File;
54
import java.io.InputStream;
65
import java.nio.file.Files;

0 commit comments

Comments
 (0)