Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM2 - REST service - second PR #9

Open
wants to merge 8 commits into
base: WS
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions README_webServices.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
2018 - Webservices application made by Jonathan Desormais @jdesorm1, Marie Gobran @mariegobran and Martine Chapuis @mchapuis

--------------------------------------------------------
HOW TO OPEN/USE THE PROJECT IN OPENESB
-------------------------------------------------------
--------------------------------------------------------

notes:
1-libraries needed for this project is under src/lib ( manually add dom4j-1.6.1.jar and jdom.jar )
2-Files created are located in ca/concordia/cse/gipsy/ws/soap for SOAP service and ca/concordia/cse/gipsy/ws/rest for REST service

--------------------------------------------------------
SOAP service
--------------------------------------------------------
1- Run Main.java in ca.concordia.cse.gipsy.ws.soap
2- Enter a number to run the service
3- Once the files are created server side, enter the command getFileGenerated to retreive them
4- GeneratorWS.java is the generator wrapper based on the GeneratorGUI.java in de.vs.unikassel.generator.gui

--------------------------------------------------------
REST service
--------------------------------------------------------

In ca.concordia.cse.gipsy.ws.rest:

1- RestGenerator.java is the generator wrapper based on the GeneratorGUI.java in de.vs.unikassel.generator.gui
2- All files are created at the same time using different threads
3- Using RestJSClient.html in `Web Pages` folder, the client can request files in the browser


1-Run Main.java in ca.concordia.cse.gipsy.ws.soap
2-Enter a number to run the service
3-Once the files are created server side, enter the command getFileGenerated to retreive them
------- HOW TO: Javascript REST Client for WS-Gen ------

1- Client can click `Generate Files` without entering any inputs
2- The files takes a moment to be generated
3- Once the files are generated, buttons will appear.
4- The client can click each `Download` buttons to get the files independantly from the server

Note:
Libraries needed for this project is under src/lib
130 changes: 130 additions & 0 deletions WebContent/RestJSClient.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html>
<head>
<title>Rest Client for WS-Gen</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
const restAPIURL = 'http://localhost:8080/WSC-Gen/resources/restGenerator';

function makeRequest(verb, url, body, toCallOnSuccess) {
document.getElementById("error").innerHTML = "";
document.getElementById("status").innerHTML = "";

const requester = new XMLHttpRequest();

requester.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
toCallOnSuccess();
} else if (this.readyState == 4 && this.status == 404) {
document.getElementById("error").innerHTML = "The file you have requested hasn't been generated yet. Please generate them first.";
} else if (this.readyState == 4) {
document.getElementById("error").innerHTML = "An error happened during the request. HTTP Code: " + this.status;
}
};

requester.open(verb, url, true);

if (verb == 'PUT') {
requester.setRequestHeader("Content-type", "application/json");
}

requester.send(body ? JSON.stringify(body) : null);
}

function generateFiles() {
let solutionsListParsed = [];

if (document.getElementById("solutionListDepths").value) {
const depths = document.getElementById("solutionListDepths").value.split(',');

for (let i = 0; i < depths.length; i++) {
if (!isNaN(parseInt(depths[i]))) {
solutionsListParsed[i] = parseInt(depths[i]);
} else {
solutionsListParsed[i] = 10;
}
}
}

const parameters = {
numberOfConcepts: document.getElementById("numberOfConcepts").value || 10000,
numberOfServices: document.getElementById("numberOfServices").value || 4000,
solvableProblem: document.getElementById("isSolvable").value == 'true' ? true : false,
solutionsList: solutionsListParsed
};

makeRequest('PUT', restAPIURL + '/gen', parameters, function() {
document.getElementById("status").innerHTML = "Successfully sent the generation request to the server.";
document.getElementById("divGetFiles").style.display = 'block';
});
}

function getWSDL() {
makeRequest('GET', restAPIURL + '/gen/wsdl', undefined, function() {
window.open(restAPIURL + '/gen/wsdl', '_blank');
});
}

function getWSLA() {
makeRequest('GET', restAPIURL + '/gen/wsla', undefined, function() {
window.open(restAPIURL + '/gen/wsla', '_blank');
});
}

