diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ab5075b3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/Identity Service/nbproject/private/ +/StackExchange Client/nbproject/private/ +/StackExchange WS/nbproject/private/ +/Identity Service/build/ +/StackExchange Client/build/ +/StackExchange WS/build/ +/StackExchange WS/dist/ +/StackExchange Client/dist/ \ No newline at end of file diff --git a/Identity Service/build.xml b/Identity Service/build.xml new file mode 100644 index 00000000..a5d7ca3a --- /dev/null +++ b/Identity Service/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project Identity Service. + + + diff --git a/Identity Service/nbproject/ant-deploy.xml b/Identity Service/nbproject/ant-deploy.xml new file mode 100644 index 00000000..2d5f8778 --- /dev/null +++ b/Identity Service/nbproject/ant-deploy.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Identity Service/nbproject/build-impl.xml b/Identity Service/nbproject/build-impl.xml new file mode 100644 index 00000000..16b010f7 --- /dev/null +++ b/Identity Service/nbproject/build-impl.xml @@ -0,0 +1,1444 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Identity Service/nbproject/genfiles.properties b/Identity Service/nbproject/genfiles.properties new file mode 100644 index 00000000..6d1ad022 --- /dev/null +++ b/Identity Service/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=b83c48dd +build.xml.script.CRC32=1d4077fb +build.xml.stylesheet.CRC32=651128d4@1.68.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=b83c48dd +nbproject/build-impl.xml.script.CRC32=a4f3343c +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 diff --git a/Identity Service/nbproject/project.properties b/Identity Service/nbproject/project.properties new file mode 100644 index 00000000..20583568 --- /dev/null +++ b/Identity Service/nbproject/project.properties @@ -0,0 +1,90 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +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=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +file.reference.mysql-connector-java-5.0.8-bin.jar=C:\\Users\\User\\Desktop\\mysql-connector-java-5.0.8-bin.jar +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${file.reference.mysql-connector-java-5.0.8-bin.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=Identity_Service.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/Identity Service/nbproject/project.xml b/Identity Service/nbproject/project.xml new file mode 100644 index 00000000..1c7842df --- /dev/null +++ b/Identity Service/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.web.project + + + Identity Service + 1.6.5 + + + ${file.reference.mysql-connector-java-5.0.8-bin.jar} + WEB-INF/lib + + + + + + + + + + + + diff --git a/Identity Service/src/conf/MANIFEST.MF b/Identity Service/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/Identity Service/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/Identity Service/src/java/Login.java b/Identity Service/src/java/Login.java new file mode 100644 index 00000000..5b555c2c --- /dev/null +++ b/Identity Service/src/java/Login.java @@ -0,0 +1,141 @@ + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.*; +import java.util.*; +import java.sql.*; + +/** + * + * @author i-ONe + */ +@WebServlet(urlPatterns = {"/Login"}) +public class Login extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // JDBC driver name and database URL + String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + String DB_URL = "jdbc:mysql://localhost:3306/stackexchange"; + + // Database credentials + String USER = "root"; + String PASS = ""; + // Set response content type + //response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + response.setContentType("application/xml;charset=UTF-8"); + try { + // Register JDBC driver + Class.forName("com.mysql.jdbc.Driver"); + + // Execute SQL query + try ( // Open a connection + Connection conn = DriverManager.getConnection(DB_URL, USER, PASS); // Execute SQL query + Statement stmt = conn.createStatement()) { + String sql; + sql = "SELECT COUNT(*) as rowcount from user where Email = '" + request.getParameter("email") + "' and Password = '" + request.getParameter("password") + "'"; + ResultSet rs = stmt.executeQuery(sql); + rs.next(); + if (rs.getInt("rowcount") != 0) { + sql = "SELECT UserID from user where Email = '" + request.getParameter("email") + "'"; + rs = stmt.executeQuery(sql); + rs.next(); + int userid = rs.getInt("UserID"); + + sql = "delete from token where UserID = " + userid; + int i = stmt.executeUpdate(sql); + + String token = ""; + do { + token = generateToken(); + sql = "SELECT COUNT(*) as rowcount from token where AccessToken = '" + token + "'"; + rs = stmt.executeQuery(sql); + rs.next(); + } while (rs.getInt("rowcount") != 0); + + java.util.Date date = new java.util.Date(); + Timestamp expiredDate = new Timestamp(date.getTime() + (1000 * 60 * 60 * 24)); + sql = "INSERT INTO token (AccessToken,UserID,ExpiredDate) VALUES ('" + token + "'," + userid + ",'" + expiredDate + "')"; + i = stmt.executeUpdate(sql); + if (i > 0) { + Cookie accessToken = new Cookie("access_token", token); + accessToken.setMaxAge(60 * 60 * 24); + response.addCookie(accessToken); + out.println("authenticationsuccess"); + } + } else { + out.println("authenticationerror"); + } + // Clean-up environment + rs.close(); + } + } catch (SQLException | ClassNotFoundException se) { + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String generateToken() { + String sAlphabet = "abcdefghijklmnopqrstuvwxyz"; + String CAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String number = "0123456789"; + String token = ""; + + Random r = new Random(); + token = token + sAlphabet.charAt(r.nextInt(26)); + token = token + number.charAt(r.nextInt(10)); + token = token + number.charAt(r.nextInt(10)); + token = token + CAlphabet.charAt(r.nextInt(26)); + + return token; + } +} diff --git a/Identity Service/src/java/TokenValidator.java b/Identity Service/src/java/TokenValidator.java new file mode 100644 index 00000000..ae8b5457 --- /dev/null +++ b/Identity Service/src/java/TokenValidator.java @@ -0,0 +1,114 @@ + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.*; +import java.sql.*; + +/** + * + * @author i-ONe + */ +@WebServlet(urlPatterns = {"/TokenValidator"}) +public class TokenValidator extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // JDBC driver name and database URL + String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + String DB_URL = "jdbc:mysql://localhost:3306/stackexchange"; + + // Database credentials + String USER = "root"; + String PASS = ""; + + Cookie cookie; + Cookie[] cookies; + cookies = request.getCookies(); + response.setContentType("application/xml;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + if (cookies != null) { + cookie = cookies[0]; + + try { + // Register JDBC driver + Class.forName("com.mysql.jdbc.Driver"); + + // Execute SQL query + try ( // Open a connection + Connection conn = DriverManager.getConnection(DB_URL, USER, PASS); // Execute SQL query + Statement stmt = conn.createStatement()) { + String sql = "SELECT UserID from token where AccessToken = '" + cookie.getValue() + "'"; + try (ResultSet rs = stmt.executeQuery(sql)) { + int userid = 0; + while (rs.next()) { + userid = rs.getInt("UserID"); + } + if (userid != 0) { + out.println(userid); + } else { + out.println("accesstokennotvalid"); + } + + // Clean-up environment + } + } + } catch (SQLException | ClassNotFoundException se) { + } + } else { + out.println("accesstokenerror"); + } + //out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/Identity Service/web/WEB-INF/glassfish-web.xml b/Identity Service/web/WEB-INF/glassfish-web.xml new file mode 100644 index 00000000..29544b30 --- /dev/null +++ b/Identity Service/web/WEB-INF/glassfish-web.xml @@ -0,0 +1,11 @@ + + + + /Identity_Service + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/Identity Service/web/WEB-INF/web.xml b/Identity Service/web/WEB-INF/web.xml new file mode 100644 index 00000000..b198f290 --- /dev/null +++ b/Identity Service/web/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + + DatabaseAccess + DatabaseAccess + + + DatabaseAccess + /DatabaseAccess + + + + 30 + + + diff --git a/Identity Service/web/index.html b/Identity Service/web/index.html new file mode 100644 index 00000000..c627c249 --- /dev/null +++ b/Identity Service/web/index.html @@ -0,0 +1,16 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ + diff --git a/README.md b/README.md index c079a1d2..e2e7d54b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Diharapkan dengan tugas ini anda dapat mengerti: ### Link Laporan -*Masukkan link laporan anda di sini* +https://www.dropbox.com/s/pzbu1epa4c5jud1/Laporan%20Tubes%202%20WBD.pdf?dl=0 ### Arsitektur Umum Server diff --git a/StackExchange Client/build.xml b/StackExchange Client/build.xml new file mode 100644 index 00000000..e0ea866a --- /dev/null +++ b/StackExchange Client/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project StackExchange Client. + + + diff --git a/StackExchange Client/catalog.xml b/StackExchange Client/catalog.xml new file mode 100644 index 00000000..4334e7ac --- /dev/null +++ b/StackExchange Client/catalog.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/nbproject/ant-deploy.xml b/StackExchange Client/nbproject/ant-deploy.xml new file mode 100644 index 00000000..2d5f8778 --- /dev/null +++ b/StackExchange Client/nbproject/ant-deploy.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange Client/nbproject/build-impl.xml b/StackExchange Client/nbproject/build-impl.xml new file mode 100644 index 00000000..c317ba43 --- /dev/null +++ b/StackExchange Client/nbproject/build-impl.xml @@ -0,0 +1,1442 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange Client/nbproject/genfiles.properties b/StackExchange Client/nbproject/genfiles.properties new file mode 100644 index 00000000..4ad86ed6 --- /dev/null +++ b/StackExchange Client/nbproject/genfiles.properties @@ -0,0 +1,9 @@ +build.xml.data.CRC32=363903de +build.xml.script.CRC32=9badb0fb +build.xml.stylesheet.CRC32=651128d4@1.68.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=363903de +nbproject/build-impl.xml.script.CRC32=4ce5057a +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 +nbproject/jaxws-build.xml.stylesheet.CRC32=6608c2cf diff --git a/StackExchange Client/nbproject/jax-ws.xml b/StackExchange Client/nbproject/jax-ws.xml new file mode 100644 index 00000000..0ef7652c --- /dev/null +++ b/StackExchange Client/nbproject/jax-ws.xml @@ -0,0 +1,114 @@ + + + + + + http://localhost:8081/StackExchange_WS/UserWS?wsdl + localhost_8081/StackExchange_WS/UserWS.wsdl + UserWS + catalog.xml + + + extension + true + + + verbose + true + + + fork + false + + + wsdlLocation + http://localhost:8081/StackExchange_WS/UserWS?wsdl + + + xnocompile + true + + + xendorsed + true + + + package + UserWS + + + + + http://localhost:8081/StackExchange_WS/QuestionWS?wsdl + localhost_8081/StackExchange_WS/QuestionWS.wsdl + QuestionWS + catalog.xml + + + extension + true + + + verbose + true + + + fork + false + + + wsdlLocation + http://localhost:8081/StackExchange_WS/QuestionWS?wsdl + + + xnocompile + true + + + xendorsed + true + + + package + QuestionWS + + + + + http://localhost:8081/StackExchange_WS/AnswerWS?wsdl + localhost_8081/StackExchange_WS/AnswerWS.wsdl + AnswerWS + catalog.xml + + + extension + true + + + verbose + true + + + fork + false + + + wsdlLocation + http://localhost:8081/StackExchange_WS/AnswerWS?wsdl + + + xnocompile + true + + + xendorsed + true + + + package + AnswerWS + + + + + diff --git a/StackExchange Client/nbproject/jaxws-build.xml b/StackExchange Client/nbproject/jaxws-build.xml new file mode 100644 index 00000000..706b2b80 --- /dev/null +++ b/StackExchange Client/nbproject/jaxws-build.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange Client/nbproject/project.properties b/StackExchange Client/nbproject/project.properties new file mode 100644 index 00000000..be4be625 --- /dev/null +++ b/StackExchange Client/nbproject/project.properties @@ -0,0 +1,88 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +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=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=StackExchange_Client.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/StackExchange Client/nbproject/project.xml b/StackExchange Client/nbproject/project.xml new file mode 100644 index 00000000..f0df71be --- /dev/null +++ b/StackExchange Client/nbproject/project.xml @@ -0,0 +1,23 @@ + + + org.netbeans.modules.web.project + + + + + + + + StackExchange Client + 1.6.5 + + + + + + + + + + + diff --git a/StackExchange Client/src/conf/MANIFEST.MF b/StackExchange Client/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/StackExchange Client/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl b/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl new file mode 100644 index 00000000..c2aff190 --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd b/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd new file mode 100644 index 00000000..efd5721f --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/AnswerWS/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl b/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl new file mode 100644 index 00000000..a21fc993 --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd b/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd new file mode 100644 index 00000000..1fc59212 --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/QuestionWS/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl b/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl new file mode 100644 index 00000000..3ba13063 --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd b/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd new file mode 100644 index 00000000..8bbd2c01 --- /dev/null +++ b/StackExchange Client/src/conf/xml-resources/web-service-references/UserWS/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/src/java/Answer/CreateAnswerServlet.java b/StackExchange Client/src/java/Answer/CreateAnswerServlet.java new file mode 100644 index 00000000..d979c265 --- /dev/null +++ b/StackExchange Client/src/java/Answer/CreateAnswerServlet.java @@ -0,0 +1,114 @@ +package Answer; + +import AnswerWS.AnswerWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class CreateAnswerServlet extends HttpServlet { + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl") + private AnswerWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String accessToken = "a"; + String content = request.getParameter("content"); + int qid = Integer.parseInt(request.getParameter("qid")); + String result = createAnswer(accessToken,qid,content); + if (result.equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/question.jsp?qid="+qid); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("
\n" + + " \n" + + "

Simple StackExchange

\n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Jawaban gagal dibuat

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String createAnswer(java.lang.String accessToken, int qid, java.lang.String content) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + AnswerWS.AnswerWS port = service.getAnswerWSPort(); + return port.createAnswer(accessToken, qid, content); + } + +} diff --git a/StackExchange Client/src/java/Answer/VoteAnswerServlet.java b/StackExchange Client/src/java/Answer/VoteAnswerServlet.java new file mode 100644 index 00000000..2c87542b --- /dev/null +++ b/StackExchange Client/src/java/Answer/VoteAnswerServlet.java @@ -0,0 +1,125 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Answer; + +import AnswerWS.AnswerWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class VoteAnswerServlet extends HttpServlet { + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl") + private AnswerWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + int qid = Integer.parseInt(request.getParameter("qid")); + int aid = Integer.parseInt(request.getParameter("aid")); + String type = request.getParameter("type"); + String accessToken = null; + String result; + if (type.equals("up")) { + result = voteAnswer(accessToken, aid, true); + } else { + result = voteAnswer(accessToken, aid, false); + } + if (result.equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/question.jsp?qid="+qid); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("
\n" + + " \n" + + "

Simple StackExchange

\n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Gagal vote pertanyaan

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String voteAnswer(java.lang.String accessToken, int aid, boolean voteUp) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + AnswerWS.AnswerWS port = service.getAnswerWSPort(); + return port.voteAnswer(accessToken, aid, voteUp); + } + +} diff --git a/StackExchange Client/src/java/Question/CreateQuestionServlet.java b/StackExchange Client/src/java/Question/CreateQuestionServlet.java new file mode 100644 index 00000000..1d81b192 --- /dev/null +++ b/StackExchange Client/src/java/Question/CreateQuestionServlet.java @@ -0,0 +1,114 @@ +package Question; + +import QuestionWS.QuestionWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class CreateQuestionServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String topic = request.getParameter("topic"); + String content = request.getParameter("content"); + String accessToken = null; + if (createQuestion(accessToken, topic, content).equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/index.jsp"); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("
\n" + + " \n" + + "

Simple StackExchange

\n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Pertanyaan gagal dibuat

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String createQuestion(java.lang.String accessToken, java.lang.String title, java.lang.String content) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.createQuestion(accessToken, title, content); + } + +} diff --git a/StackExchange Client/src/java/Question/DeleteQuestionServlet.java b/StackExchange Client/src/java/Question/DeleteQuestionServlet.java new file mode 100644 index 00000000..f5bde100 --- /dev/null +++ b/StackExchange Client/src/java/Question/DeleteQuestionServlet.java @@ -0,0 +1,119 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Question; + +import QuestionWS.QuestionWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class DeleteQuestionServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + int qid = Integer.parseInt(request.getParameter("qid")); + String accessToken = null; + String result = deleteQuestion(qid, accessToken); + if (result.equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/index.jsp"); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("
\n" + + " \n" + + "

Simple StackExchange

\n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Gagal menghapus pertanyaan

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String deleteQuestion(int qid, java.lang.String accessToken) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.deleteQuestion(qid, accessToken); + } + +} diff --git a/StackExchange Client/src/java/Question/EditQuestionServlet.java b/StackExchange Client/src/java/Question/EditQuestionServlet.java new file mode 100644 index 00000000..6302fa5a --- /dev/null +++ b/StackExchange Client/src/java/Question/EditQuestionServlet.java @@ -0,0 +1,101 @@ +package Question; + +import QuestionWS.Question; +import QuestionWS.QuestionWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class EditQuestionServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + int qid = Integer.parseInt(request.getParameter("qid")); + List question = getQuestionByQID(qid); + for (int i = 0; i < question.size(); i++) { + out.println("
\n" + + " " + + "
\n" + + " \n" + + "
\n" + + "
"); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private java.util.List getQuestionByQID(int qid) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.getQuestionByQID(qid); + } + +} diff --git a/StackExchange Client/src/java/Question/EditServlet.java b/StackExchange Client/src/java/Question/EditServlet.java new file mode 100644 index 00000000..ce49d19c --- /dev/null +++ b/StackExchange Client/src/java/Question/EditServlet.java @@ -0,0 +1,121 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Question; + +import QuestionWS.QuestionWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class EditServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + int qid = Integer.parseInt(request.getParameter("qid")); + String topic = request.getParameter("topic"); + String content = request.getParameter("content"); + String accessToken = null; + String result = editQuestion(qid, accessToken, topic, content); + if (result.equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/index.jsp"); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Pertanyaan gagal diubah

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String editQuestion(int qid, java.lang.String accessToken, java.lang.String title, java.lang.String content) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.editQuestion(qid, accessToken, title, content); + } + +} diff --git a/StackExchange Client/src/java/Question/QuestionByQIDServlet.java b/StackExchange Client/src/java/Question/QuestionByQIDServlet.java new file mode 100644 index 00000000..23bc5926 --- /dev/null +++ b/StackExchange Client/src/java/Question/QuestionByQIDServlet.java @@ -0,0 +1,220 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package Question; + +import AnswerWS.Answer; +import AnswerWS.AnswerWS_Service; +import QuestionWS.Question; +import QuestionWS.QuestionWS_Service; +import UserWS.UserWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class QuestionByQIDServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl") + private AnswerWS_Service service_2; + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl") + private UserWS_Service service_1; + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + int qid = Integer.parseInt((String) request.getAttribute("qid")); + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + List question = getQuestionByQID(qid); + for (int i = 0; i < question.size(); i++) { + out.println("
\n" + + "

"); + out.println(question.get(i).getTopic()); + out.println("

\n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
"); + out.println(question.get(i).getVotes()); + out.println("
\n" + + " \n" + + " \n" + + " \n" + + "
"); + out.println(question.get(i).getContent()); + out.println("
\n" + + " asked by "); + out.println(getUser(question.get(i).getUserID()).get(0).getEmail()); + out.println(" at "); + out.println(question.get(i).getDateTime().substring(0, 19)); + out.println(" | \n" + + " \n" + + " edit\n" + + " | \n" + + " \n" + + " delete\n" + + " \n" + + "
\n" + + "\n" + + "
\n" + + "

"); + out.print(question.get(i).getAnswers() + " Answer"); + if (question.get(i).getAnswers() != 1) { + out.println("s"); + } + out.println("

\n" + + "
"); + } + List answers = getAnswerByQID(Integer.valueOf((String) request.getAttribute("qid"))); + for (int i = 0; i < answers.size(); i++) { + out.println("\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + "
"); + out.println(answers.get(i).getVotes()); + out.println("
\n" + + " \n" + + " \n" + + " \n" + + "
"); + out.println(answers.get(i).getContent()); + out.println("
\n" + + " answered by "); + out.println(getUser(answers.get(i).getUserID()).get(0).getEmail()); + out.println(" at "); + out.println(answers.get(i).getDateTime().substring(0, 19)); + out.println("
\n" + + "
"); + } + out.println("

\n" + + " Your Answer\n" + + "

\n" + + "\n" + + "
\n" + + " \n" + + " \n" + + "
\n" + + "
"); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private java.util.List getQuestionByQID(int qid) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.getQuestionByQID(qid); + } + + private java.util.List getUser(int userID) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + UserWS.UserWS port = service_1.getUserWSPort(); + return port.getUser(userID); + } + + private java.util.List getAnswerByQID(int qid) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + AnswerWS.AnswerWS port = service_2.getAnswerWSPort(); + return port.getAnswerByQID(qid); + } + +} diff --git a/StackExchange Client/src/java/Question/QuestionListServlet.java b/StackExchange Client/src/java/Question/QuestionListServlet.java new file mode 100644 index 00000000..3a8c3d47 --- /dev/null +++ b/StackExchange Client/src/java/Question/QuestionListServlet.java @@ -0,0 +1,147 @@ +package Question; + +import QuestionWS.Question; +import QuestionWS.QuestionWS_Service; +import UserWS.UserWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class QuestionListServlet extends HttpServlet { + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl") + private UserWS_Service service_1; + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + List questions = getAllQuestion(); + for (int i = 0; i < questions.size(); i++) { + out.println("\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " "); + out.println(questions.get(i).getVotes()); + out.println("
\n" + + " Votes\n" + + "
\n" + + "
\n" + + " "); + out.println(questions.get(i).getAnswers()); + out.println("
\n" + + " Answers\n" + + "
\n" + + "
\n" + + "

\n" + + " "); + out.println(questions.get(i).getTopic()); + out.println("\n" + + "

\n" + + "

"); + out.println(questions.get(i).getContent()); + out.println("

\n" + + "
\n" + + "
\n" + + " asked by\n" + + "

"); + out.println(getUser(questions.get(i).getUserID()).get(0).getEmail()); + out.println("

| \n" + + " \n" + + " edit\n" + + " | \n" + + " \n" + + " delete\n" + + " \n" + + "
\n" + + "
"); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private java.util.List getAllQuestion() { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.getAllQuestion(); + } + + private java.util.List getUser(int userID) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + UserWS.UserWS port = service_1.getUserWSPort(); + return port.getUser(userID); + } +} diff --git a/StackExchange Client/src/java/Question/VoteQuestionServlet.java b/StackExchange Client/src/java/Question/VoteQuestionServlet.java new file mode 100644 index 00000000..1fb1d83f --- /dev/null +++ b/StackExchange Client/src/java/Question/VoteQuestionServlet.java @@ -0,0 +1,120 @@ +package Question; + +import QuestionWS.QuestionWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class VoteQuestionServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl") + private QuestionWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + int qid = Integer.parseInt(request.getParameter("qid")); + String type = request.getParameter("type"); + String accessToken = null; + String result; + if (type.equals("up")) { + result = voteQuestion(accessToken, qid, true); + } else { + result = voteQuestion(accessToken, qid, false); + } + if (result.equals("Respons oke!")) { + response.sendRedirect("/StackExchange_Client/question.jsp?qid="+qid); + } else { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + out.println("

Gagal vote pertanyaan

"); + out.println("
"); + out.println(""); + out.println(""); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String voteQuestion(java.lang.String accessToken, int qid, boolean voteUp) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + QuestionWS.QuestionWS port = service.getQuestionWSPort(); + return port.voteQuestion(accessToken, qid, voteUp); + } + +} diff --git a/StackExchange Client/src/java/User/Login.java b/StackExchange Client/src/java/User/Login.java new file mode 100644 index 00000000..08df1e66 --- /dev/null +++ b/StackExchange Client/src/java/User/Login.java @@ -0,0 +1,126 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package User; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.MediaType; +import javax.xml.ws.Response; + +/** + * + * @author User + */ +@WebServlet(name = "Login", urlPatterns = {"/Login"}) +public class Login extends HttpServlet { + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + // Get the parameters needed + String email = request.getParameter("email"); + String password = request.getParameter("password"); + + // Creating a new Form Object, and set the parameters + Form form = new Form(); + form.param("email", email); + form.param("password", password); + + // Create a new Client Object + Client client = ClientBuilder.newClient(); + + // URL/Endpoint of the resource provider + String url = "http://localhost:8082/Identity_Service/Login"; + + try + { + // Call the REST API and save the result string + String result = client.target(url).request(MediaType.APPLICATION_XML) + .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED), String.class); + // The result is User not found or the loign failed + if("authenticationerror".equals(result.trim())){ + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + + // Redirect to the login page with error message + request.setAttribute("errorMessage", "Invalid Email / Password !"); + request.getRequestDispatcher("/login.jsp").forward(request, response); + } + if("authenticationsuccess".equals(result.trim())){ + // Redirect it to the home page + response.setContentType("text/html"); + response.sendRedirect("index.jsp"); + }else{ + + + out.println(url); + } + } + catch(ServletException | IOException ex){ + request.setAttribute("errorMessage", ex.getMessage()); + request.getRequestDispatcher("/login.jsp").forward(request, response); + } + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + +} diff --git a/StackExchange Client/src/java/User/RegisterServlet.java b/StackExchange Client/src/java/User/RegisterServlet.java new file mode 100644 index 00000000..6cfa094c --- /dev/null +++ b/StackExchange Client/src/java/User/RegisterServlet.java @@ -0,0 +1,120 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package User; + +import UserWS.UserWS_Service; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.ws.WebServiceRef; + +/** + * + * @author M. Fauzan Naufan + */ +public class RegisterServlet extends HttpServlet { + + @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl") + private UserWS_Service service; + + /** + * Processes requests for both HTTP GET and POST + * methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("Simple StackExchange"); + out.println(""); + out.println(""); + out.println(""); + out.println("\n" + + "
\n" + + " \n" + + " Register |\n" + + " Login\n" + + " \n" + + "
"); + out.println("
"); + out.println("
"); + String nama = request.getParameter("nama"); + String email = request.getParameter("email"); + String password = request.getParameter("password"); + String result = register(nama, email, password); + if (result.equals("Sukses!")) { + out.println("

Akun dengan nama " + nama + " berhasil diregistrasi

"); + } else { + out.println("

Registrasi akun gagal

"); + } + out.println("
"); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// + + private String register(java.lang.String nama, java.lang.String email, java.lang.String password) { + // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe. + // If the calling of port operations may lead to race condition some synchronization is required. + UserWS.UserWS port = service.getUserWSPort(); + return port.register(nama, email, password); + } + +} diff --git a/StackExchange Client/web/WEB-INF/glassfish-web.xml b/StackExchange Client/web/WEB-INF/glassfish-web.xml new file mode 100644 index 00000000..60c15cdc --- /dev/null +++ b/StackExchange Client/web/WEB-INF/glassfish-web.xml @@ -0,0 +1,10 @@ + + + + /StackExchange_Client + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/StackExchange Client/web/WEB-INF/jax-ws-catalog.xml b/StackExchange Client/web/WEB-INF/jax-ws-catalog.xml new file mode 100644 index 00000000..79707918 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/jax-ws-catalog.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/web.xml b/StackExchange Client/web/WEB-INF/web.xml new file mode 100644 index 00000000..e6984e23 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/web.xml @@ -0,0 +1,88 @@ + + + + RegisterServlet + User.RegisterServlet + + + QuestionListServlet + Question.QuestionListServlet + + + CreateQuestionServlet + Question.CreateQuestionServlet + + + QuestionByQIDServlet + Question.QuestionByQIDServlet + + + CreateAnswerServlet + Answer.CreateAnswerServlet + + + EditQuestionServlet + Question.EditQuestionServlet + + + EditServlet + Question.EditServlet + + + DeleteQuestionServlet + Question.DeleteQuestionServlet + + + VoteQuestionServlet + Question.VoteQuestionServlet + + + VoteAnswerServlet + Answer.VoteAnswerServlet + + + RegisterServlet + /RegisterServlet + + + QuestionListServlet + /QuestionListServlet + + + CreateQuestionServlet + /CreateQuestionServlet + + + QuestionByQIDServlet + /QuestionByQIDServlet + + + CreateAnswerServlet + /CreateAnswerServlet + + + EditQuestionServlet + /EditQuestionServlet + + + EditServlet + /EditServlet + + + DeleteQuestionServlet + /DeleteQuestionServlet + + + VoteQuestionServlet + /VoteQuestionServlet + + + VoteAnswerServlet + /VoteAnswerServlet + + + + 30 + + + diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl new file mode 100644 index 00000000..c2aff190 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.wsdl @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd new file mode 100644 index 00000000..efd5721f --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/AnswerWS.xsd_1.xsd @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl new file mode 100644 index 00000000..a21fc993 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.wsdl @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd new file mode 100644 index 00000000..1fc59212 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/QuestionWS.xsd_1.xsd @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl new file mode 100644 index 00000000..3ba13063 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.wsdl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd new file mode 100644 index 00000000..8bbd2c01 --- /dev/null +++ b/StackExchange Client/web/WEB-INF/wsdl/localhost_8081/StackExchange_WS/UserWS.xsd_1.xsd @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StackExchange Client/web/create.jsp b/StackExchange Client/web/create.jsp new file mode 100644 index 00000000..62bd1464 --- /dev/null +++ b/StackExchange Client/web/create.jsp @@ -0,0 +1,32 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Simple StackExchange + + + + + +
+
+

What's your question?

+
+
+
+ +
+
+
+ + diff --git a/StackExchange Client/web/edit.jsp b/StackExchange Client/web/edit.jsp new file mode 100644 index 00000000..a8ac4c69 --- /dev/null +++ b/StackExchange Client/web/edit.jsp @@ -0,0 +1,28 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Simple StackExchange + + + + + +
+
+

Edit your question

+
+ +
+ + diff --git a/StackExchange Client/web/img/vote-down.png b/StackExchange Client/web/img/vote-down.png new file mode 100644 index 00000000..5defb324 Binary files /dev/null and b/StackExchange Client/web/img/vote-down.png differ diff --git a/StackExchange Client/web/img/vote-up.png b/StackExchange Client/web/img/vote-up.png new file mode 100644 index 00000000..16b41539 Binary files /dev/null and b/StackExchange Client/web/img/vote-up.png differ diff --git a/StackExchange Client/web/index.jsp b/StackExchange Client/web/index.jsp new file mode 100644 index 00000000..db904391 --- /dev/null +++ b/StackExchange Client/web/index.jsp @@ -0,0 +1,45 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + Simple StackExchange + + + + + +
+
+ + +

+ Recently Asked Questions +

+
+ +
+ +
+
+ + diff --git a/StackExchange Client/web/login.jsp b/StackExchange Client/web/login.jsp new file mode 100644 index 00000000..3ba6ecdd --- /dev/null +++ b/StackExchange Client/web/login.jsp @@ -0,0 +1,32 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Simple StackExchange + + + + + +
+
+

Log in to your account

+
+
+
+
+ +
+
+ + diff --git a/StackExchange Client/web/main.css b/StackExchange Client/web/main.css new file mode 100644 index 00000000..3841139a --- /dev/null +++ b/StackExchange Client/web/main.css @@ -0,0 +1,170 @@ +.navbar{ + +} + + + + +a { + color:inherit; + cursor:pointer; + text-decoration:none; +} + +a.red { + color:red; +} + +a.gold { + color:gold; +} + +a.white { + color:white; +} + +b.navbar-down { + margin-right: 2%; +} + +body { + font-family:Calibri; + margin:0; +} + +div.main { + margin-left:20%; + margin-right:20%; + margin-top:0; +} + +div.navbar-up { + background-color : black; + text-align: center; + padding-top: 5px; +} + +div.navbar-down { + background-color : black; + text-align: right; + color:white; + padding-bottom: 5px; +} + +div.searchbar { + margin-left:15px; + margin-right:15px; +} + +div.VotesA { + padding-bottom:7px; +} + +div#VotesQ { + padding-bottom:7px; +} + +h1 { + text-align:center; +} + +h1.white { + display : inline; + color:white; +} + +h2 { + margin-bottom:0; +} + +hr { + border:1px solid black; + margin-bottom:1em; +} + +input.button { + margin-left:93%; + width:7.2%; +} + +input.text { + margin-bottom:0.2em; + padding:3px; + width:100%; +} + +input#searchbar { + border:3px solid black; + height:22px; + width:85%; +} + +input#searchbutton { + background-color:white; + border:3px solid black; + height:30px; + width:12%; +} + +p.blue { + color:blue; + display:inline; +} + +p.content { + font-size:auto; + margin:0; + max-height:50px; + overflow:hidden; + padding:2%; +} + +p.topic { + font-size:20px; + margin:0; + padding:2%; +} + +p#RecentlyAsked { + font-size:19px; + margin-bottom:0; +} + +p#searchbar { + margin-top:0.5em; + text-align:center; +} + +p#SearchResults { + font-size:19px; + margin-bottom:0; +} + +table { + width:100%; +} + +td.Answerer,td.Asker { + text-align:right; +} + +td.Answers,td.Votes { + text-align:center; + width:10%; +} + +td.VotesQA { + color:grey; + font-size:25px; + text-align:center; + width:8%; +} + +textarea { + margin-bottom:0.2em; + padding:3px; + font-family:Calibri; + font-size:14px; + width:100%; + height:110px; +} \ No newline at end of file diff --git a/StackExchange Client/web/question.jsp b/StackExchange Client/web/question.jsp new file mode 100644 index 00000000..f777bd2e --- /dev/null +++ b/StackExchange Client/web/question.jsp @@ -0,0 +1,29 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + Simple StackExchange + + + + + + +
+ + +
+ + diff --git a/StackExchange Client/web/register.jsp b/StackExchange Client/web/register.jsp new file mode 100644 index 00000000..0d73646c --- /dev/null +++ b/StackExchange Client/web/register.jsp @@ -0,0 +1,33 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + Simple StackExchange + + + + + +
+
+

Register your account

+
+
+
+
+
+ +
+
+ + diff --git a/StackExchange WS/build.xml b/StackExchange WS/build.xml new file mode 100644 index 00000000..37da8c40 --- /dev/null +++ b/StackExchange WS/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + Builds, tests, and runs the project StackExchange WS. + + + diff --git a/StackExchange WS/nbproject/ant-deploy.xml b/StackExchange WS/nbproject/ant-deploy.xml new file mode 100644 index 00000000..2d5f8778 --- /dev/null +++ b/StackExchange WS/nbproject/ant-deploy.xml @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange WS/nbproject/build-impl.xml b/StackExchange WS/nbproject/build-impl.xml new file mode 100644 index 00000000..684cab0b --- /dev/null +++ b/StackExchange WS/nbproject/build-impl.xml @@ -0,0 +1,1445 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange WS/nbproject/genfiles.properties b/StackExchange WS/nbproject/genfiles.properties new file mode 100644 index 00000000..c159494a --- /dev/null +++ b/StackExchange WS/nbproject/genfiles.properties @@ -0,0 +1,9 @@ +build.xml.data.CRC32=9b1c82b9 +build.xml.script.CRC32=0e9ef7c9 +build.xml.stylesheet.CRC32=651128d4@1.68.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=9b1c82b9 +nbproject/build-impl.xml.script.CRC32=2a897a91 +nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.68.1.1 +nbproject/jaxws-build.xml.stylesheet.CRC32=6608c2cf diff --git a/StackExchange WS/nbproject/jax-ws.xml b/StackExchange WS/nbproject/jax-ws.xml new file mode 100644 index 00000000..db3c33c2 --- /dev/null +++ b/StackExchange WS/nbproject/jax-ws.xml @@ -0,0 +1,15 @@ + + + + + AnswerModel.AnswerWS + + + UserModel.UserWS + + + QuestionModel.QuestionWS + + + + diff --git a/StackExchange WS/nbproject/jaxws-build.xml b/StackExchange WS/nbproject/jaxws-build.xml new file mode 100644 index 00000000..5fa8c649 --- /dev/null +++ b/StackExchange WS/nbproject/jaxws-build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StackExchange WS/nbproject/project.properties b/StackExchange WS/nbproject/project.properties new file mode 100644 index 00000000..cf328a25 --- /dev/null +++ b/StackExchange WS/nbproject/project.properties @@ -0,0 +1,89 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=true +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.web.dir}/WEB-INF/classes +build.classes.excludes=**/*.java,**/*.form +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +build.web.dir=${build.dir}/web +build.web.excludes=${build.classes.excludes} +client.urlPart= +compile.jsps=false +conf.dir=${source.root}/conf +debug.classpath=${build.classes.dir}:${javac.classpath} +debug.test.classpath=\ + ${run.test.classpath} +display.browser=true +# Files to be excluded from distribution war +dist.archive.excludes= +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=\ + ${libs.javaee-endorsed-api-6.0.classpath} +excludes= +includes=** +j2ee.compile.on.save=true +j2ee.copy.static.files.on.save=true +j2ee.deploy.on.save=true +j2ee.platform=1.7-web +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar +j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar +j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar +j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar +j2ee.platform.wsit.classpath= +j2ee.server.type=gfv3ee6 +jar.compress=false +javac.classpath=\ + ${libs.MySQLDriver.classpath} +# Space-separated list of extra javac options +javac.compilerargs= +javac.debug=true +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.preview=true +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +lib.dir=${web.docbase.dir}/WEB-INF/lib +persistence.xml.dir=${conf.dir} +platform.active=default_platform +resource.dir=setup +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +# Space-separated list of JVM arguments used when running a class with a main method or a unit test +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value): +runmain.jvmargs= +source.encoding=UTF-8 +source.root=src +src.dir=${source.root}/java +test.src.dir=test +war.content.additional= +war.ear.name=${war.name} +war.name=StackExchange_WS.war +web.docbase.dir=web +webinf.dir=web/WEB-INF diff --git a/StackExchange WS/nbproject/project.xml b/StackExchange WS/nbproject/project.xml new file mode 100644 index 00000000..de9560ad --- /dev/null +++ b/StackExchange WS/nbproject/project.xml @@ -0,0 +1,26 @@ + + + org.netbeans.modules.web.project + + + + + + StackExchange WS + 1.6.5 + + + ${libs.MySQLDriver.classpath} + WEB-INF/lib + + + + + + + + + + + + diff --git a/StackExchange WS/src/conf/MANIFEST.MF b/StackExchange WS/src/conf/MANIFEST.MF new file mode 100644 index 00000000..59499bce --- /dev/null +++ b/StackExchange WS/src/conf/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/StackExchange WS/src/java/AnswerModel/Answer.java b/StackExchange WS/src/java/AnswerModel/Answer.java new file mode 100644 index 00000000..a9764aeb --- /dev/null +++ b/StackExchange WS/src/java/AnswerModel/Answer.java @@ -0,0 +1,45 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package AnswerModel; + +import javax.xml.bind.*; +import javax.xml.bind.annotation.*; + +/** + * + * @author M. Fauzan Naufan + */ + +@XmlRootElement(name="Answer") +public class Answer { + @XmlElement(name="AID", required=true) + private int aid; + @XmlElement(name="UserID", required=true) + private int userid; + @XmlElement(name="Content", required=true) + private String content; + @XmlElement(name="Votes", required=true) + private int votes; + @XmlElement(name="QID", required=true) + private int qid; + @XmlElement(name="DateTime", required=true) + private String datetime; + + public Answer() { + aid=0; + userid=0; + qid=0; + } + + public Answer(int aid1, int userid1, String content1, int votes1, int qid1, String datetime1) { + aid=aid1; + userid=userid1; + content=content1; + votes=votes1; + qid=qid1; + datetime=datetime1; + } +} diff --git a/StackExchange WS/src/java/AnswerModel/AnswerWS.java b/StackExchange WS/src/java/AnswerModel/AnswerWS.java new file mode 100644 index 00000000..6188314e --- /dev/null +++ b/StackExchange WS/src/java/AnswerModel/AnswerWS.java @@ -0,0 +1,135 @@ +package AnswerModel; + +import DB.Database; +import java.io.IOException; +import java.net.*; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.*; +import javax.jws.*; +import javax.servlet.http.Cookie; + +/** + * + * @author M. Fauzan Naufan + */ +@WebService(serviceName = "AnswerWS") +public class AnswerWS { + + /** + * Web service operation + * + * @param qid + * @return + */ + @WebMethod(operationName = "getAnswerByQID") + @WebResult(name = "Answer") + public ArrayList getAnswerByQID(@WebParam(name = "qid") int qid) { + Connection conn = new Database().connect(); + ArrayList answers = new ArrayList(); + Statement stmt; + ResultSet rs; + + try { + stmt = conn.createStatement(); + String sql = "SELECT * FROM answer WHERE qid = ? ORDER BY Votes DESC"; + + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, qid); + rs = pstmt.executeQuery(); + + while (rs.next()) { + answers.add(new Answer(rs.getInt("AID"), + rs.getInt("UserID"), + rs.getString("content"), + rs.getInt("Votes"), + qid, + rs.getString("DateTime") + )); + } + rs.close(); + stmt.close(); + } catch (SQLException ex) { + + } + return answers; + } + + /** + * Web service operation + * + * @param access_token + * @param qid + * @param content + * @return + * @throws java.net.MalformedURLException + */ + @WebMethod(operationName = "createAnswer") + public String createAnswer(@WebParam(name = "access_token") String access_token, @WebParam(name = "qid") int qid, @WebParam(name = "content") String content) throws MalformedURLException, IOException { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + URL IS = new URL("http://localhost:8082/Identity_Service/TokenValidator"); + HttpURLConnection connection = null; + connection = (HttpURLConnection)IS.openConnection(); + connection.setRequestMethod("POST"); + connection.setDoInput(true); + connection.setDoOutput(true); + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + int userID = 8; + try { + stmt = conn.createStatement(); + String sqlA = "INSERT INTO answer VALUES (0,?,?,0,?,?)"; + String sqlQ = "UPDATE question SET Answers=Answers+1 WHERE qid = ?"; + PreparedStatement pstmtA = conn.prepareStatement(sqlA); + PreparedStatement pstmtQ = conn.prepareStatement(sqlQ); + pstmtA.setInt(1, userID); + pstmtA.setString(2, content); + pstmtA.setInt(3, qid); + SimpleDateFormat ft = new SimpleDateFormat("y-M-d H:m:s"); + pstmtA.setString(4, ft.format(new java.util.Date())); + pstmtQ.setInt(1, qid); + int a = pstmtA.executeUpdate(); + int b = pstmtQ.executeUpdate(); + stmt.close(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } + + /** + * Web service operation + * @param access_token + * @param AID + * @param voteUp + * @return + */ + @WebMethod(operationName = "voteAnswer") + public String voteAnswer(@WebParam(name = "access_token") String access_token, @WebParam(name = "AID") int AID, @WebParam(name = "voteUp") boolean voteUp) { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + //Update ke DB : UPDATE question SET topic = title, content = new content, datetime = new datetime WHERE qid = 'qid' + try { + stmt = conn.createStatement(); + String sql; + if (voteUp) { + sql = "UPDATE answer SET Votes=Votes+1 WHERE aid = ?"; + } else { + sql = "UPDATE answer SET Votes=Votes-1 WHERE aid = ?"; + } + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, AID); + int a = pstmt.executeUpdate(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } +} diff --git a/StackExchange WS/src/java/DB/Database.java b/StackExchange WS/src/java/DB/Database.java new file mode 100644 index 00000000..e64a0340 --- /dev/null +++ b/StackExchange WS/src/java/DB/Database.java @@ -0,0 +1,26 @@ +package DB; +import java.sql.*; +/** + * + * @author M. Fauzan Naufan + */ +public class Database { + public Connection connect() { + Connection conn = null; + try { + Class.forName("com.mysql.jdbc.Driver"); + System.out.println("Driver loaded!"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("Cannot find the driver in the classpath!", e); + } + + String url = "jdbc:mysql://localhost:3306/stackexchange"; + String username = "root"; + String password = ""; + try { + conn = DriverManager.getConnection(url, username, password); + } catch (SQLException se) { + } + return conn; + } +} diff --git a/StackExchange WS/src/java/QuestionModel/Question.java b/StackExchange WS/src/java/QuestionModel/Question.java new file mode 100644 index 00000000..f72686da --- /dev/null +++ b/StackExchange WS/src/java/QuestionModel/Question.java @@ -0,0 +1,44 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package QuestionModel; + +import javax.xml.bind.annotation.XmlElement; + +/** + * + * @author M. Fauzan Naufan + */ +public class Question { + @XmlElement(name="QID", required=true) + private final int qid; + @XmlElement(name="UserID", required=true) + private final int userid; + @XmlElement(name="Topic", required=true) + private String topic; + @XmlElement(name="Content", required=true) + private String content; + @XmlElement(name="Votes", required=true) + private int votes; + @XmlElement(name="DateTime", required=true) + private String datetime; + @XmlElement(name="Answers", required=true) + private int answers; + + public Question() { + qid = 0; + userid = 0; + } + + public Question(int qid1, int userid1, String topic1, String content1, int votes1, String datetime1, int answers1) { + qid = qid1; + userid=userid1; + topic=topic1; + content=content1; + votes=votes1; + datetime=datetime1; + answers=answers1; + } +} diff --git a/StackExchange WS/src/java/QuestionModel/QuestionWS.java b/StackExchange WS/src/java/QuestionModel/QuestionWS.java new file mode 100644 index 00000000..bbf17988 --- /dev/null +++ b/StackExchange WS/src/java/QuestionModel/QuestionWS.java @@ -0,0 +1,223 @@ +package QuestionModel; + +import DB.Database; +import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import javax.jws.*; + +/** + * + * @author M. Fauzan Naufan + */ +@WebService(serviceName = "QuestionWS") +public class QuestionWS { + + /** + * Web service operation + * + * @param access_token + * @param title + * @param content + * @return + */ + @WebMethod(operationName = "createQuestion") + public String createQuestion(@WebParam(name = "access_token") String access_token, @WebParam(name = "title") String title, @WebParam(name = "content") String content) { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + int userID = 8; + try { + stmt = conn.createStatement(); + String sql = "INSERT INTO question VALUES (0,?,?,?,0,?,0)"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, userID); + pstmt.setString(2, title); + pstmt.setString(3, content); + SimpleDateFormat ft = new SimpleDateFormat("y-M-d H:m:s"); + pstmt.setString(4, ft.format(new Date())); + int a = pstmt.executeUpdate(); + stmt.close(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } + + /** + * Web service operation + * + * @param qid + * @param access_token + * @param title + * @param content + * @return + */ + @WebMethod(operationName = "editQuestion") + public String editQuestion(@WebParam(name = "qid") int qid, @WebParam(name = "access_token") String access_token, @WebParam(name = "title") String title, @WebParam(name = "content") String content) { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + //Update ke DB : UPDATE question SET topic = title, content = new content, datetime = new datetime WHERE qid = 'qid' + try { + stmt = conn.createStatement(); + String sql = "UPDATE question SET topic=?, content=?, datetime=? WHERE qid=?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setString(1, title); + pstmt.setString(2, content); + SimpleDateFormat ft = new SimpleDateFormat("y-M-d H:m:s"); + pstmt.setString(3, ft.format(new Date())); + pstmt.setInt(4, qid); + int a = pstmt.executeUpdate(); + stmt.close(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } + + /** + * Web service operation + * + * @param qid + * @param access_token + * @return + */ + @WebMethod(operationName = "deleteQuestion") + public String deleteQuestion(@WebParam(name = "qid") int qid, @WebParam(name = "access_token") String access_token) { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + try { + stmt = conn.createStatement(); + String sqlQ = "DELETE FROM question WHERE qid = ?"; + String sqlA = "DELETE FROM answer WHERE qid = ?"; + PreparedStatement pstmtQ = conn.prepareStatement(sqlQ); + PreparedStatement pstmtA = conn.prepareStatement(sqlA); + pstmtQ.setInt(1, qid); + pstmtA.setInt(1, qid); + int a = pstmtQ.executeUpdate(); + int b = pstmtA.executeUpdate(); + stmt.close(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } + + /** + * Web service operation + * + * @param access_token + * @param qid + * @param voteUp + * @return + */ + @WebMethod(operationName = "voteQuestion") + public String voteQuestion(@WebParam(name = "access_token") String access_token, @WebParam(name = "qid") int qid, @WebParam(name = "voteUp") boolean voteUp) { + Connection conn = new Database().connect(); + Statement stmt; + //1.HTTP Request connection ke Identity Service, untuk memastikan pemilik access_token + //2a.Jika access token kadaluarsa, respons expired token + //2b.Jika access token tidak valid, respons error + //2c.Jika access token valid, ambil user ID + //Update ke DB : UPDATE question SET topic = title, content = new content, datetime = new datetime WHERE qid = 'qid' + try { + stmt = conn.createStatement(); + String sql; + if (voteUp) { + sql = "UPDATE question SET Votes=Votes+1 WHERE qid = ?"; + } else { + sql = "UPDATE question SET Votes=Votes-1 WHERE qid = ?"; + } + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, qid); + int a = pstmt.executeUpdate(); + return "Respons oke!"; + } catch (SQLException se) { + return "Gagal!"; + } + } + + /** + * Web service operation + * + * @return + */ + @WebMethod(operationName = "getAllQuestion") + public ArrayList getAllQuestion() { + Connection conn = new Database().connect(); + Statement stmt; + ResultSet rs; + + ArrayList questions = new ArrayList<>(); + + try { + stmt = conn.createStatement(); + String sql = "SELECT * FROM question ORDER BY DateTime DESC"; + + PreparedStatement pstmt = conn.prepareStatement(sql); + rs = pstmt.executeQuery(); + while (rs.next()) { + questions.add(new Question(rs.getInt("QID"), + rs.getInt("UserID"), + rs.getString("Topic"), + rs.getString("Content"), + rs.getInt("Votes"), + rs.getString("DateTime"), + rs.getInt("Answers") + )); + } + } catch (SQLException ex) { + + } + return questions; + } + + /** + * Web service operation + * + * @param qid + * @return + */ + @WebMethod(operationName = "getQuestionByQID") + public ArrayList getQuestionByQID(@WebParam(name = "qid") int qid) { + Connection conn = new Database().connect(); + Statement stmt; + ResultSet rs; + + ArrayList questions = new ArrayList<>(); + + try { + stmt = conn.createStatement(); + String sql = "SELECT * FROM question WHERE qid = ?"; + + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, qid); + rs = pstmt.executeQuery(); + while (rs.next()) { + questions.add(new Question(rs.getInt("QID"), + rs.getInt("UserID"), + rs.getString("Topic"), + rs.getString("Content"), + rs.getInt("Votes"), + rs.getString("DateTime"), + rs.getInt("Answers") + )); + } + } catch (SQLException ex) { + + } + return questions; + } +} diff --git a/StackExchange WS/src/java/UserModel/User.java b/StackExchange WS/src/java/UserModel/User.java new file mode 100644 index 00000000..6069169a --- /dev/null +++ b/StackExchange WS/src/java/UserModel/User.java @@ -0,0 +1,30 @@ +package UserModel; + +import javax.xml.bind.annotation.XmlElement; + +/** + * + * @author M. Fauzan Naufan + */ +public class User { + + @XmlElement(name = "UserID", required = true) + private final int userid; + @XmlElement(name = "Nama", required = true) + private String nama; + @XmlElement(name = "Email", required = true) + private String email; + @XmlElement(name = "Password", required = true) + private String password; + + public User() { + userid = 0; + } + + public User(int userid1, String nama1, String email1, String password1) { + userid = userid1; + nama = nama1; + email = email1; + password = password1; + } +} diff --git a/StackExchange WS/src/java/UserModel/UserWS.java b/StackExchange WS/src/java/UserModel/UserWS.java new file mode 100644 index 00000000..595831e6 --- /dev/null +++ b/StackExchange WS/src/java/UserModel/UserWS.java @@ -0,0 +1,86 @@ +package UserModel; + +import DB.Database; +import java.sql.*; +import java.util.ArrayList; +import javax.jws.*; + +/** + * + * @author M. Fauzan Naufan + */ +@WebService(serviceName = "UserWS") +public class UserWS { + + /** + * Web service operation + * + * @param nama + * @param email + * @param password + * @return + */ + @WebMethod(operationName = "register") + public String register(@WebParam(name = "nama") String nama, @WebParam(name = "email") String email, @WebParam(name = "password") String password) { + Connection conn = new Database().connect(); + Statement stmt; + ResultSet rs; + int i; + + try { + i = 0; + stmt = conn.createStatement(); + String sqlCheck = "SELECT * FROM user WHERE email = ?"; + PreparedStatement pstmtCheck = conn.prepareStatement(sqlCheck); + pstmtCheck.setString(1, email); + rs = pstmtCheck.executeQuery(); + while (rs.next()) { + i++; + } + if (i > 0) { + return "Error! Karena email tersebut sudah pernah didaftarkan"; + } else { + String sqlMain = "INSERT INTO user VALUES (0,?,?,?)"; + PreparedStatement pstmtMain = conn.prepareStatement(sqlMain); + pstmtMain.setString(1, nama); + pstmtMain.setString(2, email); + pstmtMain.setString(3, password); + int a = pstmtMain.executeUpdate(); + stmt.close(); + return "Sukses!"; + } + } catch (SQLException ex) { + return "Error!"; + } + } + + /** + * Web service operation + * @param UserID + * @return + */ + @WebMethod(operationName = "getUser") + public ArrayList getUser(@WebParam(name = "UserID") int UserID) { + Connection conn = new Database().connect(); + Statement stmt; + ResultSet rs; + ArrayList users = new ArrayList(); + try { + stmt = conn.createStatement(); + String sql = "SELECT * FROM user WHERE UserID = ?"; + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, UserID); + rs = pstmt.executeQuery(); + while (rs.next()) { + users.add(new User(rs.getInt("UserID"), + rs.getString("Nama"), + rs.getString("Email"), + rs.getString("Password") + )); + } + } catch (SQLException ex) { + + } + return users; + } +} diff --git a/StackExchange WS/web/WEB-INF/glassfish-web.xml b/StackExchange WS/web/WEB-INF/glassfish-web.xml new file mode 100644 index 00000000..f1b6fadb --- /dev/null +++ b/StackExchange WS/web/WEB-INF/glassfish-web.xml @@ -0,0 +1,11 @@ + + + + /StackExchange_WS + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/StackExchange WS/web/WEB-INF/web.xml b/StackExchange WS/web/WEB-INF/web.xml new file mode 100644 index 00000000..6058a367 --- /dev/null +++ b/StackExchange WS/web/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + + + + 30 + + + diff --git a/StackExchange WS/web/index.html b/StackExchange WS/web/index.html new file mode 100644 index 00000000..c627c249 --- /dev/null +++ b/StackExchange WS/web/index.html @@ -0,0 +1,16 @@ + + + + + TODO supply a title + + + + +
TODO write content
+ +