1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.bitrepository.webservice;
23
24 import java.net.MalformedURLException;
25 import java.net.URL;
26
27 public class WebserviceInputChecker {
28
29 public static void checkFileIDParameter(String fileID) throws WebserviceIllegalArgumentException {
30 if(fileID == null || fileID.isEmpty()) {
31 throw new WebserviceIllegalArgumentException("Failure: missing fileID parameter.");
32 }
33 }
34
35 public static void checkFileSizeParameter(String fileSize) throws WebserviceIllegalArgumentException {
36 if(fileSize == null || fileSize.isEmpty()) {
37 throw new WebserviceIllegalArgumentException("Failure: missing filesize");
38 }
39 try {
40 Long.parseLong(fileSize);
41 } catch (Exception e) {
42 throw new WebserviceIllegalArgumentException("Failure: " + fileSize + " is not a valid number value");
43 }
44 }
45
46 public static void checkURLParameter(String URL) throws WebserviceIllegalArgumentException {
47 if(URL == null || URL.isEmpty()) {
48 throw new WebserviceIllegalArgumentException("Failure: missing url parameter.");
49 }
50 @SuppressWarnings("unused")
51 URL url;
52 try {
53 url = new URL(URL);
54 } catch (MalformedURLException e) {
55 throw new WebserviceIllegalArgumentException("Failure: malformed url parameter.");
56 }
57 }
58
59 public static void checkChecksumTypeParameter(String checksumType) throws WebserviceIllegalArgumentException {
60 if(checksumType == null || checksumType.isEmpty()) {
61 throw new WebserviceIllegalArgumentException("Failure: missing checksumType parameter.");
62 }
63
64 }
65
66 public static void checkPillarIDParameter(String pillarID) throws WebserviceIllegalArgumentException {
67 if(pillarID == null || pillarID.isEmpty()) {
68 throw new WebserviceIllegalArgumentException("Failure: missing pillarID parameter.");
69 }
70 }
71
72 public static void checkChecksumParameter(String checksum) throws WebserviceIllegalArgumentException {
73 if(checksum != null && !checksum.isEmpty()) {
74 if((checksum.length() % 2) != 0) {
75 throw new WebserviceIllegalArgumentException("Failure: checksum parameter contains an uneven number of characters.");
76 }
77 if(!checksum.matches("^\\p{XDigit}*$")) {
78 throw new WebserviceIllegalArgumentException("Failure: checksum parameter contains a non hexadecimal value.");
79 }
80 }
81 }
82
83 public static void checkSaltParameter(String salt) throws WebserviceIllegalArgumentException {
84 if(salt != null && !salt.isEmpty()) {
85 if((salt.length() % 2) != 0) {
86 throw new WebserviceIllegalArgumentException("Failure: salt parameter contains an uneven number of characters.");
87 }
88 if(!salt.matches("^\\p{XDigit}*$")) {
89 throw new WebserviceIllegalArgumentException("Failure: salt parameter contains a non hexadecimal value.");
90 }
91 }
92 }
93 }