Skip to content

Commit e9c0731

Browse files
committed
Merge remote-tracking branch 'qfj-repo-remote/master' into fix-orchestra-with-updated-project-structure
2 parents ec0e8e9 + e612ee6 commit e9c0731

File tree

6 files changed

+127
-24
lines changed

6 files changed

+127
-24
lines changed

quickfixj-base/src/main/java/quickfix/FileUtil.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.io.InputStream;
2727
import java.net.HttpURLConnection;
2828
import java.net.URL;
29+
import java.net.URLConnection;
30+
2931

3032

3133
public class FileUtil {
@@ -144,10 +146,17 @@ public static InputStream open(Class<?> clazz, String name, Location... location
144146
case URL:
145147
try {
146148
URL url = new URL(name);
147-
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
148-
httpURLConnection.setRequestProperty("User-Agent", "Java-QuickFIXJ-FileUtil");
149-
httpURLConnection.connect();
150-
in = httpURLConnection.getInputStream();
149+
URLConnection urlConnection = url.openConnection();
150+
if (urlConnection instanceof HttpURLConnection) {
151+
HttpURLConnection httpURLConnection = (HttpURLConnection)urlConnection;
152+
httpURLConnection.setRequestProperty("User-Agent", "Java-QuickFIXJ-FileUtil");
153+
httpURLConnection.connect();
154+
in = httpURLConnection.getInputStream();
155+
} else {
156+
if (urlConnection != null) {
157+
in = urlConnection.getInputStream();
158+
}
159+
}
151160
} catch (IOException e) {
152161
// ignore
153162
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*******************************************************************************
2+
* Copyright (c) quickfixengine.org All rights reserved.
3+
*
4+
* This file is part of the QuickFIX FIX Engine
5+
*
6+
* This file may be distributed under the terms of the quickfixengine.org
7+
* license as defined by quickfixengine.org and appearing in the file
8+
* LICENSE included in the packaging of this file.
9+
*
10+
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
11+
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
12+
* PARTICULAR PURPOSE.
13+
*
14+
* See http://www.quickfixengine.org/LICENSE for licensing information.
15+
*
16+
* Contact ask@quickfixengine.org if any conditions of this licensing
17+
* are not clear to you.
18+
******************************************************************************/
19+
20+
package quickfix;
21+
22+
import static org.junit.Assert.assertEquals;
23+
import static org.junit.Assert.assertNotNull;
24+
import static org.junit.Assert.assertTrue;
25+
26+
import java.io.InputStream;
27+
import java.net.Socket;
28+
29+
import org.junit.Test;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
public class FileUtilTest {
34+
private final Logger log = LoggerFactory.getLogger(getClass());
35+
36+
@Test
37+
public void testFileLocation() throws Exception {
38+
// Assumption: current directory is QFJ project base directory
39+
InputStream in = FileUtil.open(null, "LICENSE");
40+
in.close();
41+
assertNotNull("File not found", in);
42+
}
43+
44+
@Test
45+
public void testClassResourceLocation() throws Exception {
46+
InputStream in = FileUtil.open(Message.class, "Session.class");
47+
in.close();
48+
assertNotNull("Resource not found", in);
49+
}
50+
51+
@Test
52+
public void testClassLoaderResourceLocation() throws Exception {
53+
InputStream in = FileUtil.open(Message.class, "quickfix/test/acceptance/definitions/client/Normal.def");
54+
in.close();
55+
assertNotNull("Resource not found", in);
56+
}
57+
58+
@Test
59+
public void testURLLocation() throws Exception {
60+
// Assumption: Internet access
61+
if (isInternetAccessible()) {
62+
InputStream in = FileUtil.open(Message.class, "http://www.quickfixj.org/");
63+
if (in != null) {
64+
in.close();
65+
}
66+
assertNotNull("Resource not found", in);
67+
}
68+
}
69+
70+
@Test
71+
public void testJARURLLocation() throws Exception {
72+
// just test that we don't run into a ClassCastException
73+
InputStream in = FileUtil.open(Message.class, "jar:file:/foo.bar!/");
74+
if (in != null) {
75+
in.close();
76+
}
77+
}
78+
79+
@Test
80+
// QFJ-775
81+
public void testSessionIDFileName() {
82+
SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER???",
83+
"bla_/--/#()_bla", "!!!TARGET", "foo::bar");
84+
String sessionIdFileName = FileUtil.sessionIdFileName(sessionID);
85+
assertEquals("FIX.4.4-SENDER____bla__--_____bla-___TARGET_foo__bar", sessionIdFileName);
86+
assertTrue(sessionIdFileName.matches("[a-zA-Z0-9-._]*"));
87+
88+
sessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET");
89+
sessionIdFileName = FileUtil.sessionIdFileName(sessionID);
90+
assertEquals("FIX.4.4-SENDER-TARGET", sessionIdFileName);
91+
}
92+
93+
private boolean isInternetAccessible() {
94+
try {
95+
Socket socket = new Socket("www.quickfixj.org", 80);
96+
socket.close();
97+
return true;
98+
} catch (Exception e) {
99+
log.warn("No internet access");
100+
}
101+
return false;
102+
}
103+
}

quickfixj-core/src/main/doc/usermanual/usage/configuration.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ <H3>QuickFIX Settings</H3>
283283
<TD> Valid XML data dictionary file, QuickFIX/J comes with the following defaults in the <code>etc</code> directory:
284284
FIXT11.xml, FIX50.xml, FIX44.xml, FIX43.xml, FIX42.xml, FIX41.xml, FIX40.xml.
285285
</TD>
286-
<TD>If DataDictionary is not specified and UserDataDictionary=Y, then QuickFIX/J will look for a
286+
<TD>If DataDictionary is not specified and UseDataDictionary=Y, then QuickFIX/J will look for a
287287
default dictionary based on the session's BeginString (e.g., FIX.4.2 = FIX42.xml). The DataDictionary
288288
file search strategy is to use a URL, then the file system, and then the thread context classloader (if any),
289289
and then the DataDictionary instance's classloader. Default data dictionary files
@@ -1267,7 +1267,7 @@ <H3>QuickFIX Settings</H3>
12671267
<TR ALIGN="left" VALIGN="middle">
12681268
<TD> <I>ResendRequestChunkSize</I> </TD>
12691269
<TD> Setting to limit the size of a resend request in case of missing messages.
1270-
This is useful when the remote FIX engine does not allow to ask for more than n message for a ResendRequest.
1270+
This is useful when the remote FIX engine does not allow to ask for more than n message for a ResendRequest. It also allows you to prevent a 'self-DDOS' by accidentally requesting a huge flood of messages your system isn't capable of processing if you are substantially behind for some reason.
12711271
<P>
12721272
E.g. if the ResendRequestChunkSize is set to 5 and a gap of 7 messages is detected,
12731273
a first resend request will be sent for 5 messages.

quickfixj-core/src/test/java/quickfix/FileUtilTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public void testURLLocation() throws Exception {
6767
}
6868
}
6969

70+
@Test
71+
public void testJARURLLocation() throws Exception {
72+
// just test that we don't run into a ClassCastException
73+
InputStream in = FileUtil.open(Message.class, "jar:file:/foo.bar!/");
74+
if (in != null) {
75+
in.close();
76+
}
77+
}
78+
7079
@Test
7180
// QFJ-775
7281
public void testSessionIDFileName() {

quickfixj-distribution/src/main/assembly/distribution.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@
2626
<exclude>classworlds:*</exclude>
2727
</excludes>
2828
</dependencySet>
29-
<!--
30-
Due to an assembly bug, a dependency that appears both in test scope
31-
and another scope (compile/runtime) in two different modules will be
32-
excluded. We re-include these here manually for now.
33-
-->
34-
<dependencySet>
35-
<outputDirectory>lib</outputDirectory>
36-
<scope>test</scope>
37-
<includes>
38-
<include>org.slf4j:slf4j-jdk14</include>
39-
</includes>
40-
</dependencySet>
4129
</dependencySets>
4230
</binaries>
4331
</moduleSet>

quickfixj-examples/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
<artifactId>slf4j-api</artifactId>
3737
<version>${slf4j.version}</version>
3838
</dependency>
39-
<dependency>
40-
<groupId>org.slf4j</groupId>
41-
<artifactId>slf4j-jdk14</artifactId>
42-
<version>${slf4j.version}</version>
43-
<scope>runtime</scope>
44-
</dependency>
4539
</dependencies>
4640

4741
<build>

0 commit comments

Comments
 (0)