Skip to content

Commit 6928196

Browse files
authored
Merge branch 'master' into issue-203288/JAVA---No_esta_llegando_primer_parm
2 parents 4260d18 + bd38d65 commit 6928196

File tree

98 files changed

+6641
-1046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6641
-1046
lines changed

.github/workflows/Build.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ jobs:
8080
master)
8181
echo "## Is MASTER branch"
8282
83-
versionChangelist="-stable.$timestamp-SNAPSHOT"
83+
versionChangelist="-preview.$timestamp-SNAPSHOT"
8484
SHOULD_DEPLOY='true'
8585
;;
8686
8787
beta)
88-
echo "## Is BETA branch, add +100 to major number"
88+
echo "## Is BETA branch"
8989
90-
pomMajorNumber=$(expr $pomMajorNumber + 100)
91-
92-
versionChangelist="-trunk.$timestamp-SNAPSHOT"
90+
versionChangelist="-beta.$timestamp-SNAPSHOT"
9391
SHOULD_DEPLOY='true'
9492
;;
9593

common/src/main/java/com/genexus/CommonUtil.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import java.math.BigDecimal;
1010
import java.io.*;
1111
import java.net.URLEncoder;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.nio.file.Paths;
1215
import java.text.*;
1316
import java.util.*;
1417

@@ -176,6 +179,62 @@ public Object initialValue()
176179
throw new ExceptionInInitializerError("GXUtil static constructor error: " + e.getMessage());
177180
}
178181
}
182+
183+
public static String getContentType(String fileName) {
184+
Path path = Paths.get(fileName);
185+
String defaultContentType = "application/octet-stream";
186+
187+
try {
188+
String probedContentType = Files.probeContentType(path);
189+
if (probedContentType == null || probedContentType.equals(defaultContentType))
190+
return findContentTypeByExtension(fileName);
191+
return probedContentType;
192+
} catch (IOException ioe) {
193+
return findContentTypeByExtension(fileName);
194+
}
195+
}
196+
197+
private static String findContentTypeByExtension(String fileName) {
198+
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
199+
String contentType = contentTypes.get(fileExtension);
200+
return contentType != null ? contentTypes.get(fileExtension) : "application/octet-stream";
201+
}
202+
203+
private static Map<String, String> contentTypes = new HashMap<String, String>() {{
204+
put("txt" , "text/plain");
205+
put("rtx" , "text/richtext");
206+
put("htm" , "text/html");
207+
put("html" , "text/html");
208+
put("xml" , "text/xml");
209+
put("aif" , "audio/x-aiff");
210+
put("au" , "audio/basic");
211+
put("wav" , "audio/wav");
212+
put("bmp" , "image/bmp");
213+
put("gif" , "image/gif");
214+
put("jpe" , "image/jpeg");
215+
put("jpeg" , "image/jpeg");
216+
put("jpg" , "image/jpeg");
217+
put("jfif" , "image/pjpeg");
218+
put("tif" , "image/tiff");
219+
put("tiff" , "image/tiff");
220+
put("png" , "image/x-png");
221+
put("3gp" , "video/3gpp");
222+
put("3g2" , "video/3gpp2");
223+
put("mpg" , "video/mpeg");
224+
put("mpeg" , "video/mpeg");
225+
put("mov" , "video/quicktime");
226+
put("qt" , "video/quicktime");
227+
put("avi" , "video/x-msvideo");
228+
put("exe" , "application/octet-stream");
229+
put("dll" , "application/x-msdownload");
230+
put("ps" , "application/postscript");
231+
put("pdf" , "application/pdf");
232+
put("svg" , "image/svg+xml");
233+
put("tgz" , "application/x-compressed");
234+
put("zip" , "application/x-zip-compressed");
235+
put("gz" , "application/x-gzip");
236+
put("json" , "application/json");
237+
}};
179238

