Skip to content

Commit

Permalink
Adding apache Multipart request builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kasundharmadasa committed Oct 26, 2018
1 parent 940f168 commit 2bfb911
Show file tree
Hide file tree
Showing 33 changed files with 108 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.1</version>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -83,7 +83,7 @@
</dependency>
</dependencies>
<build>
<finalName>automation-manager-webapp</finalName>
<finalName>scan-manager-webapp</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -92,7 +92,6 @@
<fork>true</fork>
<mainClass>org.wso2.security.tools.sgs.webapp.Application</mainClass>
<jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>

</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.List;

/**
* Scan Manager configuration model class
* SGS webapp configuration model class
*/
public class ScanManagerConfiguration {
public class SGSWebappConfiguration {

private String clientId;
private String clientSecret;
Expand All @@ -39,7 +39,7 @@ public class ScanManagerConfiguration {
private List<Scanner> dynamicScanners;
private List<Scanner> dependencyScanners;

private ScanManagerConfiguration() {
private SGSWebappConfiguration() {
}

public String getStopScanURI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.wso2.security.tools.sgs.webapp.exception.ScanManagerWebException;
import org.wso2.security.tools.sgs.webapp.exception.SGSWebappException;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
* Scan manager configuration builder class.
* SGS webapp configuration builder class.
*/
public class ScanMangerConfigurationBuilder {
public class SGSWebappConfigurationBuilder {

private static final String SCAN_MANAGER_CONFIG_FILE = "scanner-config.yaml";
private static final String SCAN_MANAGER_CONFIG_FILE = "sgs-webapp-config.yaml";

/**
* Reading the scan manager configuration from scanner-config.yaml
* Reading the sgs webapp configuration from sgs-webapp-config.yaml
*
* @return
* @throws ScanManagerWebException
* @throws SGSWebappException
*/
public static ScanManagerConfiguration getConfiguration() throws ScanManagerWebException {
public static SGSWebappConfiguration getConfiguration() throws SGSWebappException {

ScanManagerConfiguration scanManagerConfiguration = null;
URL scanManagerConfigURL = ScanManagerConfiguration.class.getClassLoader()
SGSWebappConfiguration sgsWebappConfiguration = null;
URL sgsWebappConfigURL = SGSWebappConfiguration.class.getClassLoader()
.getResource(SCAN_MANAGER_CONFIG_FILE);
if (scanManagerConfigURL != null) {
scanManagerConfiguration = getConfiguration(new File(scanManagerConfigURL.getFile()));
if (sgsWebappConfigURL != null) {
sgsWebappConfiguration = getConfiguration(new File(sgsWebappConfigURL.getFile()));
} else {
throw new ScanManagerWebException("Unable to find the scan manager configuration");
throw new SGSWebappException("Unable to find the sgs webapp configuration");
}
return scanManagerConfiguration;
return sgsWebappConfiguration;
}

/**
* Reading the scan manager configuration from a given config file
* Reading the sgs webapp configuration from a given config file
*
* @param configFile
* @return
* @throws ScanManagerWebException
* @throws SGSWebappException
*/
public static ScanManagerConfiguration getConfiguration(File configFile) throws ScanManagerWebException {
ScanManagerConfiguration configuration = null;
public static SGSWebappConfiguration getConfiguration(File configFile) throws SGSWebappException {
SGSWebappConfiguration configuration = null;

if (configFile.exists()) {
try {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
configuration = mapper.readValue(
configFile, ScanManagerConfiguration.class);
configFile, SGSWebappConfiguration.class);
} catch (IOException e) {
throw new ScanManagerWebException("Unable to read the configuration file " + configFile + e.getMessage(), e);
throw new SGSWebappException("Unable to read the configuration file " + configFile + ". " + e.getMessage(), e);
}
}
return configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.wso2.security.tools.sgs.webapp.exception.ScanManagerWebException;
import org.wso2.security.tools.sgs.webapp.exception.SGSWebappException;

import javax.annotation.PostConstruct;

Expand All @@ -33,17 +33,17 @@ public class StartUpInit {

private static final Logger logger = LoggerFactory.getLogger(StartUpInit.class);

public static ScanManagerConfiguration scanManagerConfiguration = null;
public static SGSWebappConfiguration sgsWebappConfiguration = null;

@PostConstruct
public void init() {
try {
scanManagerConfiguration = ScanMangerConfigurationBuilder.getConfiguration();
if (scanManagerConfiguration == null) {
throw new ScanManagerWebException("Error occurred while reading the" +
" application configuration");
sgsWebappConfiguration = SGSWebappConfigurationBuilder.getConfiguration();
if (sgsWebappConfiguration == null) {
throw new SGSWebappException("Error occurred while reading the" +
" SGS webapp configuration");
}
} catch (ScanManagerWebException e) {
} catch (SGSWebappException e) {
logger.error("Error occurred while initializing", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.wso2.security.tools.sgs.webapp.config.ScanManagerConfiguration;
import org.wso2.security.tools.sgs.webapp.config.SGSWebappConfiguration;
import org.wso2.security.tools.sgs.webapp.config.StartUpInit;
import org.wso2.security.tools.sgs.webapp.entity.Scanner;
import org.wso2.security.tools.sgs.webapp.service.ScanService;
Expand Down Expand Up @@ -69,11 +69,11 @@ public String startScan(MultipartHttpServletRequest multipartHttpServletRequest,
}

@GetMapping(value = "/scanners")
public String getScanners(@ModelAttribute("scannerConfig") ScanManagerConfiguration scannerConfiguration) {
public String getScanners(@ModelAttribute("scannerConfig") SGSWebappConfiguration sgsWebappConfiguration) {

scannerConfiguration.setStaticScanners(StartUpInit.scanManagerConfiguration.getStaticScanners());
scannerConfiguration.setDynamicScanners(StartUpInit.scanManagerConfiguration.getDynamicScanners());
scannerConfiguration.setDependencyScanners(StartUpInit.scanManagerConfiguration.getDependencyScanners());
sgsWebappConfiguration.setStaticScanners(StartUpInit.sgsWebappConfiguration.getStaticScanners());
sgsWebappConfiguration.setDynamicScanners(StartUpInit.sgsWebappConfiguration.getDynamicScanners());
sgsWebappConfiguration.setDependencyScanners(StartUpInit.sgsWebappConfiguration.getDependencyScanners());
return "scanManager/scanners";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@
package org.wso2.security.tools.sgs.webapp.exception;

/**
* The class {@code ScanManagerWebException} extends {@link Exception}, is the general Scan Manager Web
* App exception
* for all operations dealing with Scan Manager Web App
* The class {@code SGSWebappException} extends {@link Exception}, is the general SGS webapp exception
* for all operations dealing with SGS webapp
*/
public class ScanManagerWebException extends Exception {
public class SGSWebappException extends Exception {

/**
* Constructs a new runtime exception with {@code null} as its
* detail message.
*/
public ScanManagerWebException() {
public SGSWebappException() {
super();
}

Expand All @@ -38,15 +37,15 @@ public ScanManagerWebException() {
*
* @param message Message for the exception
*/
public ScanManagerWebException(String message) {
public SGSWebappException(String message) {
super(message);
}

/**
* Constructs a new runtime exception with the specified detail message and
* cause.
*/
public ScanManagerWebException(String message, Throwable e) {
public SGSWebappException(String message, Throwable e) {
super(message, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HttpRequestHandler {
* @return
* @throws RestClientException
*/
public static ResponseEntity<String> sendPOST(String url, MultiValueMap<String, String> requestHeaders, Map<String, Object>
public ResponseEntity<String> sendPOST(String url, MultiValueMap<String, String> requestHeaders, Map<String, Object>
requestParams) throws RestClientException {

HttpEntity<?> request = new HttpEntity<>(requestParams, requestHeaders);
Expand All @@ -56,7 +56,7 @@ public static ResponseEntity<String> sendPOST(String url, MultiValueMap<String,
* @return
* @throws RestClientException
*/
public static ResponseEntity<String> sendGET(String url, MultiValueMap<String, String> requestHeaders, Map<String, Object>
public ResponseEntity<String> sendGET(String url, MultiValueMap<String, String> requestHeaders, Map<String, Object>
requestParams) throws RestClientException {

HttpEntity<?> request = new HttpEntity<>(requestParams, requestHeaders);
Expand Down
Loading

0 comments on commit 2bfb911

Please sign in to comment.