Roberto Sánchez
2014-01-22 2fd6ff883fa6ee5ece773c69fce66f3cd03c86a5
securis/src/main/java/net/curisit/securis/services/LicenseServices.java
....@@ -6,8 +6,11 @@
66
77 import javax.inject.Named;
88 import javax.servlet.http.HttpServletRequest;
9
+import javax.ws.rs.Consumes;
910 import javax.ws.rs.DefaultValue;
11
+import javax.ws.rs.FormParam;
1012 import javax.ws.rs.GET;
13
+import javax.ws.rs.POST;
1114 import javax.ws.rs.Path;
1215 import javax.ws.rs.PathParam;
1316 import javax.ws.rs.Produces;
....@@ -20,11 +23,13 @@
2023 import net.curisit.integrity.beans.ServiceResponse;
2124
2225 import org.apache.commons.io.IOUtils;
26
+import org.jboss.resteasy.annotations.providers.multipart.MultipartForm;
27
+import org.jboss.resteasy.annotations.providers.multipart.PartType;
2328 import org.slf4j.Logger;
2429 import org.slf4j.LoggerFactory;
2530
2631 // The Java class will be hosted at the URI path "/myresource"
27
-@Path("/license")
32
+@Path("/test")
2833 public class LicenseServices {
2934
3035 // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class);
....@@ -38,6 +43,7 @@
3843 private URI uri;
3944
4045 public LicenseServices() {
46
+
4147 }
4248
4349 /**
....@@ -70,55 +76,56 @@
7076 /**
7177 * @return the version of the three entities that can be synchronized (Users, DataSet and Settings)
7278 */
79
+ @POST
80
+ @Path("/upload1")
81
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
82
+ @Produces(
83
+ { MediaType.APPLICATION_JSON })
84
+ public Response testFile1(@MultipartForm FileUploadForm mfdi) {
85
+ log.info("FORM: texto: {}, file: {}", mfdi.getTexto(), new String(mfdi.getFile()));
86
+ return Response.ok("OK").build();
87
+ }
88
+
7389 @GET
7490 @Path("/current/{license}")
7591 @Produces(
7692 { MediaType.APPLICATION_JSON })
77
- public ServiceResponse<ServerConfigVersions> status(@PathParam("license") String license, @DefaultValue("-1") @QueryParam("minorVersion") int minorVersion, @DefaultValue("-1") @QueryParam("majorVersion") int majorVersion) {
93
+ public ServiceResponse<ServerConfigVersions> testFile(@PathParam("license") String license, @DefaultValue("-1") @QueryParam("minorVersion") int minorVersion, @DefaultValue("-1") @QueryParam("majorVersion") int majorVersion) {
7894
7995 log.info("Called 'current' service with license: {}", license);
8096 ServiceResponse<ServerConfigVersions> response = new ServiceResponse<ServerConfigVersions>();
8197
8298 return response;
8399 }
84
- //
85
- // private <T> ServiceResponse<T> buildErrorResponse(ServiceResponse<T> response, String msgErrorCode) {
86
- // response.setSuccess(false);
87
- // response.setErrorMessage(localManager.getString(msgErrorCode));
88
- // response.setErrorMessageCode(msgErrorCode);
89
- // return response;
90
- // }
91
- //
92
- // private Date calculateCaducation() {
93
- // Integer licenseExpiration = systemParams.getParamAsInt(SystemParams.Keys.CONFIG_SERVER_LICENSE_EXPIRATION);
94
- // if (licenseExpiration == null)
95
- // licenseExpiration = DEFAULT_LICENSE_EXPIRATION;
96
- // return Utils.addDays(new Date(), licenseExpiration);
97
- // }
98
- //
99
- // private boolean validateLicense(String license) {
100
- // BasicApplication ba = basicApplicationDao.findByLicense(license);
101
- // return (ba != null);
102
- // }
103
- //
104
- // private boolean validateVersion(int minorVersion, int majorVersion) {
105
- // return (versionManager.getMajorVersion() == majorVersion);
106
- // }
107
- //
108
- // private BasicApplication findBasicApp(String license) {
109
- // BasicApplication ba = basicApplicationDao.findByLicense(license);
110
- // return ba;
111
- // }
112
- //
113
- // private License generateLicense() {
114
- // // TODO complete all field of the license
115
- // License license = new License();
116
- // license.setCustomerCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CUSTOMER_CODE));
117
- // license.setCSCode(systemParams.getParam(SystemParams.Keys.CONFIG_COMMON_CS_CODE));
118
- // license.setCRCLogo("00000000");
119
- // license.setExpirationDate(calculateCaducation());
120
- // license.setInstallCode(codeGenerator.generateInstalationNumber());
121
- // return license;
122
- // }
123100
101
+ public static class FileUploadForm {
102
+
103
+ @FormParam("file1")
104
+ @PartType("application/octet-stream")
105
+ private byte[] file;
106
+
107
+ @FormParam("texto1")
108
+ @PartType("text/plain")
109
+ private String texto;
110
+
111
+ public FileUploadForm() {
112
+ }
113
+
114
+ public byte[] getFile() {
115
+ return file;
116
+ }
117
+
118
+ public void setFile(byte[] file) {
119
+ this.file = file;
120
+ }
121
+
122
+ public void setTexto(final String texto) {
123
+ this.texto = texto;
124
+ }
125
+
126
+ public String getTexto() {
127
+ return texto;
128
+ }
129
+
130
+ }
124131 }