180239
public static String removeAllQuotes(String fileName)
181240
{

common/src/main/java/com/genexus/internet/GXHttpClient.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -568,74 +568,81 @@ protected String setPathUrl(String url) {
568568
return url;
569569
}
570570

571+
572+
protected File fileToPost;
573+
protected String fileToPostName;
574+
571575
@SuppressWarnings("unchecked")
572576
protected byte[] getData()
573577
{
574578
byte[] out = new byte[0];
575579

576-
for (Object key: getVariablesToSend().keySet())
580+
for (Object key : getVariablesToSend().keySet())
577581
{
578-
String value = getMultipartTemplate().getFormDataTemplate((String)key, (String)getVariablesToSend().get(key));
579-
getContentToSend().add(0, value); //Variables al principio
582+
String value = getMultipartTemplate().getFormDataTemplate((String) key, (String) getVariablesToSend().get(key));
583+
getContentToSend().add(0, value); // Variables al principio
580584
}
581585

582586
for (int idx = 0; idx < getContentToSend().size(); idx++)
583587
{
584588
Object curr = getContentToSend().elementAt(idx);
585589

586-
if (curr instanceof String)
590+
if (curr instanceof String)
587591
{
588592
try
589593
{
590-
if(contentEncoding != null)
594+
if (contentEncoding != null)
591595
{
592-
out = addToArray(out, ((String)curr).getBytes(contentEncoding));
593-
}else
596+
out = addToArray(out, ((String) curr).getBytes(contentEncoding));
597+
} else
594598
{
595599
out = addToArray(out, (String) curr);
596600
}
597-
}catch(UnsupportedEncodingException e)
601+
} catch (UnsupportedEncodingException e)
598602
{
599603
System.err.println(e.toString());
600604
out = addToArray(out, (String) curr);
601605
}
602606
}
603-
else if (curr instanceof Object[])
607+
else if (curr instanceof Object[])
604608
{
605-
StringWriter writer = (StringWriter)((Object[])curr)[0];
606-
StringBuffer encoding = (StringBuffer)((Object[])curr)[1];
609+
StringWriter writer = (StringWriter) ((Object[]) curr)[0];
610+
StringBuffer encoding = (StringBuffer) ((Object[]) curr)[1];
607611

608-
if(encoding == null || encoding.length() == 0)
612+
if (encoding == null || encoding.length() == 0)
609613
{
610614
encoding = new StringBuffer("UTF-8");
611615
}
612616
try
613617
{
614618
out = addToArray(out, writer.toString().getBytes(encoding.toString()));
615619
}
616-
catch(UnsupportedEncodingException e)
620+
catch (UnsupportedEncodingException e)
617621
{
618622
out = addToArray(out, writer.toString());
619623
}
620624
}
621-
else if (curr instanceof byte[])
625+
else if (curr instanceof byte[])
622626
{
623627
out = addToArray(out, (byte[]) curr);
624628
}
625-
else //File or FormFile
629+
else // File or FormFile
626630
{
627631
File file;
628632
if (curr instanceof FormFile)
629633
{
630-
FormFile formFile = (FormFile)curr;
634+
FormFile formFile = (FormFile) curr;
631635
out = startMultipartFile(out, formFile.name, formFile.file);
632636
file = new File(formFile.file);
637+
fileToPostName = formFile.name;
633638
}
634639
else
635640
{
636641
file = (File) curr;
637642
}
638-
try (BufferedInputStream bis = new java.io.BufferedInputStream(new FileInputStream(file)))
643+
fileToPost = file;
644+
645+
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)))
639646
{
640647
out = addToArray(out, CommonUtil.readToByteArray(bis));
641648
}

gxawsserverless/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<version>${project.version}</version>
3232
</dependency>
3333

34+
<dependency>
35+
<groupId>${project.groupId}</groupId>
36+
<artifactId>gxserverlesscommon</artifactId>
37+
<version>${project.version}</version>
38+
</dependency>
39+
3440
<dependency>
3541
<groupId>javax.servlet</groupId>
3642
<artifactId>javax.servlet-api</artifactId>

gxawsserverless/src/main/java/com/genexus/cloud/serverless/Helper.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

gxawsserverless/src/main/java/com/genexus/cloud/serverless/aws/handler/LambdaBaseEventHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import com.genexus.ApplicationContext;
44
import com.genexus.ModelContext;
55
import com.genexus.cloud.serverless.*;
6-
import com.genexus.cloud.serverless.model.EventMessageResponse;
7-
import com.genexus.cloud.serverless.model.EventMessages;
6+
import com.genexus.cloud.serverless.model.*;
87
import com.genexus.diagnostics.core.ILogger;
98
import com.genexus.specific.java.Connect;
109
import com.genexus.specific.java.LogManager;
@@ -64,7 +63,7 @@ private void initialize() throws Exception {
6463
}
6564

