Skip to content

Commit 00fb416

Browse files
Merge branch 'master' into PDFBoxHTMLSupport
2 parents 589b5be + ea3753a commit 00fb416

File tree

60 files changed

+614
-240
lines changed

Some content is hidden

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

60 files changed

+614
-240
lines changed

common/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@
3939
<artifactId>bcprov-jdk15on</artifactId>
4040
<version>1.69</version>
4141
</dependency>
42-
</dependencies>
42+
<dependency>
43+
<groupId>io.opentelemetry</groupId>
44+
<artifactId>opentelemetry-api</artifactId>
45+
<version>${io.opentelemetry.version}</version>
46+
</dependency>
47+
</dependencies>
4348

4449
<build>
4550
<finalName>gxcommon</finalName>

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.math.BigInteger;
2020
import java.net.HttpURLConnection;
2121
import java.net.URL;
22+
import java.util.regex.Matcher;
23+
import java.util.regex.Pattern;
2224

2325
import com.genexus.common.interfaces.SpecificImplementation;
2426

@@ -47,6 +49,11 @@ public final class CommonUtil
4749
private static DateFormat parse_asctime;
4850
private static final Object http_parse_lock = new Object();
4951

52+
private static final String LOG_USER_ENTRY_WHITELIST_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890+-_=/[]{}\":, ";
53+
private static final String HTTP_HEADER_WHITELIST_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.;+-_=/[]{}\"':, @()?<>\\";
54+
public static final HashMap<Character, Character> LOG_USER_ENTRY_WHITELIST;
55+
public static final HashMap<Character, Character> HTTP_HEADER_WHITELIST;
56+
5057
public static final ILogger logger = LogManager.getLogger(CommonUtil.class);
5158

5259
static
@@ -159,6 +166,9 @@ public Object initialValue()
159166
{"Big5_HKSCS","Big5-HKSCS"},
160167
{"EncodingWrapper","EncodingWrapper"}
161168
};
169+
170+
LOG_USER_ENTRY_WHITELIST = stringToHashMap(LOG_USER_ENTRY_WHITELIST_STRING);
171+
HTTP_HEADER_WHITELIST = stringToHashMap(HTTP_HEADER_WHITELIST_STRING);
162172
}
163173
catch (Exception e)
164174
{
@@ -2704,14 +2714,27 @@ public static <T> T[] concatArrays(T[] first, T[] second) {
27042714
}
27052715

27062716

2717+
private static Pattern pagingSelectPattern;
27072718
public static String pagingSelect(String select)
27082719
{
27092720
String pagingSelect = ltrim(select);
2710-
// Quita distinct
27112721
if(pagingSelect.startsWith("DISTINCT"))
27122722
pagingSelect = pagingSelect.substring(9);
2713-
// Renombra referencias a tablas por GXICTE
27142723
pagingSelect = pagingSelect.replaceAll("T\\d+\\.", "GX_ICTE.");
2724+
if(pagingSelectPattern == null)
2725+
pagingSelectPattern = Pattern.compile("GX_ICTE\\.(\\[\\w+]) AS \\b(\\w+)\\b(?=,|$)");
2726+
Matcher match = pagingSelectPattern.matcher(pagingSelect);
2727+
HashMap<String, String> maps = new HashMap<>();
2728+
while(match.find())
2729+
{
2730+
if(match.groupCount() == 2)
2731+
{
2732+
maps.put(match.group(0), String.format("GX_ICTE.[%s]", match.group(2)));
2733+
maps.put(match.group(1), String.format("[%s]", match.group(2)));
2734+
}
2735+
}
2736+
for(Map.Entry<String, String> map : maps.entrySet())
2737+
pagingSelect = pagingSelect.replace(map.getKey(), map.getValue());
27152738
return pagingSelect;
27162739
}
27172740

@@ -3443,4 +3466,25 @@ public static String getClassName(String pgmName) {
34433466

34443467
return classPackage + pgmName.replace('\\', '.').trim();
34453468
}
3469+
3470+
private static HashMap<Character, Character> stringToHashMap(String input) {
3471+
HashMap<Character, Character> hashMap = new HashMap<>();
3472+
3473+
for (char c : input.toCharArray()) {
3474+
hashMap.put(c, c);
3475+
}
3476+
return hashMap;
3477+
}
3478+
3479+
public static String Sanitize(String input, HashMap<Character, Character> whiteList) {
3480+
StringBuilder sanitizedInput = new StringBuilder();
3481+
3482+
for (char c : input.toCharArray()) {
3483+
if (whiteList.containsKey(c)) {
3484+
char safeC = whiteList.get(c);
3485+
sanitizedInput.append(safeC);
3486+
}
3487+
}
3488+
return sanitizedInput.toString();
3489+
}
34463490
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ private byte[] loadBytes(String className)
170170
className = className.replace('.', '/') + ".class";
171171

172172
logger.debug("## GXJarClassLoader: Loading class: " + className + " [" + source + "]");
173+
BufferedInputStream bis = null;
174+
InputStream theStream = null;
173175
try
174176
{
175177
if(sourceIsJAR)
@@ -178,7 +180,7 @@ private byte[] loadBytes(String className)
178180
if((theEntry = zipFile.getEntry(className)) != null)
179181
{
180182
result = new byte[(int)theEntry.getSize()];
181-
InputStream theStream = zipFile.getInputStream(theEntry);
183+
theStream = zipFile.getInputStream(theEntry);
182184
new DataInputStream(new BufferedInputStream(theStream)).readFully(result);
183185
theStream.close();
184186
}
@@ -189,13 +191,21 @@ private byte[] loadBytes(String className)
189191
if(theFile.exists())
190192
{
191193
result = new byte[(int)theFile.length()];
192-
FileInputStream theStream = new FileInputStream(theFile);
194+
theStream = new FileInputStream(theFile);
193195
new DataInputStream(new BufferedInputStream(theStream)).readFully(result);
194196
theStream.close();
195197
classTimeStamps.put(className, new Long(theFile.lastModified()));
196198
}
197199
}
198200
}catch(IOException e) { ; }
201+
finally
202+
{
203+
try{
204+
if (bis != null) bis.close();
205+
if (theStream != null) theStream.close();
206+
}
207+
catch (IOException ioe) { logger.error("## GXJarClassLoader: Failed to close buffered input stream", ioe ); }
208+
}
199209
return result;
200210
}
201211

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ public final void writeBlobfile(String fileName)
422422

