Skip to content

Commit 26d8acb

Browse files
Client enhancement (#18)
* adding the possibility to use extra headers * trustSSL
1 parent 297dbe6 commit 26d8acb

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.geosiris</groupId>
55
<artifactId>etpproto-java</artifactId>
66
<name>${project.groupId}:${project.artifactId}</name>
7-
<version>1.0.5</version>
7+
<version>1.0.6</version>
88
<organization>
99
<name>Geosiris</name>
1010
<url>http://www.geosiris.com</url>

src/example/com/geosiris/etp/example/Main.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public static void main(String[] args) throws Exception {
7373
// putDA_REST(args);
7474
// putDA_split(args);
7575
test_external_server(args);
76+
// test_get_big_data_array_2(args);
7677
}
7778

7879
public static void test_external_server(String[] args) throws Exception {
@@ -280,6 +281,21 @@ public static void test_get_big_data_array(String[] args) throws Exception {
280281
// ETPHelper.sendGetDataArray(client, uri, "/RESQML/3a45fb70-8ba9-4341-a701-0f514270ba9c/points_patch0", 50000);
281282
var m = ETPHelper.getMultipleDataArrays(client, uri, List.of("/RESQML/3a45fb70-8ba9-4341-a701-0f514270ba9c/points_patch0"), 50000);
282283
// logger.info(m);
284+
// Thread.sleep(3000000);
285+
}finally {
286+
client.closeClient();
287+
}
288+
289+
}
290+
public static void test_get_big_data_array_2(String[] args) throws Exception {
291+
ETPClient client = getClient(1<<22, args);
292+
293+
String uri = "eml:///dataspace('bpmn')/resqml20.obj_PointSetRepresentation(91ef4b87-3d9d-4a3e-b753-8caa0cdc5931)";
294+
try {
295+
// ETPHelper.sendGetDataArray(client, uri, "/RESQML/3a45fb70-8ba9-4341-a701-0f514270ba9c/points_patch0", 50000);
296+
// var m = ETPHelper.sendGetDataArray_prettier(client, uri, "/RESQML/6567dc5c-4bf5-491a-b019-bd067d355587/points_patch", 50000, true);
297+
var m = ETPHelper.getMultipleDataArrays(client, uri, List.of("/RESQML/6567dc5c-4bf5-491a-b019-bd067d355587/points_patch"), 50000);
298+
logger.info(m.values().iterator().next());
283299
// Thread.sleep(3000000);
284300
}finally {
285301
client.closeClient();

src/main/java/com/geosiris/etp/communication/ETPConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static List<SupportedProtocol> computeSupportedProtocols(Map<Communicatio
159159
for(Map.Entry<CommunicationProtocol, ProtocolHandler> ph: protocolHandlers.entrySet()){
160160
supported.add(new SupportedProtocol(
161161
ph.getKey().id,
162-
new Version(),
162+
Version.newBuilder().setMajor(1).setMinor(2).build(), // TODO: change version when etp changes
163163
"store",
164164
new HashMap<>()
165165
));

src/main/java/com/geosiris/etp/websocket/ETPClient.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@
2323
import com.geosiris.etp.communication.*;
2424
import com.geosiris.etp.utils.ETPDefaultProtocolBuilder;
2525
import com.geosiris.etp.utils.ETPUtils;
26+
import com.google.gson.Gson;
2627
import org.apache.avro.specific.SpecificRecordBase;
2728
import org.apache.logging.log4j.LogManager;
2829
import org.apache.logging.log4j.Logger;
2930
import org.eclipse.jetty.http.HttpURI;
31+
import org.eclipse.jetty.util.ssl.SslContextFactory;
3032
import org.eclipse.jetty.websocket.api.Session;
3133
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
3234
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
3335
import org.eclipse.jetty.websocket.client.WebSocketClient;
3436

37+
import javax.net.ssl.SSLContext;
3538
import java.net.ConnectException;
3639
import java.net.URI;
3740
import java.util.*;
@@ -139,7 +142,11 @@ public final static ETPClient getInstance(
139142
ETPClient etpClient = new ETPClient(serverUri, etpConnection, maxMsgSize);
140143

141144
try {
142-
etpClient.wsclient = new WebSocketClient();
145+
146+
SslContextFactory sslContextFactory = new SslContextFactory();
147+
sslContextFactory.setTrustAll(true);
148+
etpClient.wsclient = new WebSocketClient(sslContextFactory);
149+
143150
// etpClient.wsclient.setMaxTextMessageBufferSize(maxMsgSize);
144151
etpClient.wsclient.setMaxBinaryMessageBufferSize(maxMsgSize);
145152

@@ -154,10 +161,9 @@ public final static ETPClient getInstance(
154161
// etpClient.wsclient.setMaxTextMessageBufferSize((int) etpClient.maxByteSizePerMessage);
155162
ClientUpgradeRequest request = new ClientUpgradeRequest();
156163

157-
158-
for(Map.Entry<String, String> e: headers.entrySet()){
159-
request.setHeader(e.getKey(), e.getValue());
160-
}
164+
//for(Map.Entry<String, String> e: headers.entrySet()){
165+
// request.setHeader(e.getKey(), e.getValue());
166+
//}
161167

162168
if (auth_basic_or_bearer != null && !auth_basic_or_bearer.isEmpty()) {
163169
request.setHeader("Authorization", auth_basic_or_bearer);
@@ -166,10 +172,17 @@ public final static ETPClient getInstance(
166172

167173
request.setHeader("etp-encoding", (encoding + "").toLowerCase());
168174
request.setSubProtocols(etpConnection.SUB_PROTOCOL);
175+
176+
for(Map.Entry<String, String> e: headers.entrySet()){
177+
request.setHeader(e.getKey(), e.getValue());
178+
}
179+
169180
logger.debug("try to connect to " + echoUri);
181+
logger.info("Headers : " + (new Gson()).toJson(request.getHeaders()));
170182
Future<Session> futureSession = etpClient.wsclient.connect(etpClient, echoUri, request);
171183
Session session = futureSession.get();
172184

185+
173186
session.getPolicy().setMaxBinaryMessageBufferSize(maxMsgSize);
174187
session.getPolicy().setMaxBinaryMessageSize(maxMsgSize);
175188

0 commit comments

Comments
 (0)