6665
protected EventMessageResponse dispatchEvent(EventMessages eventMessages, String lambdaRawMessageBody) throws Exception {
67-
String jsonStringMessages = Helper.toJSONString(eventMessages);
66+
String jsonStringMessages = JSONHelper.toJSONString(eventMessages);
6867

6968
if (logger.isDebugEnabled()) {
7069
logger.debug(String.format("dispatchEventMessages (%s) - serialized messages: %s", functionConfiguration.getEntryPointClassName(), jsonStringMessages));
@@ -74,7 +73,7 @@ protected EventMessageResponse dispatchEvent(EventMessages eventMessages, String
7473
EventMessageResponse response = null;
7574

7675
try {
77-
response = executor.execute(modelContext, eventMessages, lambdaRawMessageBody);
76+
response = executor.execute(modelContext, eventMessages, null, lambdaRawMessageBody);
7877
} catch (Exception e) {
7978
logger.error(String.format("dispatchEventmessages - program '%s' execution error", entryPointClass.getName()), e);
8079
throw e;

gxawsserverless/src/main/java/com/genexus/cloud/serverless/aws/handler/LambdaEventBridgeHandler.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import com.amazonaws.services.lambda.runtime.Context;
44
import com.amazonaws.services.lambda.runtime.RequestHandler;
5-
import com.genexus.cloud.serverless.Helper;
5+
import com.genexus.cloud.serverless.JSONHelper;
6+
import com.genexus.cloud.serverless.model.*;
67
import com.genexus.cloud.serverless.exception.FunctionRuntimeException;
7-
import com.genexus.cloud.serverless.model.EventMessage;
8-
import com.genexus.cloud.serverless.model.EventMessageResponse;
9-
import com.genexus.cloud.serverless.model.EventMessageSourceType;
10-
import com.genexus.cloud.serverless.model.EventMessages;
118
import com.genexus.json.JSONObjectWrapper;
129
import org.apache.http.client.utils.DateUtils;
1310

@@ -25,7 +22,7 @@ public LambdaEventBridgeHandler(String entryPointClassName) throws Exception {
2522

2623
@Override
2724
public String handleRequest(Map<String, Object> stringObjectMap, Context context) {
28-
String jsonEventRaw = Helper.toJSONString(stringObjectMap);
25+
String jsonEventRaw = JSONHelper.toJSONString(stringObjectMap);
2926

3027
logger.debug("handleRequest started with event: " + jsonEventRaw);
3128

@@ -44,7 +41,7 @@ public String handleRequest(Map<String, Object> stringObjectMap, Context context
4441
msgItem.setMessageData(new JSONObjectWrapper(jsonEventRaw).getJSONObject("detail").toString());
4542
}
4643
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
47-
Helper.addEventMessageProperty(msgItem, entry.getKey(), entry.getValue().toString());
44+
JSONHelper.addEventMessageProperty(msgItem, entry.getKey(), entry.getValue().toString());
4845
}
4946
msgs.add(msgItem);
5047
response = dispatchEvent(msgs, jsonEventRaw);
@@ -63,6 +60,6 @@ public String handleRequest(Map<String, Object> stringObjectMap, Context context
6360
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
6461
throw new RuntimeException(response.getErrorMessage());
6562
}
66-
return Helper.toJSONString(response);
63+
return JSONHelper.toJSONString(response);
6764
}
6865
}

gxawsserverless/src/main/java/com/genexus/cloud/serverless/aws/handler/LambdaSQSHandler.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
77
import com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
88
import com.genexus.cloud.serverless.*;
9-
import com.genexus.cloud.serverless.model.EventMessageProperty;
10-
import com.genexus.cloud.serverless.model.EventMessage;
11-
import com.genexus.cloud.serverless.model.EventMessageResponse;
12-
import com.genexus.cloud.serverless.model.EventMessageSourceType;
13-
import com.genexus.cloud.serverless.model.EventMessages;
9+
import com.genexus.cloud.serverless.model.*;
1410

1511
import java.util.ArrayList;
1612
import java.util.Date;
@@ -64,7 +60,7 @@ public SQSBatchResponse handleRequest(SQSEvent sqsEvent, Context context) {
6460
String errorMessage;
6561

6662
try {
67-
EventMessageResponse response = dispatchEvent(msgs, Helper.toJSONString(sqsEvent));
63+
EventMessageResponse response = dispatchEvent(msgs, JSONHelper.toJSONString(sqsEvent));
6864
wasHandled = !response.hasFailed();
6965
errorMessage = response.getErrorMessage();
7066
} catch (Exception e) {

0 commit comments

Comments
 (0)