Skip to content

Commit

Permalink
Correct Resource not found in FileUtilTest (#654)
Browse files Browse the repository at this point in the history
* update FileUtil to resolve new 403 error for requests with User-Agent header

* Updated User-Agent value for FileUtil

* Added check for HttpUrlConnection to changes done in #460

---------

Co-authored-by: david-gibbs-ig <[email protected]>
  • Loading branch information
chrjohn and david-gibbs-ig committed Aug 11, 2023
1 parent bf063e3 commit ba2da65
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 15 additions & 1 deletion quickfixj-core/src/main/java/quickfix/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;


public class FileUtil {
public static String fileAppendPath(String pathPrefix, String pathSuffix) {
Expand Down Expand Up @@ -141,7 +144,18 @@ public static InputStream open(Class<?> clazz, String name, Location... location
break;
case URL:
try {
in = new URL(name).openStream();
URL url = new URL(name);
URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection)urlConnection;
httpURLConnection.setRequestProperty("User-Agent", "Java-QuickFIXJ-FileUtil");
httpURLConnection.connect();
in = httpURLConnection.getInputStream();
} else {
if (urlConnection != null) {
in = urlConnection.getInputStream();
}
}
} catch (IOException e) {
// ignore
}
Expand Down
9 changes: 9 additions & 0 deletions quickfixj-core/src/test/java/quickfix/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public void testURLLocation() throws Exception {
}
}

@Test
public void testJARURLLocation() throws Exception {
// just test that we don't run into a ClassCastException
InputStream in = FileUtil.open(Message.class, "jar:file:/foo.bar!/");
if (in != null) {
in.close();
}
}

@Test
// QFJ-775
public void testSessionIDFileName() {
Expand Down

0 comments on commit ba2da65

Please sign in to comment.