function getOWL() {
makeRequest('GET', restAPIURL + '/gen/owl', undefined, function() {
window.open(restAPIURL + '/gen/owl', '_blank');
});
}

function getBPEL() {
makeRequest('GET', restAPIURL + '/gen/bpel', undefined, function() {
window.open(restAPIURL + '/gen/bpel', '_blank');
});
}

function changedValue() {
if (document.getElementById("isSolvable").value == 'true') {
document.getElementById("labelSolutionDepths").style.display = 'block';
} else {
document.getElementById("labelSolutionDepths").style.display = 'none';
document.getElementById("solutionListDepths").value = '';
}
}
</script>

<div style="text-align: center;">
<h1>Javascript REST Client for WS-Gen</h1>
</div>
<div>
<h3>Parameters for the Generator</h3>
<p id="error" style="color: red;"></p>
<p id="status"></p>
<label>
Number of concepts (integer):
<input id="numberOfConcepts" type="number"/>
</label>
<label>
Number of services (integer):
<input id="numberOfServices" type="number"/>
</label>
<label>
Is solvable (true or false)
<input id="isSolvable" type="text" onkeyup="changedValue()"/>
</label>
<label id="labelSolutionDepths" style="display: none;">
Solution list depths (integer separated by ,):
<input id="solutionListDepths" type="text"/>
</label>
<button type="button" onclick="generateFiles()">Generate Files</button>
<div id="divGetFiles" style="display: none;">
<button type="button" onclick="getWSDL()">Download WSDL</button>
<button type="button" onclick="getWSLA()">Download WSLA</button>
<button type="button" onclick="getOWL()">Download OWL</button>
<button type="button" onclick="getBPEL()">Download BPEL</button>
</div>
</div>
</body>
</html>
7 changes: 7 additions & 0 deletions nbproject/build-impl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
<project xmlns:webproject1="http://www.netbeans.org/ns/web-project/1" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:webproject3="http://www.netbeans.org/ns/web-project/3" basedir=".." default="default" name="WSC09Platform-impl">
<import file="jaxws-build.xml"/>
<import file="rest-build.xml"/>
<import file="ant-deploy.xml"/>
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
Expand Down Expand Up @@ -998,6 +999,9 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.xalan-2.7.0.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.xercesImpl-2.8.1.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.dom4j-1.6.1.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-annotations-2.9.4.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-core-2.9.4.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<copyfiles files="${file.reference.jackson-databind-2.9.4.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
<mkdir dir="${build.web.dir}/META-INF"/>
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
</target>
Expand All @@ -1015,6 +1019,9 @@ exists or setup the property manually. For example like this:
<copyfiles files="${file.reference.xalan-2.7.0.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.xercesImpl-2.8.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.dom4j-1.6.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-annotations-2.9.4.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-core-2.9.4.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
<copyfiles files="${file.reference.jackson-databind-2.9.4.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
</target>
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
<delete dir="${build.web.dir}/WEB-INF/lib"/>
Expand Down
12 changes: 12 additions & 0 deletions nbproject/genfiles.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@

build.xml.data.CRC32=7b1a7c2c
build.xml.data.CRC32=59c97cea

build.xml.script.CRC32=bcdf5eca
build.xml.stylesheet.CRC32=651128d4@1.77.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.

nbproject/build-impl.xml.data.CRC32=7b1a7c2c
nbproject/build-impl.xml.script.CRC32=7965e830
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1
nbproject/rest-build.xml.data.CRC32=0ab29f81
nbproject/rest-build.xml.script.CRC32=c9ad12d8
nbproject/rest-build.xml.stylesheet.CRC32=0cfeebcc@1.31.1

nbproject/build-impl.xml.data.CRC32=59c97cea
nbproject/build-impl.xml.script.CRC32=37407d58
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1

