Skip to content
Snippets Groups Projects
Commit 7775eb55 authored by Alkhwarizm's avatar Alkhwarizm
Browse files

Created SOAP webservices

parents
Branches
No related merge requests found
Showing
with 711 additions and 0 deletions
package com.ojol;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.ojol package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _ValidateToken_QNAME = new QName("http://service.identity/", "validateToken");
private final static QName _ValidateTokenResponse_QNAME = new QName("http://service.identity/", "validateTokenResponse");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.ojol
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link ValidateTokenResponse }
*
*/
public ValidateTokenResponse createValidateTokenResponse() {
return new ValidateTokenResponse();
}
/**
* Create an instance of {@link ValidateToken }
*
*/
public ValidateToken createValidateToken() {
return new ValidateToken();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link ValidateToken }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://service.identity/", name = "validateToken")
public JAXBElement<ValidateToken> createValidateToken(ValidateToken value) {
return new JAXBElement<ValidateToken>(_ValidateToken_QNAME, ValidateToken.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link ValidateTokenResponse }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://service.identity/", name = "validateTokenResponse")
public JAXBElement<ValidateTokenResponse> createValidateTokenResponse(ValidateTokenResponse value) {
return new JAXBElement<ValidateTokenResponse>(_ValidateTokenResponse_QNAME, ValidateTokenResponse.class, null, value);
}
}
package com.ojol;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for validateToken complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="validateToken">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="arg0" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "validateToken", propOrder = {
"arg0"
})
public class ValidateToken {
protected String arg0;
/**
* Gets the value of the arg0 property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getArg0() {
return arg0;
}
/**
* Sets the value of the arg0 property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setArg0(String value) {
this.arg0 = value;
}
}
package com.ojol;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for validateTokenResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="validateTokenResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="return" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "validateTokenResponse", propOrder = {
"_return"
})
public class ValidateTokenResponse {
@XmlElement(name = "return")
protected String _return;
/**
* Gets the value of the return property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getReturn() {
return _return;
}
/**
* Sets the value of the return property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setReturn(String value) {
this._return = value;
}
}
package com.ojol;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.7-b01
* Generated source version: 2.2
*
*/
@WebService(name = "ValidatorService", targetNamespace = "http://service.identity/")
@XmlSeeAlso({
ObjectFactory.class
})
public interface ValidatorService {
/**
*
* @param arg0
* @return
* returns java.lang.String
*/
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "validateToken", targetNamespace = "http://service.identity/", className = "com.ojol.ValidateToken")
@ResponseWrapper(localName = "validateTokenResponse", targetNamespace = "http://service.identity/", className = "com.ojol.ValidateTokenResponse")
@Action(input = "http://service.identity/ValidatorService/validateTokenRequest", output = "http://service.identity/ValidatorService/validateTokenResponse")
public String validateToken(
@WebParam(name = "arg0", targetNamespace = "")
String arg0);
}
package com.ojol;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.7-b01
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "ValidatorServiceService", targetNamespace = "http://service.identity/", wsdlLocation = "file:/home/iqbal/Documents/Kuliah/Semester 5/WBD/TugasBesar2_2017/ojol-webservice/src/com/ojol/validator.wsdl")
public class ValidatorServiceService
extends Service
{
private final static URL VALIDATORSERVICESERVICE_WSDL_LOCATION;
private final static WebServiceException VALIDATORSERVICESERVICE_EXCEPTION;
private final static QName VALIDATORSERVICESERVICE_QNAME = new QName("http://service.identity/", "ValidatorServiceService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/home/iqbal/Documents/Kuliah/Semester 5/WBD/TugasBesar2_2017/ojol-webservice/src/com/ojol/validator.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
VALIDATORSERVICESERVICE_WSDL_LOCATION = url;
VALIDATORSERVICESERVICE_EXCEPTION = e;
}
public ValidatorServiceService() {
super(__getWsdlLocation(), VALIDATORSERVICESERVICE_QNAME);
}
public ValidatorServiceService(WebServiceFeature... features) {
super(__getWsdlLocation(), VALIDATORSERVICESERVICE_QNAME, features);
}
public ValidatorServiceService(URL wsdlLocation) {
super(wsdlLocation, VALIDATORSERVICESERVICE_QNAME);
}
public ValidatorServiceService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, VALIDATORSERVICESERVICE_QNAME, features);
}
public ValidatorServiceService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public ValidatorServiceService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns ValidatorService
*/
@WebEndpoint(name = "ValidatorServicePort")
public ValidatorService getValidatorServicePort() {
return super.getPort(new QName("http://service.identity/", "ValidatorServicePort"), ValidatorService.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns ValidatorService
*/
@WebEndpoint(name = "ValidatorServicePort")
public ValidatorService getValidatorServicePort(WebServiceFeature... features) {
return super.getPort(new QName("http://service.identity/", "ValidatorServicePort"), ValidatorService.class, features);
}
private static URL __getWsdlLocation() {
if (VALIDATORSERVICESERVICE_EXCEPTION!= null) {
throw VALIDATORSERVICESERVICE_EXCEPTION;
}
return VALIDATORSERVICESERVICE_WSDL_LOCATION;
}
}
@javax.xml.bind.annotation.XmlSchema(namespace = "http://service.identity/")
package com.ojol;
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01 svn-revision#${svn.Last.Changed.Rev}. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01 svn-revision#${svn.Last.Changed.Rev}. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.identity/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.identity/" name="ValidatorServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://service.identity/" schemaLocation="http://localhost:8001/validator?xsd=1"/>
</xsd:schema>
</types>
<message name="validateToken">
<part name="parameters" element="tns:validateToken"/>
</message>
<message name="validateTokenResponse">
<part name="parameters" element="tns:validateTokenResponse"/>
</message>
<portType name="ValidatorService">
<operation name="validateToken">
<input wsam:Action="http://service.identity/ValidatorService/validateTokenRequest" message="tns:validateToken"/>
<output wsam:Action="http://service.identity/ValidatorService/validateTokenResponse" message="tns:validateTokenResponse"/>
</operation>
</portType>
<binding name="ValidatorServicePortBinding" type="tns:ValidatorService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="validateToken">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ValidatorServiceService">
<port name="ValidatorServicePort" binding="tns:ValidatorServicePortBinding">
<soap:address location="http://localhost:8001/validator"/>
</port>
</service>
</definitions>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01 svn-revision#${svn.Last.Changed.Rev}. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.7-b01 svn-revision#${svn.Last.Changed.Rev}. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.identity/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.identity/" name="ValidatorServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://service.identity/" schemaLocation="http://localhost:8001/validator?xsd=1"/>
</xsd:schema>
</types>
<message name="validateToken">
<part name="parameters" element="tns:validateToken"/>
</message>
<message name="validateTokenResponse">
<part name="parameters" element="tns:validateTokenResponse"/>
</message>
<portType name="ValidatorService">
<operation name="validateToken">
<input wsam:Action="http://service.identity/ValidatorService/validateTokenRequest" message="tns:validateToken"/>
<output wsam:Action="http://service.identity/ValidatorService/validateTokenResponse" message="tns:validateTokenResponse"/>
</operation>
</portType>
<binding name="ValidatorServicePortBinding" type="tns:ValidatorService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="validateToken">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ValidatorServiceService">
<port name="ValidatorServicePort" binding="tns:ValidatorServicePortBinding">
<soap:address location="http://localhost:8001/validator"/>
</port>
</service>
</definitions>
\ No newline at end of file
package main.entity;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class User {
private int id;
private String fullname;
private String username;
private String email;
private String password;
private String phone;
private String photo;
private short isDriver;
public User() {
}
public User(int id, String fullname, String username, String email, String password, String phone, String photo, short isDriver) {
this.id = id;
this.fullname = fullname;
this.username = username;
this.email = email;
this.password = password;
this.phone = phone;
this.photo = photo;
this.isDriver = isDriver;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
public short getIsDriver() {
return isDriver;
}
public void setIsDriver(short isDriver) {
this.isDriver = isDriver;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", fullname='" + fullname + '\'' +
", username='" + username + '\'' +
", email='" + email + '\'' +
", password='" + password + '\'' +
", phone='" + phone + '\'' +
", photo='" + photo + '\'' +
", isDriver=" + isDriver +
'}';
}
}
package main.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import main.entity.User;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class UserService {
public User getUserByUsername(String username) {
String url = "http://localhost:8080/ojol/users?username=" + username;
ObjectMapper mapper = new ObjectMapper();
User user = new User();
try {
user = mapper.readValue(new URL(url), User.class);
} catch (Exception e) {
e.printStackTrace();
}
return user;
}
}
package main.service;
import main.entity.User;
import main.util.Authenticator;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.util.Objects;
@WebService(targetNamespace = "com.ojol", serviceName = "ValidatorService")
public class ValidatorService {
@WebMethod
public User validateToken(String token) {
String validation = Authenticator.getValidation(token);
User user;
if (Objects.equals(validation, "unauthorized") || Objects.equals(validation, "expired")) {
return null;
} else {
user = new UserService().getUserByUsername(validation);
}
return user;
}
public static void main(String[] argv) {
Object implementor = new ValidatorService ();
String address = "http://localhost:8002/ValidatorService";
Endpoint.publish(address, implementor);
}
}
package main.util;
import com.ojol.ValidateToken;
import com.ojol.ValidatorService;
import com.ojol.ValidatorServiceService;
import java.util.Objects;
public class Authenticator {
public static boolean isTokenValid(String token) {
String validation = getValidation(token);
if (Objects.equals(validation, "unauthorized") || Objects.equals(validation, "expired")) {
return false;
}
return true;
}
public static String getValidation (String token) {
ValidatorServiceService validator = new ValidatorServiceService();
ValidatorService validatorService = validator.getValidatorServicePort();
String validation = validatorService.validateToken(token);
return validation;
}
}
package main.util;
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_OJOL_URL = "jdbc:mysql://localhost:3306/db_ojol?useSSL=false";
// Database credentials
static final String USER = "root";
static final String PASS = "iqbal";
static Connection connection = null;
public static Connection getOjolConnection() {
try {
Class.forName(JDBC_DRIVER).newInstance();
connection = DriverManager.getConnection(DB_OJOL_URL, USER, PASS);
return connection;
} catch (Exception e) {
System.out.println("Ojol DB Error: " + e.getMessage());
e.printStackTrace();
}
return null;
}
}
package main.util;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestDB {
public static void main(String[] args) {
try {
Connection conn = MySQLConnection.getOjolConnection();
Statement stmt = conn.createStatement();
String query = "SELECT * FROM preferred_location";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
System.out.println(rs.getInt("id_driver"));
System.out.println(rs.getString("location"));
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name='HelloWorld'
implementation='example.HelloWorld'
url-pattern='/services/HelloWorld'/>
<endpoint
name='ValidatorService'
implementation='main.service.ValidatorService'
url-pattern='/services/ValidatorService'/>
</endpoints>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<description>JAX-WS endpoint</description>
<display-name>WSServlet</display-name>
<servlet-name>WSServlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WSServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: iqbal
Date: 08/11/17
Time: 15:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
$END$
</body>
</html>
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