Skip to content

Commit

Permalink
Added check for HttpUrlConnection to changes done in #460
Browse files Browse the repository at this point in the history
  • Loading branch information
chrjohn committed Jul 27, 2023
1 parent 565127e commit a699570
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 12 additions & 4 deletions quickfixj-core/src/main/java/quickfix/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;


public class FileUtil {
Expand Down Expand Up @@ -144,10 +145,17 @@ public static InputStream open(Class<?> clazz, String name, Location... location
case URL:
try {
URL url = new URL(name);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestProperty("User-Agent", "Java-QuickFIXJ-FileUtil");
httpURLConnection.connect();
in = httpURLConnection.getInputStream();
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 a699570

Please sign in to comment.