Skip to content
Merged
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
9 changes: 9 additions & 0 deletions java/src/main/java/com/genexus/GXutil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import com.genexus.common.interfaces.SpecificImplementation;
import com.genexus.db.DataStoreProvider;
import com.genexus.db.GXEmbedding;
import com.genexus.internet.HttpClient;
import com.genexus.internet.HttpContext;
import com.genexus.internet.StringCollection;
import com.genexus.platform.INativeFunctions;
import com.genexus.platform.NativeFunctions;
import com.genexus.util.*;

import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -1782,4 +1784,11 @@ public static String embeddingToStr(GXEmbedding embedding) {
return embedding.toString();
}

public static byte[] ImageUrlToBytes(String url) throws IOException{
HttpClient httpClient = new HttpClient();
httpClient.execute( "GET", url);
try (InputStream in = httpClient.getInputStream()) {
return IOUtils.toByteArray(in);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1391,10 +1391,10 @@ public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws
int queryIndex = fileName.lastIndexOf('?');
if (queryIndex > -1)
fileName = fileName.substring(0, queryIndex + 1) + PrivateUtilities.encodeURL(fileName.substring(queryIndex + 1));
URL fileURL = new URL(fileName);
String fileURL = fileName;
String blobPath = com.genexus.Preferences.getDefaultPreferences().getBLOB_PATH();
fileName = com.genexus.PrivateUtilities.getTempFileName(blobPath, CommonUtil.getFileName(fileName), CommonUtil.getFileType(fileName), true);
com.genexus.PrivateUtilities.InputStreamToFile(fileURL.openStream() ,fileName);
new com.genexus.util.GXFile(fileName).fromBytes(GXutil.ImageUrlToBytes(fileURL));
}
}
catch(MalformedURLException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public HttpClientJavaLib() {
if (isFirstIpDnsEnabled()) {
builder.setDnsResolver(FIRST_IP_DNS_RESOLVER);
}
String userAgent = clientCfg.getProperty("Client", "UserAgentHeader", "");
if (!userAgent.isEmpty()) {
builder.setUserAgent(userAgent);
}
httpClientBuilder = builder;
cookies = new BasicCookieStore();
streamsToClose = new Vector<>();
Expand Down
9 changes: 3 additions & 6 deletions java/src/main/java/com/genexus/reports/PDFReportItext2.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.genexus.ApplicationContext;
import com.genexus.CommonUtil;
import com.genexus.GXutil;
import com.genexus.ModelContext;
import com.genexus.platform.NativeFunctions;
import com.genexus.webpanels.HttpContextWeb;
Expand Down Expand Up @@ -396,9 +397,8 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom
}
}
}
catch(java.lang.IllegalArgumentException ex) {//Puede ser una url absoluta
java.net.URL url= new java.net.URL(bitmap);
image = com.lowagie.text.Image.getInstance(url);
catch(java.lang.IllegalArgumentException | IOException ex) {//Puede ser una url absoluta
image = com.lowagie.text.Image.getInstance(GXutil.ImageUrlToBytes(bitmap));
}

if (documentImages == null) {
Expand Down Expand Up @@ -443,9 +443,6 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom
catch(DocumentException de) {
log.error("GxDrawBitMap failed:", de);
}
catch(IOException ioe) {
log.error("GxDrawBitMap failed:", ioe);
}
catch(Exception e) {
log.error("GxDrawBitMap failed:", e);
}
Expand Down
6 changes: 3 additions & 3 deletions java/src/main/java/com/genexus/reports/PDFReportItext8.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.genexus.ApplicationContext;
import com.genexus.CommonUtil;
import com.genexus.GXutil;
import com.genexus.ModelContext;
import com.genexus.platform.NativeFunctions;
import com.genexus.reports.fonts.PDFFont;
Expand Down Expand Up @@ -425,9 +426,8 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom
}
}
}
catch(java.lang.IllegalArgumentException ex) {
URL url= new java.net.URL(bitmap);
imageData = ImageDataFactory.create(url);
catch(java.lang.IllegalArgumentException | com.itextpdf.io.exceptions.IOException ex) {
imageData = ImageDataFactory.create(GXutil.ImageUrlToBytes(bitmap));
}

if (documentImages == null) {
Expand Down
6 changes: 3 additions & 3 deletions java/src/main/java/com/genexus/reports/PDFReportPDFBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.genexus.ApplicationContext;
import com.genexus.CommonUtil;
import com.genexus.GXutil;
import com.genexus.ModelContext;
import com.genexus.platform.NativeFunctions;
import com.genexus.webpanels.HttpContextWeb;
Expand Down Expand Up @@ -377,9 +378,8 @@ public void GxDrawBitMap(String bitmap, int left, int top, int right, int bottom
}
}
}
catch(java.lang.IllegalArgumentException ex) {
URL url= new java.net.URL(bitmap);
image = PDImageXObject.createFromByteArray(document, IOUtils.toByteArray(url.openStream()),bitmap);
catch(java.lang.IllegalArgumentException | java.io.FileNotFoundException ex) {
image = PDImageXObject.createFromByteArray(document, GXutil.ImageUrlToBytes(bitmap),bitmap);
}

if (documentImages == null) {
Expand Down
Loading