nbproject/jaxws-build.xml.stylesheet.CRC32=6608c2cf
11 changes: 9 additions & 2 deletions nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
endorsed.classpath=
excludes=
file.reference.axis.jar=WebContent/WEB-INF/lib/axis.jar
file.reference.commons-discovery-0.2.jar=WebContent/WEB-INF/lib/commons-discovery-0.2.jar
file.reference.commons-logging.jar=WebContent/WEB-INF/lib/commons-logging.jar
file.reference.dom4j-1.6.1.jar=src/lib/dom4j-1.6.1.jar
file.reference.jackson-annotations-2.9.4.jar=src/lib/jackson-annotations-2.9.4.jar
file.reference.jackson-core-2.9.4.jar=src/lib/jackson-core-2.9.4.jar
file.reference.jackson-databind-2.9.4.jar=src/lib/jackson-databind-2.9.4.jar
file.reference.jaxrpc.jar=WebContent/WEB-INF/lib/jaxrpc.jar
file.reference.jdom.jar=src/lib/jdom.jar
file.reference.saaj.jar=WebContent/WEB-INF/lib/saaj.jar
Expand Down Expand Up @@ -68,7 +72,10 @@ javac.classpath=\
${file.reference.WebServiceChallengeSources.jar}:\
${file.reference.xalan-2.7.0.jar}:\
${file.reference.xercesImpl-2.8.1.jar}:\
${file.reference.dom4j-1.6.1.jar}
${file.reference.dom4j-1.6.1.jar}:\
${file.reference.jackson-annotations-2.9.4.jar}:\
${file.reference.jackson-core-2.9.4.jar}:\
${file.reference.jackson-databind-2.9.4.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
Expand All @@ -95,10 +102,10 @@ javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=WebContent/WEB-INF/lib
no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
rest.config.type=ide
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
Expand Down
14 changes: 14 additions & 0 deletions nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
<type>org.netbeans.modules.web.project</type>
<configuration>
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1">
<extension file="rest-build.xml" id="rest.5"/>
<extension file="jaxws-build.xml" id="jaxws">
<dependency dependsOn="wsimport-client-generate" target="-pre-pre-compile"/>
</extension>

</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>WSC09Platform</name>
Expand Down Expand Up @@ -63,6 +65,18 @@
<file>${file.reference.dom4j-1.6.1.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jackson-annotations-2.9.4.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jackson-core-2.9.4.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.jackson-databind-2.9.4.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
Expand Down
6 changes: 6 additions & 0 deletions src/ca/concordia/cse/gipsy/ws/rest/ApplicationConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ca.concordia.cse.gipsy.ws.rest;

import javax.ws.rs.core.Application;

@javax.ws.rs.ApplicationPath("resources")
public class ApplicationConfig extends Application {}
72 changes: 72 additions & 0 deletions src/ca/concordia/cse/gipsy/ws/rest/GeneratorConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ca.concordia.cse.gipsy.ws.rest;

import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;

/**
*
* @author Jo
*/
@XmlRootElement
public class GeneratorConfiguration implements Serializable {
public int numberOfConcepts;
public int numberOfServices;
public boolean solvableProblem;
public int[] solutionsList ;

public GeneratorConfiguration() {

}

public void setNumberOfConcepts(String valueInput) {
this.numberOfConcepts = getInt(valueInput, 10000, "Number of concepts");
}

public void setNumberOfServices(String valueInput) {
this.numberOfServices = getInt(valueInput, 4000, "Number of services");
}

public void setSolvableProblem(boolean solvableProblem) {
this.solvableProblem = solvableProblem;
}

public void setSolutionsListViaString(String valueInput) {
String[] differentDepths = valueInput.split(",");

solutionsList = new int[differentDepths.length];

for (int i = 0; i < differentDepths.length; i++) {
solutionsList[i] = getInt(differentDepths[i], 10, "Solution list depth");
}
}

public void setSolutionsList(int[] valueInput) {
this.solutionsList = valueInput;
}

public int getNumberOfConcepts() {
return numberOfConcepts;
}

public int getNumberOfServices() {
return numberOfServices;
}

public boolean isSolvableProblem() {
return solvableProblem;
}

public int[] getSolutionsList() {
return solutionsList;
}

private int getInt(String value, int defaultVal, String paramName) {
try {
return Integer.parseInt(value);
} catch (Exception ex) {
System.out.println("Invalid value for " + paramName + ", taking default value: " + defaultVal);
return defaultVal;
}
}

}
Loading