| .. | .. |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | import javax.inject.Named; |
|---|
| 8 | 8 | import javax.servlet.http.HttpServletRequest; |
|---|
| 9 | +import javax.ws.rs.Consumes; |
|---|
| 9 | 10 | import javax.ws.rs.DefaultValue; |
|---|
| 11 | +import javax.ws.rs.FormParam; |
|---|
| 10 | 12 | import javax.ws.rs.GET; |
|---|
| 13 | +import javax.ws.rs.POST; |
|---|
| 11 | 14 | import javax.ws.rs.Path; |
|---|
| 12 | 15 | import javax.ws.rs.PathParam; |
|---|
| 13 | 16 | import javax.ws.rs.Produces; |
|---|
| .. | .. |
|---|
| 20 | 23 | import net.curisit.integrity.beans.ServiceResponse; |
|---|
| 21 | 24 | |
|---|
| 22 | 25 | import org.apache.commons.io.IOUtils; |
|---|
| 26 | +import org.jboss.resteasy.annotations.providers.multipart.MultipartForm; |
|---|
| 27 | +import org.jboss.resteasy.annotations.providers.multipart.PartType; |
|---|
| 23 | 28 | import org.slf4j.Logger; |
|---|
| 24 | 29 | import org.slf4j.LoggerFactory; |
|---|
| 25 | 30 | |
|---|
| 26 | 31 | // The Java class will be hosted at the URI path "/myresource" |
|---|
| 27 | | -@Path("/license") |
|---|
| 32 | +@Path("/test") |
|---|
| 28 | 33 | public class LicenseServices { |
|---|
| 29 | 34 | |
|---|
| 30 | 35 | // private LicenseHelper licenseHelper = InjectorFactory.getInjector().getInstance(LicenseHelper.class); |
|---|
| .. | .. |
|---|
| 38 | 43 | private URI uri; |
|---|
| 39 | 44 | |
|---|
| 40 | 45 | public LicenseServices() { |
|---|
| 46 | + |
|---|
| 41 | 47 | } |
|---|
| 42 | 48 | |
|---|
| 43 | 49 | /** |
|---|
| .. | .. |
|---|
| 70 | 76 | /** |
|---|
| 71 | 77 | * @return the version of the three entities that can be synchronized (Users, DataSet and Settings) |
|---|
| 72 | 78 | */ |
|---|
| 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 | + |
|---|
| 73 | 89 | @GET |
|---|
| 74 | 90 | @Path("/current/{license}") |
|---|
| 75 | 91 | @Produces( |
|---|
| 76 | 92 | { 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) { |
|---|
| 78 | 94 | |
|---|
| 79 | 95 | log.info("Called 'current' service with license: {}", license); |
|---|
| 80 | 96 | ServiceResponse<ServerConfigVersions> response = new ServiceResponse<ServerConfigVersions>(); |
|---|
| 81 | 97 | |
|---|
| 82 | 98 | return response; |
|---|
| 83 | 99 | } |
|---|
| 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 | | - // } |
|---|
| 123 | 100 | |
|---|
| 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 | + } |
|---|
| 124 | 131 | } |
|---|