package rest; import dto.ConnectDB; import dto.ScanObj; import dto.ScanObjPayload; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.json.JSONObject; import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import java.net.URISyntaxException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @Path("/") public class CreateScanResource { @RestClient CreateScanService createScanService; @POST @Consumes({ "application/json" }) //in theory should take List to clean it up public ScanObj invokeScanAnalyze(@Valid String scanInvocation) throws URISyntaxException { JSONObject jsonData = new JSONObject(scanInvocation); ScanObj scanObj = ScanObjPayload.constructScanPayload(jsonData); ConnectDB connectDB = new ConnectDB(); Connection conn = connectDB.connect(); Statement stmt = null; String sql = "INSERT INTO scans (scanid, productid, eventid, ismanagedservice, componentlist) VALUES ('" +scanObj.scanId+"', '"+scanObj.productId+"', '"+scanObj.eventId+"', '"+scanObj.isManagedService+"', '"+scanObj.componentList+"')"; try{ stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); conn.close(); } catch (SQLException e){ System.out.println(e); } return scanObj; } }