Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions java/src/main/java/com/genexus/webpanels/FileItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,8 @@ public void write(String wFile)
gxFile.delete();
}
}

public GXFile getFile() {
return gxFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import com.genexus.*;
import com.genexus.internet.HttpContext;

import com.genexus.util.GXFile;
import org.json.JSONArray;
import com.genexus.json.JSONObjectWrapper;
import org.apache.commons.io.FilenameUtils;

import java.io.InputStream;

import java.lang.reflect.*;

public class GXObjectUploadServices extends GXWebObjectStub
{
{
private static final String ENV_HOOK_CLASS = "GX_UPLOAD_SECURITY_HOOK_CLASS";
boolean isRestCall = false;
String keyId;
String jsonResponse = null;
Expand Down Expand Up @@ -53,6 +55,8 @@ protected void doExecute(HttpContext context) throws Exception
context.setContentType("text/plain");
FileItemCollection postedFiles = context.getHttpRequest().getPostedparts();
JSONArray jsonArray = new JSONArray();
short[] status = new short[1];
String[] body = new String[1];
for (int i = 0, len = postedFiles.getCount(); i < len; i++)
{
keyId = HttpUtils.getUploadFileKey();
Expand All @@ -72,6 +76,10 @@ protected void doExecute(HttpContext context) throws Exception
if (!savedFileName.isEmpty()){
HttpUtils.CacheUploadFile(keyId, savedFileName, fileName, ext);
}
if (executeUploadHook(modelContext, file.getFile(), fileName, status, body)) {
context.sendResponseStatus(status[0], body[0]);
return;
}
}
}
JSONObjectWrapper jObjResponse = new JSONObjectWrapper();
Expand Down Expand Up @@ -265,5 +273,39 @@ private String getExtension(String contentType)
}
protected void init(HttpContext context )
{
}
}

private static boolean executeUploadHook(
ModelContext ctx,
GXFile file,
String originalFileName,
short[] httpStatusCode,
String[] httpResponseBody) {

try {
String hookClassName = System.getenv(ENV_HOOK_CLASS);
if (hookClassName == null || hookClassName.isEmpty())
return false;

Class<?> hookClass = Class.forName(hookClassName);
Object hookInstance = hookClass
.getConstructor(int.class, ModelContext.class)
.newInstance(-1, ctx);

Method executeUdp = hookClass.getMethod(
"executeUdp",
GXFile.class,
String.class,
short[].class,
String[].class);

Object result = executeUdp.invoke(hookInstance, file, originalFileName, httpStatusCode, httpResponseBody);
return (Boolean) result;

} catch (Exception e) {
httpStatusCode[0] = 400;
httpResponseBody[0] = e.getMessage();
return true;
}
}
}
Loading