diff --git a/.gitignore b/.gitignore index 8a9d8ad20f0dd87d29b199bd34211a5bffecb84d..d3a936bfde3f471f784f0a8b360faaed5a63e48f 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,7 @@ build/ ### Mac OS ### .DS_Store -.env \ No newline at end of file +.env +db +src/main/resources/posters/poster* +src/main/resources/trailers/trailer* \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 37092cb2d2c9defa4d9cea3f0ed91e31847f0242..2fce26df0011b9f3e8a332595103898493c9d583 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,14 +1,13 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ExternalStorageConfigurationManager" enabled="true" /> - <component name="MavenProjectsManager"> - <option name="originalFiles"> - <list> - <option value="$PROJECT_DIR$/pom.xml" /> - </list> - </option> - </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8 (WSL)" project-jdk-type="JavaSDK"> - <output url="file://$PROJECT_DIR$/out" /> - </component> +<project version="4"> + <component name="ExternalStorageConfigurationManager" enabled="true" /> + <component name="MavenProjectsManager"> + <option name="originalFiles"> + <list> + <option value="$PROJECT_DIR$/pom.xml" /> + </list> + </option> + </component> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8 (WSL)" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/out" /> + </component> </project> \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c5e0e5e72b64182e5a428527b162cb619c61ff14 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM maven:3-amazoncorretto-8 AS build +WORKDIR /app +COPY src /usr/src/app/src +COPY pom.xml /usr/src/app +RUN mvn -f /usr/src/app/pom.xml clean package + +FROM amazoncorretto:8-alpine-jdk +EXPOSE 8082 +COPY --from=build /usr/src/app/target/drawl_soap-jar-with-dependencies.jar /usr/src/app/drawl_soap.jar +CMD ["java","-jar","/usr/src/app/service_soap.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1ef90d8fd7e4785f039ce1b6f19ba2468b399d5f..e028101feb8679d9eba1c28230592580c5715d2b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.soapServiceV2</groupId> - <artifactId>soapServiceV2</artifactId> - <version>1.0-SNAPSHOT</version> + <groupId>org.soapService</groupId> + <artifactId>soapService</artifactId> + <version>2.0</version> <properties> <maven.compiler.source>8</maven.compiler.source> @@ -31,6 +31,12 @@ <artifactId>mysql-connector-j</artifactId> <version>8.1.0</version> </dependency> + <!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core --> + <dependency> + <groupId>org.apache.tika</groupId> + <artifactId>tika-core</artifactId> + <version>2.9.1</version> + </dependency> </dependencies> <build> @@ -42,7 +48,7 @@ <configuration> <archive> <manifest> - <mainClass>org.soapServiceV2.App</mainClass> + <mainClass>org.soapService.App</mainClass> </manifest> </archive> <descriptorRefs> @@ -60,6 +66,6 @@ </executions> </plugin> </plugins> - <finalName>service_soap</finalName> + <finalName>drawl_soap</finalName> </build> </project> \ No newline at end of file diff --git a/schema/schema.sql b/schema/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..c29f58b458c0cf8faeaa8a5fd9fe2063425d7581 --- /dev/null +++ b/schema/schema.sql @@ -0,0 +1,81 @@ +-- LOGS + +CREATE TABLE IF NOT EXISTS logs ( + id SERIAL PRIMARY KEY, + + req_desc VARCHAR(10000) NOT NULL, + ip VARCHAR(50) NOT NULL, + endpoint_dest VARCHAR(255) NOT NULL, + + created_at TIMESTAMP DEFAULT NOW() +); + +-- CATALOG_REQUESTS + +CREATE TABLE IF NOT EXISTS catalog_requests ( + id SERIAL PRIMARY KEY, + uuid VARCHAR(36) UNIQUE NOT NULL, + + title VARCHAR(255) NOT NULL, + description VARCHAR(255), + poster VARCHAR(255) NOT NULL, + trailer VARCHAR(255), + category ENUM('ANIME', 'DRAMA', 'MIXED'), + + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() +); + +DELIMITER $$ + CREATE TRIGGER IF NOT EXISTS catalog_requests_updated_at + BEFORE UPDATE ON catalog_requests FOR EACH ROW + BEGIN + SET NEW.updated_at = NOW(); + END; +$$ +DELIMITER ; + +-- ACCOUNT_VERIFICATION_REQUEST + +CREATE TABLE account_verification_requests ( + id SERIAL PRIMARY KEY, + uuid VARCHAR(36) UNIQUE NOT NULL, + + user_id INT UNIQUE NOT NULL, + status ENUM('PENDING', 'ACCEPTED', 'REJECTED'), + + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() +); + +DELIMITER $$ + CREATE TRIGGER IF NOT EXISTS account_verification_requests_updated_at + BEFORE UPDATE ON account_verification_requests FOR EACH ROW + BEGIN + SET NEW.updated_at = NOW(); + END; +$$ +DELIMITER ; + +-- REPORT_USERS + +CREATE TABLE report_users ( + id SERIAL PRIMARY KEY, + uuid VARCHAR(36) UNIQUE NOT NULL, + + content VARCHAR(255) NOT NULL, + reporter_id INT NOT NULL, + reported_id INT NOT NULL, + + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() +); + +DELIMITER $$ + CREATE TRIGGER IF NOT EXISTS report_users_updated_at + BEFORE UPDATE ON report_users FOR EACH ROW + BEGIN + SET NEW.updated_at = NOW(); + END; +$$ +DELIMITER ; \ No newline at end of file diff --git a/src/main/java/org/soapServiceV2/App.java b/src/main/java/org/soapService/App.java similarity index 60% rename from src/main/java/org/soapServiceV2/App.java rename to src/main/java/org/soapService/App.java index 5b8ef8989644b220c19f8a744987e0d2d6942599..ce70d1348229da90c20ab479028fa911b974529f 100644 --- a/src/main/java/org/soapServiceV2/App.java +++ b/src/main/java/org/soapService/App.java @@ -1,14 +1,14 @@ -package org.soapServiceV2; +package org.soapService; -import org.soapServiceV2.Services.AccountVerificationRequestServiceImpl; -import org.soapServiceV2.Services.CatalogRequestServiceImpl; -import org.soapServiceV2.Services.ReportUserServiceImpl; +import org.soapService.Services.AccountVerificationRequestServiceImpl; +import org.soapService.Services.CatalogRequestServiceImpl; +import org.soapService.Services.ReportUserServiceImpl; import javax.xml.ws.Endpoint; public class App { public static void main(String[] args) { - String baseUrl = "http://0.0.0.0:8082/"; + String baseUrl = "http://0.0.0.0:8083/"; // Register services; Endpoint.publish(baseUrl + "catalog-request", new CatalogRequestServiceImpl()); diff --git a/src/main/java/org/soapServiceV2/Config/Database.java b/src/main/java/org/soapService/Config/Database.java similarity index 92% rename from src/main/java/org/soapServiceV2/Config/Database.java rename to src/main/java/org/soapService/Config/Database.java index 3542f268cc671d320120a0a83f62ac150f635de8..6df129744fa15e7960c080f9c0264b8846732e7c 100644 --- a/src/main/java/org/soapServiceV2/Config/Database.java +++ b/src/main/java/org/soapService/Config/Database.java @@ -1,4 +1,4 @@ -package org.soapServiceV2.Config; +package org.soapService.Config; import io.github.cdimascio.dotenv.Dotenv; diff --git a/src/main/java/org/soapServiceV2/Domain/AccountVerificationRequest.java b/src/main/java/org/soapService/Domain/AccountVerificationRequest.java similarity index 87% rename from src/main/java/org/soapServiceV2/Domain/AccountVerificationRequest.java rename to src/main/java/org/soapService/Domain/AccountVerificationRequest.java index 34be8011492441340f9d752411893051a4c55a4b..10d934946aa076b7ad2c9e2d9a8d63d59ca59c56 100644 --- a/src/main/java/org/soapServiceV2/Domain/AccountVerificationRequest.java +++ b/src/main/java/org/soapService/Domain/AccountVerificationRequest.java @@ -1,4 +1,4 @@ -package org.soapServiceV2.Domain; +package org.soapService.Domain; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/org/soapServiceV2/Domain/CatalogRequest.java b/src/main/java/org/soapService/Domain/CatalogRequest.java similarity index 88% rename from src/main/java/org/soapServiceV2/Domain/CatalogRequest.java rename to src/main/java/org/soapService/Domain/CatalogRequest.java index aefceced962ab944c7131acb40086a723fcbce1d..748ca790229147ed5a39d94b2e38b00a52769f41 100644 --- a/src/main/java/org/soapServiceV2/Domain/CatalogRequest.java +++ b/src/main/java/org/soapService/Domain/CatalogRequest.java @@ -1,4 +1,4 @@ -package org.soapServiceV2.Domain; +package org.soapService.Domain; import lombok.AllArgsConstructor; diff --git a/src/main/java/org/soapServiceV2/Domain/Log.java b/src/main/java/org/soapService/Domain/Log.java similarity index 86% rename from src/main/java/org/soapServiceV2/Domain/Log.java rename to src/main/java/org/soapService/Domain/Log.java index a69c8fd3cc5a2c9b3f2f93da38d177c9eedca4d9..d01c5f4d0e97d4fd20912299922776d99e6cdc6b 100644 --- a/src/main/java/org/soapServiceV2/Domain/Log.java +++ b/src/main/java/org/soapService/Domain/Log.java @@ -1,4 +1,4 @@ -package org.soapServiceV2.Domain; +package org.soapService.Domain; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/org/soapServiceV2/Domain/ReportUser.java b/src/main/java/org/soapService/Domain/ReportUser.java similarity index 87% rename from src/main/java/org/soapServiceV2/Domain/ReportUser.java rename to src/main/java/org/soapService/Domain/ReportUser.java index f3f5bc3b937ac495d058445bdff75b06750e13a1..fa3d37afe69ca0cc980df428f73ee5e8e3fdfbd2 100644 --- a/src/main/java/org/soapServiceV2/Domain/ReportUser.java +++ b/src/main/java/org/soapService/Domain/ReportUser.java @@ -1,4 +1,4 @@ -package org.soapServiceV2.Domain; +package org.soapService.Domain; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/org/soapService/Handlers/Handler.java b/src/main/java/org/soapService/Handlers/Handler.java new file mode 100644 index 0000000000000000000000000000000000000000..47b2d7552d55106ee419f99ba8120bcb2a736ec2 --- /dev/null +++ b/src/main/java/org/soapService/Handlers/Handler.java @@ -0,0 +1,99 @@ +package org.soapService.Handlers; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.xml.internal.ws.developer.JAXWSProperties; +import org.soapService.Domain.Log; +import org.soapService.Repository.LogRepository; +import org.w3c.dom.NodeList; + +import javax.xml.namespace.QName; +import javax.xml.soap.Node; +import javax.xml.soap.SOAPBody; +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.soap.SOAPHandler; +import javax.xml.ws.handler.soap.SOAPMessageContext; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class Handler implements SOAPHandler<SOAPMessageContext> { + // public static ThreadLocal<Log> threadLocal = new ThreadLocal<>(); + private static LogRepository logRepository = new LogRepository(); + + public Set<QName> getHeaders() { + return null; + } + + public boolean handleMessage(SOAPMessageContext context) { + Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); + HttpExchange httpExchange = (HttpExchange) context.get(JAXWSProperties.HTTP_EXCHANGE); + + if (!outboundProperty) { + String ip = httpExchange.getRemoteAddress().getAddress().toString().replace("/", ""); + String endpoint = httpExchange.getRequestURI().toString(); + String operation = ""; + Map<String, String> args = new HashMap<>(); + + try { + SOAPBody soapBody = context.getMessage().getSOAPBody(); + + // Get operation + Iterator bodyElements = soapBody.getChildElements(); + while (bodyElements.hasNext()) { + Object bodyElement = bodyElements.next(); + if (bodyElement instanceof Node) { + Node node = (Node) bodyElement; + if (node.getLocalName() != null) { + operation = node.getLocalName(); + NodeList nl = node.getChildNodes(); + for (int i = 0; i < nl.getLength(); i++) { + if (nl.item(i).getLocalName() != null) { + args.put(nl.item(i).getLocalName(), nl.item(i).getTextContent().substring(0, Math.min(nl.item(i).getTextContent().length(), 200))); + } + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + // Format + // [ClientName] -> [arg0]: <arg0_value>; [arg1]: <arg1_value> + String requestDescription = "[ClientName] ->" + (!args.isEmpty() ? " " : " No Args"); + for (Map.Entry<String, String> entry : args.entrySet()) { + requestDescription += "[" + entry.getKey() + "]:"; + requestDescription += entry.getValue() + "; "; + } + + // Write log + Log log = new Log(); + log.setIp(ip); + log.setEndpointDest(endpoint + "." + operation); + log.setReqDesc(requestDescription); + + try { + logRepository.add(log); + } catch (SQLException e) { + e.printStackTrace(); + } + + System.out.println("\nINFORMATION: "); + System.out.println("IP: " + ip); + System.out.println("Endpoint: " + endpoint + "." + operation); + System.out.println("Request Description: " + requestDescription); + } + + return true; + } + + public boolean handleFault(SOAPMessageContext context) { + return true; + } + + public void close(MessageContext context) { + + } +} diff --git a/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java b/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..6bf7e5a0ebb4a496668f455fe4143231bb358033 --- /dev/null +++ b/src/main/java/org/soapService/Repository/AccountVerificationRequestRepository.java @@ -0,0 +1,32 @@ +package org.soapService.Repository; + +import org.soapService.Domain.AccountVerificationRequest; + +import java.sql.SQLException; +import java.util.List; + +public class AccountVerificationRequestRepository implements BaseRepository<AccountVerificationRequest> { + public int add(AccountVerificationRequest data) throws SQLException { + return 0; + } + + public List<AccountVerificationRequest> getAll() throws SQLException { + return null; + } + + public AccountVerificationRequest getById(int id) throws SQLException { + return null; + } + + public void update(int id) throws SQLException { + + } + + public void deleteAll() throws SQLException { + + } + + public void delete(int id) throws SQLException { + + } +} diff --git a/src/main/java/org/soapService/Repository/BaseRepository.java b/src/main/java/org/soapService/Repository/BaseRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..ff841a1dd1afa59e86888858a0534685ce3b47b7 --- /dev/null +++ b/src/main/java/org/soapService/Repository/BaseRepository.java @@ -0,0 +1,19 @@ +package org.soapService.Repository; + +import java.sql.SQLException; +import java.util.List; + +public interface BaseRepository<T> { + public int add(T data) throws SQLException; + + public List<T> getAll() throws SQLException; + + public T getById(int id) throws SQLException; + + public void update(int id) throws SQLException; + + public void deleteAll() throws SQLException; + + public void delete(int id) throws SQLException; + +} diff --git a/src/main/java/org/soapService/Repository/CatalogReqeustRepository.java b/src/main/java/org/soapService/Repository/CatalogReqeustRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..ea45a0a66ebf4797b33620aa72ae9be8463b4bfa --- /dev/null +++ b/src/main/java/org/soapService/Repository/CatalogReqeustRepository.java @@ -0,0 +1,32 @@ +package org.soapService.Repository; + +import org.soapService.Domain.CatalogRequest; + +import java.sql.SQLException; +import java.util.List; + +public class CatalogReqeustRepository implements BaseRepository<CatalogRequest> { + public int add(CatalogRequest data) throws SQLException { + return 0; + } + + public List<CatalogRequest> getAll() throws SQLException { + return null; + } + + public CatalogRequest getById(int id) throws SQLException { + return null; + } + + public void update(int id) throws SQLException { + + } + + public void deleteAll() throws SQLException { + + } + + public void delete(int id) throws SQLException { + + } +} diff --git a/src/main/java/org/soapService/Repository/LogRepository.java b/src/main/java/org/soapService/Repository/LogRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..c9656220f78c335370a1160b034f483d944ff2bd --- /dev/null +++ b/src/main/java/org/soapService/Repository/LogRepository.java @@ -0,0 +1,44 @@ +package org.soapService.Repository; + +import org.soapService.Config.Database; +import org.soapService.Domain.Log; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; + +public class LogRepository implements BaseRepository<Log> { + + private static Connection conn = Database.getConnection(); + + public int add(Log data) throws SQLException { + String query = "INSERT INTO logs(req_desc, ip, endpoint_dest) VALUES (?, ?, ?)"; + PreparedStatement ps = conn.prepareStatement(query); + ps.setString(1, data.getReqDesc()); + ps.setString(2, data.getIp()); + ps.setString(3, data.getEndpointDest()); + + return ps.executeUpdate(); + } + + public List<Log> getAll() throws SQLException { + return null; + } + + public Log getById(int id) throws SQLException { + return null; + } + + public void update(int id) throws SQLException { + + } + + public void deleteAll() throws SQLException { + + } + + public void delete(int id) throws SQLException { + + } +} diff --git a/src/main/java/org/soapService/Repository/ReportUserRepository.java b/src/main/java/org/soapService/Repository/ReportUserRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..c1180fc2547618e4cc37205f6080103482350f95 --- /dev/null +++ b/src/main/java/org/soapService/Repository/ReportUserRepository.java @@ -0,0 +1,32 @@ +package org.soapService.Repository; + +import org.soapService.Domain.ReportUser; + +import java.sql.SQLException; +import java.util.List; + +public class ReportUserRepository implements BaseRepository<ReportUser> { + public int add(ReportUser data) throws SQLException { + return 0; + } + + public List<ReportUser> getAll() throws SQLException { + return null; + } + + public ReportUser getById(int id) throws SQLException { + return null; + } + + public void update(int id) throws SQLException { + + } + + public void deleteAll() throws SQLException { + + } + + public void delete(int id) throws SQLException { + + } +} diff --git a/src/main/java/org/soapService/Services/AccountVerificationRequestService.java b/src/main/java/org/soapService/Services/AccountVerificationRequestService.java new file mode 100644 index 0000000000000000000000000000000000000000..fc7411af3903ce3e43ddaaceb7d5c733f89015c1 --- /dev/null +++ b/src/main/java/org/soapService/Services/AccountVerificationRequestService.java @@ -0,0 +1,34 @@ +package org.soapService.Services; + +import org.soapService.Domain.AccountVerificationRequest; + +import javax.jws.HandlerChain; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.ws.RequestWrapper; +import java.util.List; + +@WebService +@HandlerChain(file = "handler-chain.xml") +public interface AccountVerificationRequestService { + @WebMethod(operationName = "GetRequests") + @RequestWrapper(className = "AccountVerificationRequestService.GetRequests") + public List<AccountVerificationRequest> getRequests(); + + @WebMethod(operationName = "CreateRequest") + @RequestWrapper(className = "AccountVerificationRequestService.CreateRequest") + public boolean createRequest(); + + @WebMethod(operationName = "AcceptRequest") + @RequestWrapper(className = "AccountVerificationRequestService.AcceptRequest") + public boolean acceptRequest(@WebParam(name = "userId") int userId); + + @WebMethod(operationName = "RejectRequest") + @RequestWrapper(className = "AccountVerificationRequestService.RejectRequest") + public boolean rejectRequest(@WebParam(name = "userId") int userId); + + @WebMethod(operationName = "DeleteRequest") + @RequestWrapper(className = "AccountVerificationRequestService.DeleteRequest") + public boolean deleteRequest(@WebParam(name = "requestId") int requestId); +} diff --git a/src/main/java/org/soapServiceV2/Services/AccountVerificationRequestServiceImpl.java b/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java similarity index 62% rename from src/main/java/org/soapServiceV2/Services/AccountVerificationRequestServiceImpl.java rename to src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java index de30348f6d37c7793aff0d44cebd76a0cfbefe6b..90ed4f2d3544fdc00e0d20d32c3d32fe301611a5 100644 --- a/src/main/java/org/soapServiceV2/Services/AccountVerificationRequestServiceImpl.java +++ b/src/main/java/org/soapService/Services/AccountVerificationRequestServiceImpl.java @@ -1,34 +1,28 @@ -package org.soapServiceV2.Services; +package org.soapService.Services; -import org.soapServiceV2.Domain.AccountVerificationRequest; +import org.soapService.Domain.AccountVerificationRequest; -import javax.jws.WebMethod; import javax.jws.WebService; import java.util.List; -@WebService(endpointInterface = "org.soapServiceV2.Services.AccountVerificationRequestService") +@WebService(endpointInterface = "org.soapService.Services.AccountVerificationRequestService") public class AccountVerificationRequestServiceImpl extends BaseService implements AccountVerificationRequestService { - @WebMethod public List<AccountVerificationRequest> getRequests() { return null; } - @WebMethod public boolean createRequest() { return false; } - @WebMethod public boolean acceptRequest(int userId) { return false; } - @WebMethod public boolean rejectRequest(int userId) { return false; } - @WebMethod public boolean deleteRequest(int requestId) { return false; } diff --git a/src/main/java/org/soapService/Services/BaseService.java b/src/main/java/org/soapService/Services/BaseService.java new file mode 100644 index 0000000000000000000000000000000000000000..b65fb3e58145d6557b9de56cb5f0b91cfe547d2e --- /dev/null +++ b/src/main/java/org/soapService/Services/BaseService.java @@ -0,0 +1,40 @@ +package org.soapService.Services; + + +import com.sun.net.httpserver.HttpExchange; +import com.sun.xml.internal.ws.developer.JAXWSProperties; +import org.soapService.Domain.Log; +import org.soapService.Repository.LogRepository; + +import javax.annotation.Resource; +import javax.xml.ws.WebServiceContext; +import javax.xml.ws.handler.MessageContext; +import java.sql.SQLException; + +public abstract class BaseService { + @Resource + WebServiceContext wsContext; + + protected void addLog() { + MessageContext messageContext = wsContext.getMessageContext(); + HttpExchange exchange = (HttpExchange) messageContext.get(JAXWSProperties.HTTP_EXCHANGE); + + Log log = new Log(); + log.setIp(exchange.getRemoteAddress().getAddress().toString().replace("/", "")); + log.setReqDesc("desc"); + log.setEndpointDest("/"); + + LogRepository logRepository = new LogRepository(); + + + try { + logRepository.add(log); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + protected void printContext() { +// System.out.println("IP From WebService: " + (String) Handler1.threadLocal.get()); + } +} diff --git a/src/main/java/org/soapService/Services/CatalogRequestService.java b/src/main/java/org/soapService/Services/CatalogRequestService.java new file mode 100644 index 0000000000000000000000000000000000000000..dd584138b77cd8cc6c7239345291345616873aa7 --- /dev/null +++ b/src/main/java/org/soapService/Services/CatalogRequestService.java @@ -0,0 +1,47 @@ +package org.soapService.Services; + +import org.soapService.Domain.CatalogRequest; + +import javax.activation.DataHandler; +import javax.jws.HandlerChain; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.ws.RequestWrapper; +import java.util.List; + +@WebService +@HandlerChain(file = "handler-chain.xml") +public interface CatalogRequestService { + @WebMethod(operationName = "CreateRequest") + @RequestWrapper(className = "CatalogRequestService.CreateRequest") + public boolean createRequest(@WebParam(name = "title") String title, + @WebParam(name = "description") String description, + @WebParam(name = "poster") String poster, + @WebParam(name = "trailer") String trailer, + @WebParam(name = "category") String category); + + @WebMethod(operationName = "GetRequests") + @RequestWrapper(className = "CatalogRequestService.GetRequests") + public List<CatalogRequest> getRequests(); + + @WebMethod(operationName = "GetRequest") + @RequestWrapper(className = "CatalogRequestService.GetRequest") + public CatalogRequest getRequest(@WebParam(name = "requestId") int requestId); + + @WebMethod(operationName = "AcceptRequest") + @RequestWrapper(className = "CatalogRequestService.AcceptRequest") + public boolean acceptRequest(@WebParam(name = "requestId") int requestId); + + @WebMethod(operationName = "RejectRequest") + @RequestWrapper(className = "CatalogRequestService.RejectRequest") + public boolean rejectRequest(@WebParam(name = "requestId") int requestId); + + @WebMethod(operationName = "DeleteRequest") + @RequestWrapper(className = "CatalogRequestService.DeleteRequest") + public boolean deleteRequest(@WebParam(name = "requestId") int requestId); + + @WebMethod(operationName = "TestUpload") + @RequestWrapper(className = "CatalogRequestService.TestUpload") + public String testUpload(@WebParam(name = "data") DataHandler data); +} diff --git a/src/main/java/org/soapService/Services/CatalogRequestServiceImpl.java b/src/main/java/org/soapService/Services/CatalogRequestServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..abcdb9e4c4ec17e7f7707db4a7098fca6e2f5362 --- /dev/null +++ b/src/main/java/org/soapService/Services/CatalogRequestServiceImpl.java @@ -0,0 +1,56 @@ +package org.soapService.Services; + +import org.soapService.Domain.CatalogRequest; +import org.soapService.Utils.FileType; +import org.soapService.Utils.FileUploader; + +import javax.activation.DataHandler; +import javax.jws.WebService; +import java.util.List; + +@WebService(endpointInterface = "org.soapService.Services.CatalogRequestService") +public class CatalogRequestServiceImpl extends BaseService implements CatalogRequestService { + public boolean createRequest(String title, String description, String poster, String trailer, String category) { + return false; + } + + public List<CatalogRequest> getRequests() { + return null; + } + + public CatalogRequest getRequest(int requestId) { + // For testing purpose + + CatalogRequest cr = new CatalogRequest(); + cr.setId(requestId); + return cr; + } + + public boolean acceptRequest(int requestId) { + return false; + } + + public boolean rejectRequest(int requestId) { + return false; + } + + public boolean deleteRequest(int requestId) { + System.out.println(requestId); + return false; + } + + public String testUpload(DataHandler dataHandler) { + try { + boolean valid = FileUploader.validateImage(dataHandler); + if (valid) { + FileUploader.upload(dataHandler, FileType.IMAGE); + } else { + return "Failed"; + } + return "Success"; + } catch (Exception e) { + e.printStackTrace(); + return "Failed"; + } + } +} diff --git a/src/main/java/org/soapService/Services/ReportUserService.java b/src/main/java/org/soapService/Services/ReportUserService.java new file mode 100644 index 0000000000000000000000000000000000000000..cc45a43c7b05cecf6ff445e53d368e78dd967184 --- /dev/null +++ b/src/main/java/org/soapService/Services/ReportUserService.java @@ -0,0 +1,31 @@ +package org.soapService.Services; + +import org.soapService.Domain.ReportUser; + +import javax.jws.HandlerChain; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.ws.RequestWrapper; +import java.util.List; + +@WebService +@HandlerChain(file = "handler-chain.xml") +public interface ReportUserService { + @WebMethod(operationName = "CreateReport") + @RequestWrapper(className = "ReportUserService.CreateReport") + public void createReport(@WebParam(name = "content") String content, + @WebParam(name = "reportedId") int reportedId); + + @WebMethod(operationName = "GetReportedUsers") + @RequestWrapper(className = "ReportUserService.GetReportedUsers") + public List<ReportUser> getReportedUsers(); + + @WebMethod(operationName = "BlockUser") + @RequestWrapper(className = "ReportUserService.BlockUser") + public boolean blockUser(@WebParam(name = "userId") int userId); + + @WebMethod(operationName = "DeleteReport") + @RequestWrapper(className = "ReportUserService.DeleteReport") + public boolean deleteReport(@WebParam(name = "reportId") int reportId); +} diff --git a/src/main/java/org/soapServiceV2/Services/ReportUserServiceImpl.java b/src/main/java/org/soapService/Services/ReportUserServiceImpl.java similarity index 61% rename from src/main/java/org/soapServiceV2/Services/ReportUserServiceImpl.java rename to src/main/java/org/soapService/Services/ReportUserServiceImpl.java index 1ad9aff6ed4c16e81a866e14a68e52261a7ddd7d..3683b05d72d2f617bb564f472a8eaeaa01a77bb6 100644 --- a/src/main/java/org/soapServiceV2/Services/ReportUserServiceImpl.java +++ b/src/main/java/org/soapService/Services/ReportUserServiceImpl.java @@ -1,29 +1,27 @@ -package org.soapServiceV2.Services; +package org.soapService.Services; -import org.soapServiceV2.Domain.ReportUser; +import org.soapService.Domain.ReportUser; -import javax.jws.WebMethod; import javax.jws.WebService; import java.util.List; -@WebService(endpointInterface = "org.soapServiceV2.Services.ReportUserService") +@WebService(endpointInterface = "org.soapService.Services.ReportUserService") public class ReportUserServiceImpl extends BaseService implements ReportUserService { - @WebMethod - public void createReport(String content, int reportedId) { + public void createReport(String content, int reportedId) { } - @WebMethod + public List<ReportUser> getReportedUsers() { return null; } - @WebMethod + public boolean blockUser(int userId) { return false; } - @WebMethod + public boolean deleteReport(int reportId) { return false; } diff --git a/src/main/java/org/soapService/Utils/FileType.java b/src/main/java/org/soapService/Utils/FileType.java new file mode 100644 index 0000000000000000000000000000000000000000..f300243955ebf12a6eef2cd276c9b9774ec291ce --- /dev/null +++ b/src/main/java/org/soapService/Utils/FileType.java @@ -0,0 +1,6 @@ +package org.soapService.Utils; + +public enum FileType { + IMAGE, + VIDEO +} diff --git a/src/main/java/org/soapService/Utils/FileUploader.java b/src/main/java/org/soapService/Utils/FileUploader.java new file mode 100644 index 0000000000000000000000000000000000000000..99edd2fde34130d44274b82c5a56005dab4d7c2a --- /dev/null +++ b/src/main/java/org/soapService/Utils/FileUploader.java @@ -0,0 +1,65 @@ +package org.soapService.Utils; + +import org.apache.commons.io.IOUtils; +import org.apache.tika.Tika; + +import javax.activation.DataHandler; +import java.io.File; +import java.io.IOException; +import java.nio.file.StandardCopyOption; +import java.util.UUID; + +public class FileUploader { + private static final int MAX_IMAGE_SIZE = 200_000; + private static final int MAX_VIDEO_SIZE = 100_000_000; + + public static boolean validateImage(DataHandler dataHandler) { + try { + Tika tika = new Tika(); + String mimeTypes = tika.detect(dataHandler.getInputStream()); + int size = IOUtils.toByteArray(dataHandler.getInputStream()).length; + + System.out.println("MIME Types: " + mimeTypes); + System.out.println("Size Image: " + size); + + if (!mimeTypes.equals("image/webp") || size > MAX_IMAGE_SIZE) { + return false; + } + + return true; + } catch (Exception e) { + return false; + } + } + + public static boolean validateVideo(DataHandler dataHandler) { + try { + Tika tika = new Tika(); + String mimeTypes = tika.detect(dataHandler.getInputStream()); + int size = IOUtils.toByteArray(dataHandler.getInputStream()).length; + + System.out.println("MIME Types: " + mimeTypes); + System.out.println("Size Image: " + size); + + if (!mimeTypes.contains("video") || size > MAX_VIDEO_SIZE) { + return false; + } + + return true; + } catch (Exception e) { + return false; + } + } + + public static void upload(DataHandler dataHandler, FileType fileType) throws IOException { + File file = null; + if (fileType == FileType.IMAGE) { + file = new File("src/main/resources/posters/poster_" + UUID.randomUUID() + ".webp"); + } else { + file = new File("src/main/resources/trailers/trailer_" + UUID.randomUUID() + ".mp4"); + } + + java.nio.file.Files.copy(dataHandler.getInputStream(), file.toPath(), StandardCopyOption.REPLACE_EXISTING); + IOUtils.closeQuietly(dataHandler.getInputStream()); + } +} diff --git a/src/main/java/org/soapServiceV2/Repository/AccountVerificationRequestRepository.java b/src/main/java/org/soapServiceV2/Repository/AccountVerificationRequestRepository.java deleted file mode 100644 index d467ea35863e53567a22030e657f51aae01b0cd3..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Repository/AccountVerificationRequestRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.soapServiceV2.Repository; - -import org.soapServiceV2.Domain.AccountVerificationRequest; - -import java.sql.SQLException; -import java.util.List; - -public class AccountVerificationRequestRepository implements BaseRepository<AccountVerificationRequest> { - public boolean add(AccountVerificationRequest data) throws SQLException { - return false; - } - - public List<AccountVerificationRequest> getAll() throws SQLException { - return null; - } - - public AccountVerificationRequest getById(int id) throws SQLException { - return null; - } - - public boolean update(int id) throws SQLException { - return false; - } - - public boolean deleteAll() throws SQLException { - return false; - } - - public boolean delete(int id) throws SQLException { - return false; - } -} diff --git a/src/main/java/org/soapServiceV2/Repository/BaseRepository.java b/src/main/java/org/soapServiceV2/Repository/BaseRepository.java deleted file mode 100644 index df53ecffecb9d2f5118233c48d73644801b10487..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Repository/BaseRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.soapServiceV2.Repository; - -import java.sql.SQLException; -import java.util.List; - -public interface BaseRepository<T> { - public boolean add(T data) throws SQLException; - - public List<T> getAll() throws SQLException; - - public T getById(int id) throws SQLException; - - public boolean update(int id) throws SQLException; - - public boolean deleteAll() throws SQLException; - - public boolean delete(int id) throws SQLException; - -} diff --git a/src/main/java/org/soapServiceV2/Repository/CatalogReqeustRepository.java b/src/main/java/org/soapServiceV2/Repository/CatalogReqeustRepository.java deleted file mode 100644 index fb29840f2d9c534b0ffc6e3a63f8a5b436ea1961..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Repository/CatalogReqeustRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.soapServiceV2.Repository; - -import org.soapServiceV2.Domain.CatalogRequest; - -import java.sql.SQLException; -import java.util.List; - -public class CatalogReqeustRepository implements BaseRepository<CatalogRequest> { - public boolean add(CatalogRequest data) throws SQLException { - return false; - } - - public List<CatalogRequest> getAll() throws SQLException { - return null; - } - - public CatalogRequest getById(int id) throws SQLException { - return null; - } - - public boolean update(int id) throws SQLException { - return false; - } - - public boolean deleteAll() throws SQLException { - return false; - } - - public boolean delete(int id) throws SQLException { - return false; - } -} diff --git a/src/main/java/org/soapServiceV2/Repository/LogRepository.java b/src/main/java/org/soapServiceV2/Repository/LogRepository.java deleted file mode 100644 index 7abfdf9a07d7f8defe3b7197a2914ce01fc8fcfd..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Repository/LogRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.soapServiceV2.Repository; - -import org.soapServiceV2.Domain.Log; - -import java.sql.SQLException; -import java.util.List; - -public class LogRepository implements BaseRepository<Log> { - - public boolean add(Log data) throws SQLException { - return false; - } - - public List<Log> getAll() throws SQLException { - return null; - } - - public Log getById(int id) throws SQLException { - return null; - } - - public boolean update(int id) throws SQLException { - return false; - } - - public boolean deleteAll() throws SQLException { - return false; - } - - public boolean delete(int id) throws SQLException { - return false; - } -} diff --git a/src/main/java/org/soapServiceV2/Repository/ReportUserRepository.java b/src/main/java/org/soapServiceV2/Repository/ReportUserRepository.java deleted file mode 100644 index c94b003959bfc4cbc7b4ecd4922965fc3d58e1bd..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Repository/ReportUserRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.soapServiceV2.Repository; - -import org.soapServiceV2.Domain.ReportUser; - -import java.sql.SQLException; -import java.util.List; - -public class ReportUserRepository implements BaseRepository<ReportUser> { - public boolean add(ReportUser data) throws SQLException { - return false; - } - - public List<ReportUser> getAll() throws SQLException { - return null; - } - - public ReportUser getById(int id) throws SQLException { - return null; - } - - public boolean update(int id) throws SQLException { - return false; - } - - public boolean deleteAll() throws SQLException { - return false; - } - - public boolean delete(int id) throws SQLException { - return false; - } -} diff --git a/src/main/java/org/soapServiceV2/Services/AccountVerificationRequestService.java b/src/main/java/org/soapServiceV2/Services/AccountVerificationRequestService.java deleted file mode 100644 index 85119811a7817c2dc364bcdbea0cadc72c146baf..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Services/AccountVerificationRequestService.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.soapServiceV2.Services; - -import org.soapServiceV2.Domain.AccountVerificationRequest; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import java.util.List; - -@WebService -public interface AccountVerificationRequestService { - @WebMethod - public List<AccountVerificationRequest> getRequests(); - - @WebMethod - public boolean createRequest(); - - @WebMethod - public boolean acceptRequest(int userId); - - @WebMethod - public boolean rejectRequest(int userId); - - @WebMethod - public boolean deleteRequest(int requestId); -} diff --git a/src/main/java/org/soapServiceV2/Services/BaseService.java b/src/main/java/org/soapServiceV2/Services/BaseService.java deleted file mode 100644 index 406e301414b7f92293662083ea17cd77bf5bcce7..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Services/BaseService.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.soapServiceV2.Services; - -public abstract class BaseService { - // TODO: Implements Logging -} diff --git a/src/main/java/org/soapServiceV2/Services/CatalogRequestService.java b/src/main/java/org/soapServiceV2/Services/CatalogRequestService.java deleted file mode 100644 index 2b7e8fcde8c1abc8fbca63f0d598242812114ce2..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Services/CatalogRequestService.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.soapServiceV2.Services; - -import org.soapServiceV2.Domain.CatalogRequest; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import java.util.List; - -@WebService -public interface CatalogRequestService { - - @WebMethod - public boolean createRequest(String title, String description, String poster, String trailer, String category); - - @WebMethod - public List<CatalogRequest> getRequests(); - - @WebMethod - public CatalogRequest getRequest(int requestId); - - @WebMethod - public boolean acceptRequest(int requestId); - - @WebMethod - public boolean rejectRequest(int requestId); - - @WebMethod - public boolean deleteRequest(int requestId); -} diff --git a/src/main/java/org/soapServiceV2/Services/CatalogRequestServiceImpl.java b/src/main/java/org/soapServiceV2/Services/CatalogRequestServiceImpl.java deleted file mode 100644 index d0d0c67953e568ce50ed2e7ec3be05898e5c2faf..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Services/CatalogRequestServiceImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.soapServiceV2.Services; - -import org.soapServiceV2.Domain.CatalogRequest; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import java.util.List; - -@WebService(endpointInterface = "org.soapServiceV2.Services.CatalogRequestService") -public class CatalogRequestServiceImpl extends BaseService implements CatalogRequestService { - - @WebMethod - public boolean createRequest(String title, String description, String poster, String trailer, String category) { - return false; - } - - @WebMethod - public List<CatalogRequest> getRequests() { - return null; - } - - @WebMethod - public CatalogRequest getRequest(int requestId) { - // For testing purpose - CatalogRequest cr = new CatalogRequest(); - cr.setId(requestId); - return cr; - } - - @WebMethod - public boolean acceptRequest(int requestId) { - return false; - } - - @WebMethod - public boolean rejectRequest(int requestId) { - return false; - } - - @WebMethod - public boolean deleteRequest(int requestId) { - return false; - } -} diff --git a/src/main/java/org/soapServiceV2/Services/ReportUserService.java b/src/main/java/org/soapServiceV2/Services/ReportUserService.java deleted file mode 100644 index 559bf420870d4d5c0e9e09d95649c4179ca40501..0000000000000000000000000000000000000000 --- a/src/main/java/org/soapServiceV2/Services/ReportUserService.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.soapServiceV2.Services; - -import org.soapServiceV2.Domain.ReportUser; - -import javax.jws.WebMethod; -import javax.jws.WebService; -import java.util.List; - -@WebService -public interface ReportUserService { - @WebMethod - public void createReport(String content, int reportedId); - - @WebMethod - public List<ReportUser> getReportedUsers(); - - @WebMethod - public boolean blockUser(int userId); - - @WebMethod - public boolean deleteReport(int reportId); -} diff --git a/src/main/resources/handler-chain.xml b/src/main/resources/handler-chain.xml new file mode 100644 index 0000000000000000000000000000000000000000..5c9fd12565af52c125f8f55dec106414ec8123be --- /dev/null +++ b/src/main/resources/handler-chain.xml @@ -0,0 +1,8 @@ +<jws:handler-chains xmlns:jws="http://java.sun.com/xml/ns/javaee"> + <jws:handler-chain> + <jws:handler> + <jws:handler-name>Handler</jws:handler-name> + <jws:handler-class>org.soapService.Handlers.Handler</jws:handler-class> + </jws:handler> + </jws:handler-chain> +</jws:handler-chains> \ No newline at end of file diff --git a/src/main/resources/posters/.gitkeep b/src/main/resources/posters/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/resources/trailers/.gitkeep b/src/main/resources/trailers/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391