423423
if (fileName.trim().length() > 0)
424424
{
425-
try
425+
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName))))
426426
{
427-
data = CommonUtil.readToByteArray(new BufferedInputStream(new FileInputStream(new File(fileName))));
427+
data = CommonUtil.readToByteArray(bis);
428428
}
429429
catch (IOException e)
430430
{

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ private static void loadImageList(String KBId)
8989
if (is != null)
9090
{
9191
parseLocations = false;
92-
BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"));
93-
line = bufread.readLine();
94-
while (line != null)
95-
{
96-
parseLine(line, KBId);
92+
try (BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"))) {
9793
line = bufread.readLine();
94+
while (line != null) {
95+
parseLine(line, KBId);
96+
line = bufread.readLine();
97+
}
9898
}
99-
bufread.close();
10099
}
101100
}
102101
catch (UnsupportedEncodingException e)

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ private void load(String resourceName)
114114

115115
if (is != null)
116116
{
117-
BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"));
118-
line = bufread.readLine();
119-
while (line != null)
120-
{
121-
parseLine(line);
122-
line = bufread.readLine();
123-
}
124-
bufread.close();
117+
try (BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"))) {
118+
line = bufread.readLine();
119+
while (line != null) {
120+
parseLine(line);
121+
line = bufread.readLine();
122+
}
123+
}
125124
}
126125
}
127126
catch(UnsupportedEncodingException e)

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,13 @@ private static void load()
137137

138138
if (is != null)
139139
{
140-
BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"));
141-
line = bufread.readLine();
142-
while (line != null)
143-
{
144-
parseLine(line);
140+
try (BufferedReader bufread = new BufferedReader(new InputStreamReader(is, "UTF8"))) {
145141
line = bufread.readLine();
142+
while (line != null) {
143+
parseLine(line);
144+
line = bufread.readLine();
145+
}
146146
}
147-
bufread.close();
148147
}
149148
}
150149
catch (UnsupportedEncodingException e)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public abstract class GXHttpClient implements IHttpClient{
5151
private boolean isURL = false;
5252
private boolean authorizationChanged = false; // Indica si se agregó alguna autorización
5353
private boolean authorizationProxyChanged = false; // Indica si se agregó alguna autorización
54+
protected boolean isChunkedResponse;
55+
5456

5557
private Vector<HttpClientPrincipal> basicAuthorization = new Vector<>();
5658
private Vector<HttpClientPrincipal> digestAuthorization = new Vector<>();
@@ -380,6 +382,7 @@ public void addHeader(String name, String value)
380382
value = multipartTemplate.contentType;
381383
}
382384
}
385+
383386
if (this.headersToSend == null)
384387
this.headersToSend =new Hashtable<>();
385388
for (String elem: headersToSend.keySet()) {
@@ -482,6 +485,10 @@ protected void resetState()
482485

483486
public abstract String getString();
484487

488+
public abstract String readChunk();
489+
490+
public abstract boolean getEof();
491+
485492
public abstract void toFile(String fileName);
486493

487494
public abstract void cleanup();
@@ -630,9 +637,9 @@ else if (curr instanceof byte[])
630637
{
631638
file = (File) curr;
632639
}
633-
try
640+
try (BufferedInputStream bis = new java.io.BufferedInputStream(new FileInputStream(file)))
634641
{
635-
out = addToArray(out, CommonUtil.readToByteArray(new java.io.BufferedInputStream(new FileInputStream(file))));
642+
out = addToArray(out, CommonUtil.readToByteArray(bis));
636643
}
637644
catch (FileNotFoundException e)
638645
{

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ public String getString()
253253
return session.getString();
254254
}
255255

256+
public String readChunk()
257+
{
258+
return session.readChunk();
259+
}
260+
261+
public boolean getEof()
262+
{
263+
return session.getEof();
264+
}
265+
256266
public void toFile(String fileName)
257267
{
258268
session.toFile(fileName);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ public String getString()
437437
return "";
438438
}
439439

440+
public boolean getEof() {
441+
return true;
442+
}
443+
444+
public String readChunk() {
445+
return getString();
446+
}
447+
440448
@Override
441449
public void toFile(String fileName)
442450
{

0 commit comments

Comments
 (0)