Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit 5e3d3da

Browse files
author
marcus.lang
committed
added client part for imageservice
1 parent 6304aae commit 5e3d3da

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

modules/app/srv/imageservice/rest/client/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<groupId>${project.groupId}</groupId>
1717
<artifactId>herbarium-m-app-srv-imagesrv-api</artifactId>
1818
</dependency>
19+
<dependency>
20+
<groupId>org.jboss.resteasy</groupId>
21+
<artifactId>resteasy-jaxrs</artifactId>
22+
</dependency>
1923
</dependencies>
2024

2125
</project>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,51 @@
11
package org.openherbarium.module.srv.imageservice.rest.endpoint;
22

3+
import javax.annotation.PostConstruct;
4+
import javax.ws.rs.client.Client;
5+
import javax.ws.rs.client.ClientBuilder;
6+
import javax.ws.rs.core.Response;
7+
import java.util.Objects;
8+
39
public class ImageServiceRestClient {
410

5-
// TODO
6-
// getImage(String id)
11+
public static final String PROPERTY_IP = "imageservice.ip";
12+
public static final String PROPERTY_PORT = "imageservice.port";
13+
public static final String DEFAULT_PORT = "8080";
14+
public static final String DEFAULT_IP = "127.0.0.1";
15+
16+
private String serverIp;
17+
private String serverPort;
18+
19+
@PostConstruct
20+
public void init() {
21+
this.serverIp = System.getProperty(PROPERTY_IP, DEFAULT_IP);
22+
this.serverPort = System.getProperty(PROPERTY_PORT, DEFAULT_PORT);
23+
if (Objects.isNull(serverIp)) throw new NullPointerException("serverIP is null");
24+
if (Objects.isNull(serverPort)) throw new NullPointerException("serverPort is null");
25+
}
26+
27+
public String getImageProperties(String imageid) {
28+
final Client client = ClientBuilder.newClient();
29+
30+
final Response response = client.target(buildBaseUrl() + imageid + "/" + "properties")
31+
.request()
32+
.get();
33+
34+
return response.readEntity(String.class);
35+
}
36+
37+
public byte[] getImage(String imageid, String tilegroup, String image) {
38+
final Client client = ClientBuilder.newClient();
39+
40+
final Response response = client.target(buildBaseUrl() + imageid + "/" + tilegroup + "/" + image)
41+
.request()
42+
.get();
43+
44+
return response.readEntity(byte[].class);
45+
}
46+
747

48+
private String buildBaseUrl() {
49+
return String.format("http://%s:%s/rest/imageservice/", serverIp, serverPort);
50+
}
851
}

0 commit comments

Comments
 (0)