Skip to content
Snippets Groups Projects
Commit dffe8955 authored by David's avatar David
Browse files
parents 4dfa5f49 85467017
Branches
No related merge requests found
File added
......@@ -4,9 +4,10 @@ import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import java.util.List;
//Service Endpoint Interface
@WebService
@WebService (name = "ProfileService", portName = "ProfilePort")
@SOAPBinding(style = Style.RPC)
public interface IProfile {
@WebMethod public Account getActiveUser(String accessToken);
......
......@@ -4,7 +4,6 @@ import javax.xml.ws.Endpoint;
//Endpoint publisher
public class Main{
public static void main(String[] args) {
Order order = new Order();
order.PuttransactionDetails("a", 2, "jakarta", "bandung", 4, "mantep gaans");
......
package com.informatika.ojek.webservice;
import javax.jws.WebService;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
//Service Implementation
@WebService(endpointInterface = "com.informatika.ojek.webservice.IProfile")
......@@ -9,7 +12,7 @@ public class Profile implements IProfile {
boolean isTokenValid = true; //request identity service
int id = 1; //request identity service
if (isTokenValid) {
//QUERY getAccount
//QUERY getAccount ke identity service
String name = "Diki Ardian";
String username = "dikiardian";
String email = "diki@gmail.com";
......@@ -22,12 +25,29 @@ public class Profile implements IProfile {
return null;
}
}
@Override public String[] getLocation(String accessToken) {
@Override public String[] getLocation(String accessToken){
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY getLocation
return new String[]{"a", "b"};
List<String> result = new ArrayList<>();
try {
String query = "SELECT * FROM pref_loc WHERE IDDriver=" + id + ";";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/projek";
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery(query);
while (rs.next()) {
result.add(rs.getString("Location"));
}
conn.close();
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
return result.toArray(new String[0]);
} else {
return null;
}
......@@ -36,8 +56,20 @@ public class Profile implements IProfile {
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY addLocation
return true;
try {
String query = "INSERT INTO pref_loc (IDDriver, Location) VALUES (" + id + ", '" + location + "');";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/projek";
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stmt = conn.createStatement();
stmt.executeUpdate(query);
conn.close();
return true;
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
return false;
}
} else {
return false;
}
......@@ -46,8 +78,20 @@ public class Profile implements IProfile {
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY delLocation
return true;
try {
String query = "DELETE FROM pref_loc WHERE IDDriver=" + id + " AND Location='" + location + "';";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/projek";
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stmt = conn.createStatement();
stmt.executeUpdate(query);
conn.close();
return true;
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
return false;
}
} else {
return false;
}
......@@ -56,8 +100,20 @@ public class Profile implements IProfile {
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY updateLocation
return true;
try {
String query = "UPDATE pref_loc SET Location = '" + newLocation + "' WHERE IDDriver=" + id + " AND Location='" + oldLocation + "';";
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/projek";
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stmt = conn.createStatement();
stmt.executeUpdate(query);
conn.close();
return true;
} catch (IllegalAccessException | InstantiationException | SQLException | ClassNotFoundException e) {
e.printStackTrace();
return false;
}
} else {
return false;
}
......@@ -66,7 +122,7 @@ public class Profile implements IProfile {
boolean isTokenValid = true; //request identity service;
int id = 1; //request identity service
if (isTokenValid) {
//QUERY updateProfile
//QUERY updateProfile dari identity service
return true;
} else {
return false;
......
package com.informatika.ojek.webservice;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class test {
public static void main(String[] args) {
try {
String url = "http://localhost:9999/ws/profile?wsdl";
String namespace = "http://webservice.ojek.informatika.com/";
QName serviceQN = new QName(namespace, "ProfileService");
Service service = Service.create(new URL(url), serviceQN);
String portName = "ProfilePort";
QName portQN = new QName(namespace, portName);
IProfile sample = service.getPort(portQN, IProfile.class);
// String[] hasil = sample.getLocation("blabla");
// System.out.println(hasil[0]);
// System.out.println(hasil[1]);
//
// if (sample.addPreferredLocation("blabla", "Cisitu")) {
// System.out.println("sukses menambahkan");
// } else {
// System.out.println("gagal");
// }
// if (sample.delPreferredLocation("blabla", "singapur")) {
// System.out.println("sukses menghapus");
// } else {
// System.out.println("gagal");
// }
if (sample.updatePreferredLocation("blabla", "kucing", "Tamansari")) {
System.out.println("sukses mengupdate");
} else {
System.out.println("gagal");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment