Commit 157b95e91e018fb524aadf98872dfb5117867f64
1 parent
2c3a8d7d
Chiamate completate,manca autenticazione
git-svn-id: http://svn.softecspa.it/desktopmate/DesktopMate%202.0/FileProxyServer/trunk@13300 edf0334f-4afc-450a-8f92-fe1409970e7d
Showing
22 changed files
with
442 additions
and
95 deletions
Show diff stats
| 1 | +<%@page import="it.softecspa.portal.ApplicationClusterInfo"%> | |
| 2 | +<%@page import="it.softecspa.portal.Parameters"%> | |
| 3 | +<% | |
| 4 | + Parameters parameters = Parameters.getInstance(); | |
| 5 | + String url = request.getScheme()+"://"+parameters.getChannelInfo().getDomainName(); | |
| 6 | + | |
| 7 | + url += parameters.getChannelInfo().getPortHTTP()+parameters.getChannelInfo().getContextName()+"/proxy-services/statement?upload"; | |
| 8 | +%> | |
| 9 | +<html> | |
| 10 | +<head> | |
| 11 | + <title>Upload file</title> | |
| 12 | + <meta http-equiv="expires" content="-1"> | |
| 13 | + <meta http-equiv="pragma" content="no-cache"> | |
| 14 | + <meta http-equiv="cache-control" content="no-cache"> | |
| 15 | + <script> | |
| 16 | + function sendData() { | |
| 17 | + var xmlhttp; | |
| 18 | + | |
| 19 | + if (window.XMLHttpRequest) { | |
| 20 | + xmlhttp = new XMLHttpRequest(); | |
| 21 | + } else if (window.ActiveXObject) { | |
| 22 | + xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
| 23 | + } | |
| 24 | + | |
| 25 | + //document.dati.risposta.value="Elaborazione in corso...."; | |
| 26 | + | |
| 27 | + xmlhttp.open("POST", "<%=url%>", false); | |
| 28 | + xmlhttp.setRequestHeader("X-username", document.dati.FIELD_USERNAME.value); | |
| 29 | + xmlhttp.setRequestHeader("X-password", document.dati.FIELD_PASSWORD.value); | |
| 30 | + // | |
| 31 | + xmlhttp.setRequestHeader("X-path", document.dati.FIELD_PATH.value); | |
| 32 | + xmlhttp.setRequestHeader("X-fileName", document.dati.FIELD_FILENAME.value); | |
| 33 | + xmlhttp.setRequestHeader("X-bufferLenght", document.dati.FIELD_BUFFER.value); | |
| 34 | + if (document.dati.FIELD_OVERWRITE.checked) { | |
| 35 | + xmlhttp.setRequestHeader("X-overwrite", document.dati.FIELD_OVERWRITE.value); | |
| 36 | + } | |
| 37 | + if (document.dati.FIELD_APPEND.checked) { | |
| 38 | + xmlhttp.setRequestHeader("X-append", document.dati.FIELD_APPEND.value); | |
| 39 | + } | |
| 40 | + xmlhttp.send(document.dati.FIELD_REQUEST.value); | |
| 41 | + | |
| 42 | + | |
| 43 | + var risposta = xmlhttp.responseText; | |
| 44 | + document.dati.FIELD_RESPONSE.value=risposta; | |
| 45 | + } | |
| 46 | + </script> | |
| 47 | + <style> | |
| 48 | + .tabella {border:solid 1px #DDDDEE; color:#2b2b2b; } | |
| 49 | + .cella {padding:5px;color:#2b2b2b; background-color:#DDDDEE; font-face:verdana; font-size:14px;} | |
| 50 | + .cellaIntestazione {padding:5px;color:#2b2b2b; background-color:#DDDDEE; font-face:verdana; font-size:14px; font-weight:bold;} | |
| 51 | + </style> | |
| 52 | +</head> | |
| 53 | +<body> | |
| 54 | + <form name="dati"> | |
| 55 | + <table border="0" cellspacing="2" cellpadding="2" class="tabella"> | |
| 56 | + <tr><td colspan="2" class="cellaIntestazione">Simulazione traferimento file</td></tr> | |
| 57 | + <tr> | |
| 58 | + <td colspan="2" class="cella"> | |
| 59 | + <ul> | |
| 60 | + <li>Incollare XML nella text area</li> | |
| 61 | + <li>La login e la password devono essere quelle di un utente abilitato all'import dei dati (ad esempio un amministratore) </li> | |
| 62 | + <li>Alla fine dell'importazione verrà visualizzato nell'area esito il risultato dell'importazione:</li> | |
| 63 | + </ul> | |
| 64 | + </td> | |
| 65 | + </tr> | |
| 66 | + <tr> | |
| 67 | + <td class="cella">login</td> | |
| 68 | + <td class="cella"><input name="FIELD_USERNAME" type="text"></td> | |
| 69 | + </tr> | |
| 70 | + <tr> | |
| 71 | + <td class="cella">password</td> | |
| 72 | + <td class="cella"><input name="FIELD_PASSWORD" type="password"></td> | |
| 73 | + </tr> | |
| 74 | + | |
| 75 | + <tr> | |
| 76 | + <td class="cella">path</td> | |
| 77 | + <td class="cella"><input name="FIELD_PATH" type="text"></td> | |
| 78 | + </tr> | |
| 79 | + <tr> | |
| 80 | + <td class="cella">fileName</td> | |
| 81 | + <td class="cella"><input name="FIELD_FILENAME" type="text"></td> | |
| 82 | + </tr> | |
| 83 | + <tr> | |
| 84 | + <td class="cella">overwrite</td> | |
| 85 | + <td class="cella"><input name="FIELD_OVERWRITE" type="checkbox" value="true"></td> | |
| 86 | + </tr> | |
| 87 | + <tr> | |
| 88 | + <td class="cella">append</td> | |
| 89 | + <td class="cella"><input name="FIELD_APPEND" type="checkbox" value="true"></td> | |
| 90 | + </tr> | |
| 91 | + <tr> | |
| 92 | + <td class="cella">bufferLength</td> | |
| 93 | + <td class="cella"><input name="FIELD_BUFFER" type="text"></td> | |
| 94 | + </tr> | |
| 95 | + | |
| 96 | + <tr> | |
| 97 | + <td class="cella" colspan="2"><input type="button" value="Invia dati" onclick="sendData();"></td> | |
| 98 | + </tr> | |
| 99 | + <tr> | |
| 100 | + <td colspan="2" class="cella"> | |
| 101 | + <div style="display: inline-block; vertical-align: top;"> | |
| 102 | + <div style="display: inline-block; vertical-align: top;"> | |
| 103 | + Invio<br> | |
| 104 | + <textarea name="FIELD_REQUEST" cols="80" rows="40"></textarea> | |
| 105 | + </div> | |
| 106 | + <div style="display:inline-block; vertical-align: top;"> | |
| 107 | + Esito<br> | |
| 108 | + <textarea name="FIELD_RESPONSE" readonly="readonly" cols="50" rows="20"></textarea> | |
| 109 | + </div> | |
| 110 | + </div> | |
| 111 | + </td> | |
| 112 | + </tr> | |
| 113 | + </table> | |
| 114 | + | |
| 115 | + </form> | |
| 116 | +</body> | |
| 117 | +</html> | ... | ... |
lib/common/local/kahuna5j_4.2.3.jar
No preview for this file type
src/it/softecspa/fileproxy/proxyservices/HttpFileProxyService.java
| ... | ... | @@ -4,14 +4,17 @@ import it.softecspa.fileproxy.proxyservices.core.HttpFileProxyServiceInterfaceSe |
| 4 | 4 | import it.softecspa.fileproxy.proxyservices.manager.DeleteManager; |
| 5 | 5 | import it.softecspa.fileproxy.proxyservices.manager.DownloadManager; |
| 6 | 6 | import it.softecspa.fileproxy.proxyservices.manager.ListManager; |
| 7 | +import it.softecspa.fileproxy.proxyservices.manager.MakeFolderManager; | |
| 7 | 8 | import it.softecspa.fileproxy.proxyservices.manager.UploadManager; |
| 8 | 9 | import it.softecspa.fileproxy.proxyservices.request.DeleteRequestType; |
| 9 | 10 | import it.softecspa.fileproxy.proxyservices.request.DownloadRequestType; |
| 10 | 11 | import it.softecspa.fileproxy.proxyservices.request.ListRequestType; |
| 12 | +import it.softecspa.fileproxy.proxyservices.request.MakeFolderRequestType; | |
| 11 | 13 | import it.softecspa.fileproxy.proxyservices.request.UploadRequestType; |
| 12 | 14 | import it.softecspa.fileproxy.proxyservices.response.DeleteResponseType; |
| 13 | 15 | import it.softecspa.fileproxy.proxyservices.response.DownloadResponseType; |
| 14 | 16 | import it.softecspa.fileproxy.proxyservices.response.ListResponseType; |
| 17 | +import it.softecspa.fileproxy.proxyservices.response.MakeFolderResponseType; | |
| 15 | 18 | import it.softecspa.fileproxy.proxyservices.response.UploadResponseType; |
| 16 | 19 | |
| 17 | 20 | import javax.servlet.ServletConfig; |
| ... | ... | @@ -76,4 +79,16 @@ public class HttpFileProxyService extends HttpFileProxyServiceInterfaceServlet { |
| 76 | 79 | return service.process(_request); |
| 77 | 80 | } |
| 78 | 81 | |
| 82 | + | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Creazione di una cartella | |
| 86 | + * @param _request | |
| 87 | + * @return | |
| 88 | + */ | |
| 89 | + public MakeFolderResponseType makeFolder(MakeFolderRequestType _request) { | |
| 90 | + MakeFolderManager service = new MakeFolderManager(); | |
| 91 | + return service.process(_request); | |
| 92 | + } | |
| 93 | + | |
| 79 | 94 | } | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/AbstractHttpFileProxyManager.java
| 1 | 1 | package it.softecspa.fileproxy.proxyservices.manager; |
| 2 | 2 | |
| 3 | -import it.softecspa.database.dbconnect.ConnectionManager; | |
| 4 | 3 | import it.softecspa.fileproxy.proxyservices.manager.core.NullSession; |
| 5 | 4 | import it.softecspa.fileproxy.proxyservices.request.AbstractHttpFileProxyRequest; |
| 6 | 5 | import it.softecspa.fileproxy.proxyservices.response.AbstractHttpFileProxyResponse; |
| 7 | 6 | import it.softecspa.fileproxy.services.ServerCacheFactory; |
| 8 | 7 | import it.softecspa.fileproxy.services.common.CheckerException; |
| 9 | 8 | import it.softecspa.fileproxy.services.common.ManagerException; |
| 9 | +import it.softecspa.fileproxy.services.common.ResponseOutcome; | |
| 10 | 10 | import it.softecspa.fileproxy.services.common.core.UniversalManager; |
| 11 | -import it.softecspa.kahuna.lang.XString; | |
| 12 | -import it.softecspa.kahuna.services.PostmanPat; | |
| 13 | -import it.softecspa.kahuna.sql.SqlWriter; | |
| 14 | -import it.softecspa.kahuna.util.calendar.EnterpriseCalendar; | |
| 15 | - | |
| 16 | -import java.math.BigDecimal; | |
| 17 | -import java.math.RoundingMode; | |
| 18 | -import java.sql.SQLException; | |
| 11 | +import it.softecspa.kahuna.io.File; | |
| 19 | 12 | |
| 20 | 13 | |
| 21 | 14 | public abstract class AbstractHttpFileProxyManager<I extends AbstractHttpFileProxyRequest, O extends AbstractHttpFileProxyResponse> extends UniversalManager <I,O,NullSession<I>> { |
| 22 | 15 | |
| 23 | - public static final String NULL_VERSION = "0.0.0"; | |
| 24 | - | |
| 25 | - // Variabile utilizzata per permetter di saltare i controlli di sessione | |
| 26 | - boolean jumpSessionValidate; | |
| 27 | - boolean forceStageMode; | |
| 28 | 16 | |
| 29 | 17 | boolean logRequestInfo; |
| 30 | 18 | |
| ... | ... | @@ -71,6 +59,29 @@ public abstract class AbstractHttpFileProxyManager<I extends AbstractHttpFilePro |
| 71 | 59 | return ServerCacheFactory.getInstance().getResourceRoot() + _path; |
| 72 | 60 | } |
| 73 | 61 | |
| 62 | + /** | |
| 63 | + * Controlla la presenza di caratteri speciali non accettati dai path | |
| 64 | + * @param da_controllare | |
| 65 | + * @throws CheckerException | |
| 66 | + */ | |
| 67 | + protected void checkWildecard(String da_controllare) throws CheckerException { | |
| 68 | + if (da_controllare==null) return; | |
| 69 | + | |
| 70 | + if (da_controllare.contains("..")) { | |
| 71 | + throw new CheckerException(ResponseOutcome.FOUND_NOT_VALID_CHAR, ".."); | |
| 72 | + } | |
| 73 | + if (da_controllare.contains("*")) { | |
| 74 | + throw new CheckerException(ResponseOutcome.FOUND_NOT_VALID_CHAR, "*"); | |
| 75 | + } | |
| 76 | + if (da_controllare.contains("!")) { | |
| 77 | + throw new CheckerException(ResponseOutcome.FOUND_NOT_VALID_CHAR, "!"); | |
| 78 | + } | |
| 79 | + if (da_controllare.contains("?")) { | |
| 80 | + throw new CheckerException(ResponseOutcome.FOUND_NOT_VALID_CHAR, "?"); | |
| 81 | + } | |
| 82 | + | |
| 83 | + } | |
| 84 | + | |
| 74 | 85 | |
| 75 | 86 | |
| 76 | 87 | @Override | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/DeleteManager.java
| ... | ... | @@ -16,8 +16,10 @@ public class DeleteManager extends AbstractHttpFileProxyManager<DeleteRequestTyp |
| 16 | 16 | |
| 17 | 17 | // Non si possono cancellare le cartelle |
| 18 | 18 | checkRequestMandatory("fileName"); |
| 19 | + checkWildecard(request.getPath()); | |
| 19 | 20 | String path = normalizePath(request.getPath()); |
| 20 | 21 | |
| 22 | + checkWildecard(request.getFileName()); | |
| 21 | 23 | file_to_delete = new File (path, request.getFileName()); |
| 22 | 24 | if (!file_to_delete.exists()) { |
| 23 | 25 | log.warn("File do not exist: '"+file_to_delete.getAbsolutePath()+"'"); | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/DownloadManager.java
| ... | ... | @@ -19,11 +19,12 @@ public class DownloadManager extends AbstractHttpFileProxyManager<DownloadReques |
| 19 | 19 | // Non si possono scaricare le cartelle |
| 20 | 20 | checkRequestMandatory("fileName"); |
| 21 | 21 | String path = normalizePath(request.getPath()); |
| 22 | + checkWildecard(request.getPath()); | |
| 22 | 23 | |
| 23 | 24 | checkRequestIfNullSetDefault("chunk", 0); |
| 24 | 25 | checkRequestIfNullSetDefault("inline", Boolean.FALSE); |
| 25 | 26 | |
| 26 | - | |
| 27 | + checkWildecard(request.getFileName()); | |
| 27 | 28 | file_to_download = new File (path, request.getFileName()); |
| 28 | 29 | if (!file_to_download.exists()) { |
| 29 | 30 | log.warn("File do not exist: '"+file_to_download.getAbsolutePath()+"'"); | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/ListManager.java
| ... | ... | @@ -24,6 +24,7 @@ public class ListManager extends AbstractHttpFileProxyManager<ListRequestType, L |
| 24 | 24 | |
| 25 | 25 | checkRequestIfNullSetDefault("onlyFile", Boolean.FALSE); |
| 26 | 26 | checkRequestIfNullSetDefault("showHidden", Boolean.FALSE); |
| 27 | + checkWildecard(request.getPath()); | |
| 27 | 28 | |
| 28 | 29 | path = normalizePath(request.getPath()); |
| 29 | 30 | } |
| ... | ... | @@ -32,8 +33,8 @@ public class ListManager extends AbstractHttpFileProxyManager<ListRequestType, L |
| 32 | 33 | |
| 33 | 34 | @Override |
| 34 | 35 | protected void doService(ListRequestType request, ListResponseType response) throws ManagerException { |
| 35 | - | |
| 36 | 36 | log.info("Request LIST of folder '"+path+"' (onlyFile="+request.getOnlyFile().booleanValue()+")"); |
| 37 | + | |
| 37 | 38 | List<File> files = File.dir(path, request.getOnlyFile().booleanValue()); |
| 38 | 39 | if (files==null) { |
| 39 | 40 | throw new ManagerException(new CheckerException(ResponseOutcome.PATH_NOT_VALID)); | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/MakeFolderManager.java
0 → 100644
| 1 | +package it.softecspa.fileproxy.proxyservices.manager; | |
| 2 | + | |
| 3 | +import it.softecspa.fileproxy.proxyservices.request.MakeFolderRequestType; | |
| 4 | +import it.softecspa.fileproxy.proxyservices.response.MakeFolderResponseType; | |
| 5 | +import it.softecspa.fileproxy.services.common.CheckerException; | |
| 6 | +import it.softecspa.fileproxy.services.common.ManagerException; | |
| 7 | +import it.softecspa.fileproxy.services.common.ResponseOutcome; | |
| 8 | +import it.softecspa.kahuna.io.File; | |
| 9 | + | |
| 10 | +public class MakeFolderManager extends AbstractHttpFileProxyManager<MakeFolderRequestType, MakeFolderResponseType> { | |
| 11 | + | |
| 12 | + private File dir_to_create; | |
| 13 | + | |
| 14 | + | |
| 15 | + @Override | |
| 16 | + protected void validateRequest() throws CheckerException, ManagerException { | |
| 17 | + | |
| 18 | + // Non si possono scaricare le cartelle | |
| 19 | + checkRequestMandatory("path"); | |
| 20 | + String path = normalizePath(request.getPath()); | |
| 21 | + checkWildecard(path); | |
| 22 | + | |
| 23 | + dir_to_create = new File (path); | |
| 24 | + if (dir_to_create.exists()) { | |
| 25 | + log.warn("Directory just exist: '"+dir_to_create.getAbsolutePath()+"'"); | |
| 26 | + throw new CheckerException(ResponseOutcome.DIRECTORY_JUST_EXIST); | |
| 27 | + } | |
| 28 | + | |
| 29 | + | |
| 30 | + } | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + protected void doService(MakeFolderRequestType request, MakeFolderResponseType response) throws ManagerException { | |
| 36 | + log.info("Request CREATE of folder '"+dir_to_create.getAbsolutePath()+"'"); | |
| 37 | + | |
| 38 | + if (!dir_to_create.mkdirs()) { | |
| 39 | + log.error("Error in create folder '"+dir_to_create.getAbsolutePath()+"'"); | |
| 40 | + throw new ManagerException(new CheckerException(ResponseOutcome.ERROR_CREATING_DIR)); | |
| 41 | + } | |
| 42 | + | |
| 43 | + | |
| 44 | + // Risposta POSITIVA | |
| 45 | + new ResponseBuilder(response).setReturn(ResponseOutcome.OK); | |
| 46 | + } | |
| 47 | + | |
| 48 | + | |
| 49 | +} | ... | ... |
src/it/softecspa/fileproxy/proxyservices/manager/UploadManager.java
| ... | ... | @@ -4,37 +4,126 @@ import it.softecspa.fileproxy.proxyservices.request.UploadRequestType; |
| 4 | 4 | import it.softecspa.fileproxy.proxyservices.response.UploadResponseType; |
| 5 | 5 | import it.softecspa.fileproxy.services.common.CheckerException; |
| 6 | 6 | import it.softecspa.fileproxy.services.common.ManagerException; |
| 7 | +import it.softecspa.fileproxy.services.common.ResponseOutcome; | |
| 8 | +import it.softecspa.kahuna.io.File; | |
| 9 | + | |
| 10 | +import java.io.FileNotFoundException; | |
| 11 | +import java.io.FileOutputStream; | |
| 12 | +import java.io.IOException; | |
| 13 | +import java.io.InputStream; | |
| 14 | +import java.io.OutputStream; | |
| 7 | 15 | |
| 8 | 16 | public class UploadManager extends AbstractHttpFileProxyManager<UploadRequestType, UploadResponseType> { |
| 9 | 17 | |
| 10 | - @Override | |
| 11 | - protected void initialize() throws ManagerException { | |
| 12 | - // TODO Auto-generated method stub | |
| 13 | - | |
| 14 | - } | |
| 18 | + private File file_to_upload; | |
| 15 | 19 | |
| 16 | 20 | @Override |
| 17 | 21 | protected void validateRequest() throws CheckerException, ManagerException { |
| 18 | - // TODO Auto-generated method stub | |
| 22 | + // Non si possono sovrascrivere le cartelle | |
| 23 | + | |
| 24 | + checkRequestMandatory("fileName"); | |
| 25 | + checkWildecard(request.getPath()); | |
| 26 | + String path = normalizePath(request.getPath()); | |
| 27 | + | |
| 28 | + checkRequestIfNullSetDefault("overwrite", Boolean.FALSE); | |
| 29 | + checkRequestIfNullSetDefault("append", Boolean.FALSE); | |
| 30 | + checkRequestIfNullSetDefault("bufferLength", 4096); | |
| 31 | + | |
| 32 | + checkWildecard(request.getFileName()); | |
| 33 | + file_to_upload = new File (path, request.getFileName()); | |
| 34 | + if (file_to_upload.exists()) { | |
| 35 | + if (!request.getOverwrite().booleanValue() && !request.getAppend().booleanValue()) { | |
| 36 | + log.warn("File just not exist: '"+file_to_upload.getAbsolutePath()+"', overwrite or append are FALSE"); | |
| 37 | + throw new CheckerException(ResponseOutcome.FILE_JUST_EXIST); | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (file_to_upload.isDirectory()) { | |
| 41 | + log.warn("File just not exist: '"+file_to_upload.getAbsolutePath()+"', but is a directory"); | |
| 42 | + throw new CheckerException(ResponseOutcome.FILE_IS_DIRECTORY); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + | |
| 19 | 47 | |
| 20 | 48 | } |
| 21 | 49 | |
| 22 | 50 | @Override |
| 23 | 51 | protected void doService(UploadRequestType request, UploadResponseType response) throws ManagerException { |
| 24 | - // TODO Auto-generated method stub | |
| 52 | + log.info("Request UPLOAD file '"+ file_to_upload.getAbsolutePath()+"'" | |
| 53 | + + (request.getOverwrite().booleanValue()?" (overwrite = TRUE)":"") | |
| 54 | + + (request.getAppend().booleanValue()?" (append = TRUE)":"") | |
| 55 | + + " (bufferLength = "+request.getBufferLength()+") "); | |
| 25 | 56 | |
| 26 | - } | |
| 27 | - | |
| 28 | - @Override | |
| 29 | - protected void completeWithSuccess(boolean stage) throws ManagerException { | |
| 30 | - // TODO Auto-generated method stub | |
| 57 | + // Prendo input stream e lo salvo su un file (prima temporaneo) | |
| 58 | + File file_temp = new File(file_to_upload.getAbsoluteFile()+".tmp"); | |
| 59 | + // Provo a cancellare il file temporaneo | |
| 60 | + file_temp.delete(); | |
| 61 | + | |
| 62 | + if (request.getAppend().booleanValue()) { | |
| 63 | + // Devo fare una copia del file per farlo diventara temporaneo | |
| 64 | + if (file_to_upload.exists()) { | |
| 65 | + // ...naturalmente se il file esite! | |
| 66 | + try { | |
| 67 | + | |
| 68 | + log.info("Creating temporay copy of file '"+ file_to_upload.getAbsolutePath()+"'"); | |
| 69 | + file_to_upload.copyTo(file_temp); | |
| 70 | + } catch (IOException e) { | |
| 71 | + throw new ManagerException(new CheckerException(ResponseOutcome.ERROR_COPY_FILE_TEMP)); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + InputStream input = request.takeInputStream(); | |
| 78 | + OutputStream output = null; | |
| 79 | + int BUFFER_LENGTH = request.getBufferLength(); | |
| 80 | + | |
| 81 | + try { | |
| 82 | + output = new FileOutputStream(file_temp, request.getAppend().booleanValue()); | |
| 83 | + | |
| 84 | + byte[] buffer = new byte[BUFFER_LENGTH]; | |
| 85 | + int bytesRead; | |
| 86 | + while ((bytesRead = input.read(buffer)) != -1) { | |
| 87 | + output.write(buffer, 0, bytesRead); | |
| 88 | + output.flush(); | |
| 89 | + } | |
| 90 | + | |
| 91 | + } catch (FileNotFoundException e) { | |
| 92 | + log.error("File '"+file_temp.getAbsolutePath()+"' not found"); | |
| 93 | + throw new ManagerException(new CheckerException(ResponseOutcome.FILE_NOT_FOUND)); | |
| 94 | + | |
| 95 | + } catch (IOException e) { | |
| 96 | + log.error("IOException writing file '"+file_temp.getAbsolutePath()+"'", e); | |
| 97 | + throw new ManagerException(e); | |
| 98 | + | |
| 99 | + } finally { | |
| 100 | + if (output!=null) { | |
| 101 | + try { | |
| 102 | + output.close(); | |
| 103 | + } catch (IOException e) { | |
| 104 | + log.error("IOException close file '"+file_temp.getAbsolutePath()+"'",e); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + log.info("Copy completed, rename temp file to '"+ file_to_upload.getAbsolutePath()+"'"); | |
| 110 | + if (request.getOverwrite().booleanValue()) { | |
| 111 | + if (file_to_upload.exists() && !file_to_upload.delete()) { | |
| 112 | + log.info("Impossibility to delete file '"+ file_to_upload.getAbsolutePath()+"' with override flag"); | |
| 113 | + } | |
| 114 | + } else if (request.getAppend().booleanValue()) { | |
| 115 | + if (file_to_upload.exists() && !file_to_upload.delete()) { | |
| 116 | + log.info("Impossibility to delete old file '"+ file_to_upload.getAbsolutePath()+"' with append flag"); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + | |
| 120 | + file_temp.renameTo(file_to_upload); | |
| 31 | 121 | |
| 32 | - } | |
| 33 | - | |
| 34 | - @Override | |
| 35 | - protected void checkAndTraceCheckerExceptionErrorIfExist(CheckerException e) { | |
| 36 | - // TODO Auto-generated method stub | |
| 37 | 122 | |
| 123 | + | |
| 124 | + // Risposta POSITIVA | |
| 125 | + new ResponseBuilder(response).setReturn(ResponseOutcome.OK); | |
| 38 | 126 | } |
| 39 | 127 | |
| 128 | + | |
| 40 | 129 | } | ... | ... |
src/it/softecspa/fileproxy/proxyservices/request/AbstractHttpFileProxyRequest.java
| ... | ... | @@ -9,7 +9,7 @@ import it.softecspa.fileproxy.services.common.core.request.TrackRequestInfo; |
| 9 | 9 | import it.softecspa.fileproxy.services.common.core.request.UniversalAuthenticatedRequest; |
| 10 | 10 | |
| 11 | 11 | |
| 12 | -public abstract class AbstractHttpFileProxyRequest implements GlobalHttpProxyRequest, RemoteHostRequestInfo, TrackRequestInfo, UniversalAuthenticatedRequest { | |
| 12 | +public abstract class AbstractHttpFileProxyRequest implements GlobalHttpProxyRequest, RemoteHostRequestInfo, TrackRequestInfo { | |
| 13 | 13 | |
| 14 | 14 | // UniversalRequest |
| 15 | 15 | private String language; |
| ... | ... | @@ -21,53 +21,28 @@ public abstract class AbstractHttpFileProxyRequest implements GlobalHttpProxyReq |
| 21 | 21 | // TrackRequestInfo |
| 22 | 22 | private boolean traceRequestInfo; |
| 23 | 23 | |
| 24 | - // UniversalAuthenticatedRequest | |
| 24 | + | |
| 25 | 25 | private String username; |
| 26 | 26 | private String password; |
| 27 | - private String organization; | |
| 28 | - | |
| 29 | - private String accessToken; | |
| 30 | 27 | |
| 31 | 28 | |
| 32 | - @Override | |
| 33 | 29 | public String getUsername() { |
| 34 | 30 | return username; |
| 35 | 31 | } |
| 36 | 32 | |
| 37 | - @Override | |
| 38 | 33 | public void setUsername(String username) { |
| 39 | 34 | this.username = username; |
| 40 | 35 | } |
| 41 | 36 | |
| 42 | - @Override | |
| 43 | 37 | public String getPassword() { |
| 44 | 38 | return password; |
| 45 | 39 | } |
| 46 | 40 | |
| 47 | - @Override | |
| 48 | 41 | public void setPassword(String password) { |
| 49 | 42 | this.password = password; |
| 50 | 43 | } |
| 51 | 44 | |
| 52 | - @Override | |
| 53 | - public String getOrganization() { | |
| 54 | - return organization; | |
| 55 | - } | |
| 56 | - | |
| 57 | - @Override | |
| 58 | - public void setOrganization(String organization) { | |
| 59 | - this.organization = organization; | |
| 60 | - } | |
| 61 | 45 | |
| 62 | - @Override | |
| 63 | - public String getAccessToken() { | |
| 64 | - return accessToken; | |
| 65 | - } | |
| 66 | - | |
| 67 | - @Override | |
| 68 | - public void setAccessToken(String authToken) { | |
| 69 | - this.accessToken = authToken; | |
| 70 | - } | |
| 71 | 46 | |
| 72 | 47 | |
| 73 | 48 | @Override | ... | ... |
src/it/softecspa/fileproxy/proxyservices/request/MakeFolderRequestType.java
0 → 100644
| 1 | +package it.softecspa.fileproxy.proxyservices.request; | |
| 2 | + | |
| 3 | + | |
| 4 | +public class MakeFolderRequestType extends AbstractHttpFileProxyRequest{ | |
| 5 | + | |
| 6 | + private String path; | |
| 7 | + | |
| 8 | + public String getPath() { | |
| 9 | + return path; | |
| 10 | + } | |
| 11 | + | |
| 12 | + public void setPath(String filename) { | |
| 13 | + this.path = filename; | |
| 14 | + } | |
| 15 | + | |
| 16 | + | |
| 17 | +} | ... | ... |
src/it/softecspa/fileproxy/proxyservices/request/UploadRequestType.java
| ... | ... | @@ -3,13 +3,20 @@ package it.softecspa.fileproxy.proxyservices.request; |
| 3 | 3 | import java.io.InputStream; |
| 4 | 4 | |
| 5 | 5 | import it.softecspa.fileproxy.services.common.core.request.InputStreamReaderXML; |
| 6 | +import it.softecspa.fileproxy.services.common.core.request.MethodPostMandatory; | |
| 6 | 7 | import it.softecspa.kahuna.util.xml.XmlRoot; |
| 7 | 8 | |
| 8 | -public class UploadRequestType extends AbstractHttpFileProxyRequest implements InputStreamReaderXML<XmlRoot>{ | |
| 9 | +public class UploadRequestType extends AbstractHttpFileProxyRequest implements InputStreamReaderXML<XmlRoot>, MethodPostMandatory { | |
| 9 | 10 | |
| 10 | 11 | private Boolean overwrite; |
| 11 | - private String filename; | |
| 12 | + private Boolean append; | |
| 12 | 13 | |
| 14 | + private String path; | |
| 15 | + private String fileName; | |
| 16 | + | |
| 17 | + private String encoding; | |
| 18 | + private Integer bufferLength; | |
| 19 | + | |
| 13 | 20 | |
| 14 | 21 | // InputStreamReaderXML |
| 15 | 22 | private InputStream inputStream; |
| ... | ... | @@ -44,12 +51,45 @@ public class UploadRequestType extends AbstractHttpFileProxyRequest implements I |
| 44 | 51 | } |
| 45 | 52 | |
| 46 | 53 | |
| 47 | - public String getFilename() { | |
| 48 | - return filename; | |
| 54 | + | |
| 55 | + public String getFileName() { | |
| 56 | + return fileName; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setFileName(String filename) { | |
| 60 | + this.fileName = filename; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public String getPath() { | |
| 64 | + return path; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setPath(String path) { | |
| 68 | + this.path = path; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public String getEncoding() { | |
| 72 | + return encoding; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setEncoding(String encoding) { | |
| 76 | + this.encoding = encoding; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public Integer getBufferLength() { | |
| 80 | + return bufferLength; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setBufferLength(Integer bufferLength) { | |
| 84 | + this.bufferLength = bufferLength; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public Boolean getAppend() { | |
| 88 | + return append; | |
| 49 | 89 | } |
| 50 | 90 | |
| 51 | - public void setFilename(String filename) { | |
| 52 | - this.filename = filename; | |
| 91 | + public void setAppend(Boolean append) { | |
| 92 | + this.append = append; | |
| 53 | 93 | } |
| 54 | 94 | |
| 55 | 95 | } | ... | ... |
src/it/softecspa/fileproxy/proxyservices/response/MakeFolderResponseType.java
0 → 100644
src/it/softecspa/fileproxy/proxyservices/xml/output/list/ResponseROOT.java
src/it/softecspa/fileproxy/services/common/ResponseOutcome.java
| ... | ... | @@ -405,6 +405,7 @@ public enum ResponseOutcome { |
| 405 | 405 | // Classe 90900 |
| 406 | 406 | , DEVICE_LOCKED (90970,false,false,"Application locked on this device") |
| 407 | 407 | |
| 408 | + , REQUEST_METHOD_NOT_VALID (90979,"Http request method not valid (POST mandatory)") | |
| 408 | 409 | , REQUEST_NOT_IMPL_ISREADER (90980,"Internal error, request must implements interface to perform operation") |
| 409 | 410 | , DB_COMPARE_CLASS_NOT_MAPPED (90981,"Class not managed from database field comparator") |
| 410 | 411 | , DB_FILED_NOT_MAPPED (90982,"Database filed not mapped") |
| ... | ... | @@ -425,23 +426,19 @@ public enum ResponseOutcome { |
| 425 | 426 | , SESSION_NOT_VALID (90997,"Session null or not valid") |
| 426 | 427 | , REQUEST_NOT_VALID (90998,"Request is not valid") |
| 427 | 428 | , RESPONSE_NOT_VALID (90999,"Response is not valid") // Valore di default |
| 428 | - // APP IN BICI CUSTOM | |
| 429 | - , PHONE_NUMBER_NOT_VALID (71000,"Phone number not valid") | |
| 430 | - , DATE_INVALID_MISSING (71001,"Date invalid or missing") | |
| 431 | - , MANDATORY_KM_USEFUL (71002,"Km Useful is a mandatory field") | |
| 432 | - , MANDATORY_KM_USELESS (71003,"Km Useless is a mandatory field") | |
| 433 | - , MANDATORY_KM_OUT_THRESHOLD (71004,"Km Out Threshold is a mandatory field") | |
| 434 | - , MANDATORY_TYPE (71005,"Type is a mandatory field") | |
| 435 | - , MANDATORY_DATE_START (71006,"Date start is a mandatory field") | |
| 436 | - , MANDATORY_DATE_END (71007,"Date end is a mandatory field") | |
| 437 | - , SESSION_TOKEN_INVALID (71008,"Invalid Session Token") | |
| 438 | - //----------------- | |
| 439 | - | |
| 440 | 429 | |
| 430 | + // FILE PROXY CUSTOM | |
| 441 | 431 | , PATH_NOT_VALID (30001,"Path not valid or not found") |
| 442 | 432 | , FILE_NOT_EXIST (30002,"File do not exist") |
| 443 | 433 | , FILE_IS_DIRECTORY (30003,"This is not a file") |
| 444 | 434 | , ERROR_DELETING_FILE (30004,"Error deleting file") |
| 435 | + , FILE_JUST_EXIST (30005,"File just exist") | |
| 436 | + , FILE_NOT_FOUND (30006,"File not found") | |
| 437 | + , ERROR_COPY_FILE_TEMP (30007,"Error creating temp file for append") | |
| 438 | + , DIRECTORY_JUST_EXIST (30008,"Directory just exist") | |
| 439 | + , ERROR_CREATING_DIR (30009,"Error creating directory") | |
| 440 | + , FOUND_NOT_VALID_CHAR (30010,"Found not valid char in path or filename") | |
| 441 | + //----------------- | |
| 445 | 442 | |
| 446 | 443 | |
| 447 | 444 | ... | ... |
src/it/softecspa/fileproxy/services/common/core/UniversalStatementHttpServlet.java
| ... | ... | @@ -13,10 +13,12 @@ import it.softecspa.fileproxy.services.common.comunicator.http.HttpRemote; |
| 13 | 13 | import it.softecspa.fileproxy.services.common.core.request.InputStreamReaderJSON; |
| 14 | 14 | import it.softecspa.fileproxy.services.common.core.request.InputStreamReaderXML; |
| 15 | 15 | import it.softecspa.fileproxy.services.common.core.request.JsonMapper; |
| 16 | +import it.softecspa.fileproxy.services.common.core.request.MethodPostMandatory; | |
| 16 | 17 | import it.softecspa.fileproxy.services.common.core.request.MultipartFormDataRequestReader; |
| 17 | 18 | import it.softecspa.fileproxy.services.common.core.request.OutputPrintWriter; |
| 18 | 19 | import it.softecspa.fileproxy.services.common.core.request.OutputStreamWriter; |
| 19 | 20 | import it.softecspa.fileproxy.services.common.core.request.RemoteHostRequestInfo; |
| 21 | +import it.softecspa.fileproxy.services.common.core.request.TrackRequestCustomInfo; | |
| 20 | 22 | import it.softecspa.fileproxy.services.common.core.request.TrackRequestInfo; |
| 21 | 23 | import it.softecspa.fileproxy.services.common.core.request.UniversalRequest; |
| 22 | 24 | import it.softecspa.fileproxy.services.common.core.response.AbstractDummyResponse; |
| ... | ... | @@ -330,7 +332,7 @@ public abstract class UniversalStatementHttpServlet <UREQ extends UniversalReque |
| 330 | 332 | HttpRemote remote = myResponse.getHttpRemote(); |
| 331 | 333 | if (log.isDebugEnabled()) log.debug("Remote call from "+remote.getTraceHost()); |
| 332 | 334 | |
| 333 | - if (log.isDebugEnabled()) log.debug("Operation required: '"+myResponse.getStatementKey()+"'"); | |
| 335 | + if (log.isDebugEnabled()) log.debug("Operation required: '"+myResponse.getStatementKey()+"', method "+request.getMethod()); | |
| 334 | 336 | // Se trovo un "-" devo mettere a maiuscolo la lettera seguente |
| 335 | 337 | int pos; |
| 336 | 338 | String statement = new String(myResponse.getStatementKey()!=null?myResponse.getStatementKey():""); |
| ... | ... | @@ -368,6 +370,17 @@ public abstract class UniversalStatementHttpServlet <UREQ extends UniversalReque |
| 368 | 370 | Object[] parameterArgs = new Object[1]; |
| 369 | 371 | parameterArgs[0] = clazzT.newInstance(statementRequestClazz, request, true); |
| 370 | 372 | |
| 373 | + | |
| 374 | + // m.veroni - 2014-06-24 - verifica obbligatorietà del metodo | |
| 375 | + if (parameterArgs[0] instanceof MethodPostMandatory) { | |
| 376 | + if (!request.getMethod().equalsIgnoreCase("POST")) { | |
| 377 | + log.error("Request method not valid, required POST (vs '"+request.getMethod()+"')"); | |
| 378 | + responseError(myResponse, ResponseOutcome.REQUEST_METHOD_NOT_VALID); | |
| 379 | + return; | |
| 380 | + } | |
| 381 | + } | |
| 382 | + | |
| 383 | + | |
| 371 | 384 | // Stampo i parametri di chiamata |
| 372 | 385 | myResponse.setInput(parameterArgs[0]); |
| 373 | 386 | if (log.isDebugEnabled()) log.debug(requestInfo(myResponse, null)); |
| ... | ... | @@ -445,22 +458,17 @@ public abstract class UniversalStatementHttpServlet <UREQ extends UniversalReque |
| 445 | 458 | myReturn.setTrace(((TrackRequestInfo)parameterArgs[0]).isTrackRequestInfo()); |
| 446 | 459 | } |
| 447 | 460 | |
| 448 | - /* FIXME aggiungere codice custom per stampare info aggiuntive nel log | |
| 461 | + | |
| 449 | 462 | // Aggiunta di informazioni accessorie recuperate dalla request |
| 450 | - if (myResponse.getInput() instanceof GlobalDeviceRequestHeader) { | |
| 463 | + if (myResponse.getInput() instanceof TrackRequestCustomInfo) { | |
| 451 | 464 | // Stampo le info recuperate delle chiamata |
| 452 | - GlobalDeviceRequestHeader input = (GlobalDeviceRequestHeader)myResponse.getInput(); | |
| 465 | + TrackRequestCustomInfo input = (TrackRequestCustomInfo)myResponse.getInput(); | |
| 453 | 466 | if (input!=null) { |
| 454 | - myResponse.setInfo(new Entry[] { new Entry("client", input.getClientId()) | |
| 455 | - , new Entry("tech", input.getTechnology()) | |
| 456 | - , new Entry("group", input.getGroupCode()) | |
| 457 | - , new Entry("instance", input.getInstanceCode()) | |
| 458 | - , new Entry("protocol", (input.getProtocolVersion()!=null?input.getProtocolVersion():Protocollo._1).toString()) | |
| 459 | - , new Entry("lang", input.getLanguage()) | |
| 460 | - }); | |
| 467 | + myResponse.setInfo(input.takeCustomEntry()); | |
| 461 | 468 | } |
| 462 | 469 | } |
| 463 | - */ | |
| 470 | + | |
| 471 | + | |
| 464 | 472 | // ---- |
| 465 | 473 | responseReturn(myResponse, myReturn, res); |
| 466 | 474 | ... | ... |
src/it/softecspa/fileproxy/services/common/core/request/InputStreamReaderJSON.java
| ... | ... | @@ -3,7 +3,7 @@ package it.softecspa.fileproxy.services.common.core.request; |
| 3 | 3 | import java.io.InputStream; |
| 4 | 4 | import java.io.Serializable; |
| 5 | 5 | |
| 6 | -public interface InputStreamReaderJSON <J extends Serializable> { | |
| 6 | +public interface InputStreamReaderJSON <J extends Serializable> extends MethodPostMandatory { | |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Restituisce l'input stream della request | ... | ... |
src/it/softecspa/fileproxy/services/common/core/request/InputStreamReaderXML.java
| ... | ... | @@ -4,7 +4,7 @@ import it.softecspa.kahuna.util.xml.XmlRoot; |
| 4 | 4 | |
| 5 | 5 | import java.io.InputStream; |
| 6 | 6 | |
| 7 | -public interface InputStreamReaderXML<X extends XmlRoot> { | |
| 7 | +public interface InputStreamReaderXML<X extends XmlRoot> extends MethodPostMandatory { | |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Restituisce l'input stream della request | ... | ... |
src/it/softecspa/fileproxy/services/common/core/request/MethodPostMandatory.java
0 → 100644
src/it/softecspa/fileproxy/services/common/core/request/MultipartFormDataRequestReader.java
| ... | ... | @@ -2,7 +2,7 @@ package it.softecspa.fileproxy.services.common.core.request; |
| 2 | 2 | |
| 3 | 3 | import javazoom.upload.MultipartFormDataRequest; |
| 4 | 4 | |
| 5 | -public interface MultipartFormDataRequestReader { | |
| 5 | +public interface MultipartFormDataRequestReader extends MethodPostMandatory { | |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Restituisce l'istanza della MultipartFormDataRequest | ... | ... |
src/it/softecspa/fileproxy/services/common/core/request/TrackRequestCustomInfo.java
0 → 100644
| 1 | +package it.softecspa.fileproxy.services.common.core.request; | |
| 2 | + | |
| 3 | +import it.softecspa.fileproxy.services.common.core.response.Entry; | |
| 4 | + | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Interfaccia universale che tutte le classi response devono estendere | |
| 8 | + * - lingua | |
| 9 | + * - versione protocollo | |
| 10 | + */ | |
| 11 | +public interface TrackRequestCustomInfo extends TrackRequestInfo { | |
| 12 | + | |
| 13 | + public Entry[] takeCustomEntry(); | |
| 14 | + | |
| 15 | +} | ... | ... |
src/it/softecspa/fileproxy/services/common/core/response/XMLResponseKO.java