Skip to content

Commit 5bbe480

Browse files
authored
Merge pull request #191 from rosette-api/ws-2537-fix-javadoc-generation-for-maven-central-requirement
WS-2537: Fix Javadoc generation. And upgrades.
2 parents c71d228 + 7493e97 commit 5bbe480

File tree

52 files changed

+375
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+375
-262
lines changed

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

annotations/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
<dependency>
3939
<groupId>com.squareup</groupId>
4040
<artifactId>javapoet</artifactId>
41-
<version>1.9.0</version>
41+
<version>${java-poet.version}</version>
4242
<scope>provided</scope>
4343
</dependency>
4444
<dependency>
4545
<groupId>org.projectlombok</groupId>
4646
<artifactId>lombok</artifactId>
47-
<version>1.18.20</version>
47+
<version>${lombok.version}</version>
4848
<scope>provided</scope>
4949
</dependency>
5050
</dependencies>

annotations/src/main/java/com/basistech/rosette/annotations/JacksonMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Basis Technology Corp.
2+
* Copyright 2017-2022 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,4 +24,4 @@
2424
@Retention(RetentionPolicy.SOURCE)
2525
@Target(ElementType.TYPE)
2626
public @interface JacksonMixin {
27-
}
27+
}

api/pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@
5454
<dependency>
5555
<groupId>org.apache.httpcomponents</groupId>
5656
<artifactId>httpclient</artifactId>
57-
<version>${http-components-version}</version>
57+
<version>${http-components.version}</version>
5858
</dependency>
5959
<dependency>
6060
<groupId>org.apache.httpcomponents</groupId>
6161
<artifactId>httpclient-osgi</artifactId>
62-
<version>${http-components-version}</version>
62+
<version>${http-components.version}</version>
6363
</dependency>
6464
<dependency>
6565
<groupId>org.apache.httpcomponents</groupId>
6666
<artifactId>httpcore-osgi</artifactId>
67-
<version>${http-components-core-version}</version>
67+
<version>${http-components-core.version}</version>
6868
</dependency>
6969
<dependency>
7070
<groupId>org.apache.httpcomponents</groupId>
7171
<artifactId>httpmime</artifactId>
72-
<version>${http-components-version}</version>
72+
<version>${http-components.version}</version>
7373
</dependency>
7474
<dependency>
7575
<groupId>org.slf4j</groupId>
@@ -82,19 +82,19 @@
8282
<dependency>
8383
<groupId>org.mock-server</groupId>
8484
<artifactId>mockserver-client-java</artifactId>
85-
<version>${mockserver-version}</version>
85+
<version>${mockserver.version}</version>
8686
<scope>test</scope>
8787
</dependency>
8888
<dependency>
8989
<groupId>org.mock-server</groupId>
9090
<artifactId>mockserver-core</artifactId>
91-
<version>${mockserver-version}</version>
91+
<version>${mockserver.version}</version>
9292
<scope>test</scope>
9393
</dependency>
9494
<dependency>
9595
<groupId>org.mock-server</groupId>
9696
<artifactId>mockserver-netty</artifactId>
97-
<version>${mockserver-version}</version>
97+
<version>${mockserver.version}</version>
9898
<scope>test</scope>
9999
</dependency>
100100
<dependency>
@@ -140,7 +140,7 @@
140140
<plugin>
141141
<groupId>org.mock-server</groupId>
142142
<artifactId>mockserver-maven-plugin</artifactId>
143-
<version>${mockserver-version}</version>
143+
<version>${mockserver.version}</version>
144144
<configuration>
145145
<serverPort>${mockServerClient.port}</serverPort>
146146
<logLevel>WARN</logLevel>

api/src/main/java/com/basistech/rosette/api/HttpRosetteAPI.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Basis Technology Corp.
2+
* Copyright 2017-2022 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,6 +73,7 @@
7373
import java.util.Properties;
7474
import java.util.Set;
7575
import java.util.concurrent.Future;
76+
import java.util.regex.Pattern;
7677
import java.util.zip.GZIPInputStream;
7778

7879
import static java.net.HttpURLConnection.HTTP_OK;
@@ -85,8 +86,11 @@ public class HttpRosetteAPI extends AbstractRosetteAPI {
8586
public static final String DEFAULT_URL_BASE = "https://api.rosette.com/rest/v1";
8687
public static final String SERVICE_NAME = "RosetteAPI";
8788
public static final String BINDING_VERSION = getVersion();
88-
public static final String USER_AGENT_STR = SERVICE_NAME + "-Java/" + BINDING_VERSION + "/" + System.getProperty("java.version");
89+
public static final String USER_AGENT_STR = SERVICE_NAME + "-Java/" + BINDING_VERSION + "/"
90+
+ System.getProperty("java.version");
8991
private static final Logger LOG = LoggerFactory.getLogger(HttpRosetteAPI.class);
92+
private static final String IO_EXCEPTION_MESSAGE = "IO Exception communicating with the Rosette API";
93+
private static final Pattern TRAILING_SLASHES = Pattern.compile("/+$");
9094
private String urlBase = DEFAULT_URL_BASE;
9195
private int failureRetries = 1;
9296
private ObjectMapper mapper;
@@ -116,7 +120,7 @@ private HttpRosetteAPI() {
116120
HttpRosetteAPI(String key, String urlToCall, Integer failureRetries,
117121
CloseableHttpClient httpClient, List<Header> additionalHeaders,
118122
Integer connectionConcurrency, boolean onlyAcceptKnownFields) throws HttpRosetteAPIException {
119-
urlBase = urlToCall == null ? urlBase : urlToCall.trim().replaceAll("/+$", "");
123+
urlBase = urlToCall == null ? urlBase : TRAILING_SLASHES.matcher(urlToCall.trim()).replaceAll("");
120124
if (failureRetries != null && failureRetries >= 1) {
121125
this.failureRetries = failureRetries;
122126
}
@@ -241,7 +245,8 @@ public PingResponse ping() throws IOException, HttpRosetteAPIException {
241245
@Override
242246
public SupportedLanguagesResponse getSupportedLanguages(String endpoint) throws HttpRosetteAPIException {
243247
if (DOC_ENDPOINTS.contains(endpoint) || NAME_DEDUPLICATION_SERVICE_PATH.equals(endpoint)) {
244-
return sendGetRequest(urlBase + endpoint + SUPPORTED_LANGUAGES_SUBPATH, SupportedLanguagesResponse.class);
248+
return sendGetRequest(urlBase + endpoint + SUPPORTED_LANGUAGES_SUBPATH,
249+
SupportedLanguagesResponse.class);
245250
} else {
246251
return null;
247252
}
@@ -258,7 +263,8 @@ public SupportedLanguagesResponse getSupportedLanguages(String endpoint) throws
258263
@Override
259264
public SupportedLanguagePairsResponse getSupportedLanguagePairs(String endpoint) throws HttpRosetteAPIException {
260265
if (NAMES_ENDPOINTS.contains(endpoint) && !NAME_DEDUPLICATION_SERVICE_PATH.equals(endpoint)) {
261-
return sendGetRequest(urlBase + endpoint + SUPPORTED_LANGUAGES_SUBPATH, SupportedLanguagePairsResponse.class);
266+
return sendGetRequest(urlBase + endpoint + SUPPORTED_LANGUAGES_SUBPATH,
267+
SupportedLanguagePairsResponse.class);
262268
} else {
263269
return null;
264270
}
@@ -276,11 +282,12 @@ public SupportedLanguagePairsResponse getSupportedLanguagePairs(String endpoint)
276282
* @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
277283
*/
278284
@Override
279-
public <RequestType extends Request, ResponseType extends Response> ResponseType perform(String endpoint, RequestType request, Class<ResponseType> responseClass) throws HttpRosetteAPIException {
285+
public <RequestType extends Request, ResponseType extends Response> ResponseType perform(String endpoint,
286+
RequestType request, Class<ResponseType> responseClass) throws HttpRosetteAPIException {
280287
try {
281288
return sendPostRequest(request, urlBase + endpoint, responseClass);
282289
} catch (IOException e) {
283-
throw new RosetteRuntimeException("IO Exception communicating with the Rosette API", e);
290+
throw new RosetteRuntimeException(IO_EXCEPTION_MESSAGE, e);
284291
} catch (URISyntaxException e) {
285292
throw new RosetteRuntimeException("Invalid URI", e);
286293
}
@@ -296,11 +303,12 @@ public <RequestType extends Request, ResponseType extends Response> ResponseType
296303
* @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
297304
*/
298305
@Override
299-
public <RequestType extends Request> AnnotatedText perform(String endpoint, RequestType request) throws HttpRosetteAPIException {
306+
public <RequestType extends Request> AnnotatedText perform(String endpoint, RequestType request)
307+
throws HttpRosetteAPIException {
300308
try {
301309
return sendPostRequest(request, urlBase + endpoint, AnnotatedText.class);
302310
} catch (IOException e) {
303-
throw new RosetteRuntimeException("IO Exception communicating with the Rosette API", e);
311+
throw new RosetteRuntimeException(IO_EXCEPTION_MESSAGE, e);
304312
} catch (URISyntaxException e) {
305313
throw new RosetteRuntimeException("Invalid URI", e);
306314
}
@@ -310,7 +318,9 @@ public <RequestType extends Request> AnnotatedText perform(String endpoint, Requ
310318
* This method always throws UnsupportedOperationException.
311319
*/
312320
@Override
313-
public <RequestType extends Request, ResponseType extends Response> Future<ResponseType> performAsync(String endpoint, RequestType request, Class<ResponseType> responseClass) throws HttpRosetteAPIException {
321+
public <RequestType extends Request, ResponseType extends Response> Future<ResponseType>
322+
performAsync(String endpoint, RequestType request, Class<ResponseType> responseClass)
323+
throws HttpRosetteAPIException {
314324
throw new UnsupportedOperationException("Asynchronous operations are not yet supported");
315325
}
316326

@@ -335,7 +345,7 @@ private <T extends Response> T sendGetRequest(String urlStr, Class<T> clazz) thr
335345
responseHeadersToExtendedInformation(resp, httpResponse);
336346
return resp;
337347
} catch (IOException e) {
338-
throw new RosetteRuntimeException("IO Exception communicating with the Rosette API", e);
348+
throw new RosetteRuntimeException(IO_EXCEPTION_MESSAGE, e);
339349
}
340350
}
341351

@@ -349,7 +359,8 @@ private <T extends Response> T sendGetRequest(String urlStr, Class<T> clazz) thr
349359
* @return Response
350360
* @throws IOException
351361
*/
352-
private <T> T sendPostRequest(Object request, String urlStr, Class<T> clazz) throws IOException, URISyntaxException {
362+
private <T> T sendPostRequest(Object request, String urlStr, Class<T> clazz)
363+
throws IOException, URISyntaxException {
353364
ObjectWriter writer = mapper.writer().without(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
354365
boolean notPlainText = false;
355366
if (request instanceof DocumentRequest) {
@@ -391,7 +402,7 @@ private <T> T sendPostRequest(Object request, String urlStr, Class<T> clazz) thr
391402
T resp = getResponse(response, clazz);
392403
Header ridHeader = response.getFirstHeader("X-RosetteAPI-DocumentRequest-Id");
393404
if (ridHeader != null && ridHeader.getValue() != null) {
394-
LOG.debug("DocumentRequest ID " + ridHeader.getValue());
405+
LOG.debug("DocumentRequest ID {}", ridHeader.getValue());
395406
}
396407
if (resp instanceof Response) {
397408
responseHeadersToExtendedInformation((Response)resp, response);
@@ -418,7 +429,8 @@ private <T extends Response> void responseHeadersToExtendedInformation(T resp, H
418429
if (resp.getExtendedInformation().get(header.getName()) instanceof Set) {
419430
currentSetValue = (Set<Object>) resp.getExtendedInformation().get(header.getName());
420431
} else {
421-
currentSetValue = new HashSet<>(Collections.singletonList(resp.getExtendedInformation().get(header.getName())));
432+
currentSetValue = new HashSet<>(Collections.singletonList(resp
433+
.getExtendedInformation().get(header.getName())));
422434
}
423435
currentSetValue.add(header.getValue());
424436
resp.addExtendedInformation(header.getName(), currentSetValue);
@@ -459,7 +471,8 @@ public boolean isStreaming() {
459471
});
460472
}
461473

462-
private void setupMultipartRequest(final Request request, final ObjectWriter finalWriter, HttpPost post) throws IOException {
474+
private void setupMultipartRequest(final Request request, final ObjectWriter finalWriter, HttpPost post)
475+
throws IOException {
463476
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
464477
builder.setMimeSubtype("mixed");
465478
builder.setMode(HttpMultipartMode.STRICT);
@@ -533,7 +546,8 @@ private String headerValueOrNull(Header header) {
533546
* @return Response
534547
* @throws IOException
535548
*/
536-
private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> clazz) throws IOException, HttpRosetteAPIException {
549+
private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> clazz)
550+
throws IOException, HttpRosetteAPIException {
537551
int status = httpResponse.getStatusLine().getStatusCode();
538552
String encoding = headerValueOrNull(httpResponse.getFirstHeader(HttpHeaders.CONTENT_ENCODING));
539553

@@ -548,15 +562,16 @@ private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> cla
548562
if ("application/json".equals(responseContentType)) {
549563
ErrorResponse errorResponse = mapper.readValue(inputStream, ErrorResponse.class);
550564
if (ridHeader != null) {
551-
LOG.debug("DocumentRequest ID " + ridHeader);
565+
LOG.debug("DocumentRequest ID {}", ridHeader);
552566
}
553567
if (ecHeader != null) {
554568
errorResponse.setCode(ecHeader);
555569
}
556570
if (429 == status) {
557571
String concurrencyMessage = "You have exceeded your plan's limit on concurrent calls. "
558-
+ "This could be caused by multiple processes or threads making Rosette API calls in parallel, "
559-
+ "or if your httpClient is configured with higher concurrency than your plan allows.";
572+
+ "This could be caused by multiple processes or threads making Rosette API calls "
573+
+ "in parallel, or if your httpClient is configured with higher concurrency "
574+
+ "than your plan allows.";
560575
if (emHeader == null) {
561576
emHeader = concurrencyMessage;
562577
} else {
@@ -677,6 +692,7 @@ public Builder additionalHeader(String name, String value) {
677692
* Only process the response from server if all fields are recognized. If set and a new
678693
* field is returned in the response, exception will be thrown.
679694
*
695+
* @param onlyAcceptKnownFields whether to accept known fields.
680696
* @return this.
681697
*/
682698
public Builder onlyAcceptKnownFields(boolean onlyAcceptKnownFields) {

api/src/test/java/com/basistech/rosette/api/BasicTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Basis Technology Corp.
2+
* Copyright 2017-2022 Basis Technology Corp.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,11 +64,12 @@ public class BasicTest extends AbstractTest {
6464
private MockServerClient mockServer;
6565
private HttpRosetteAPI api;
6666

67-
private static int getFreePort() {
67+
public BasicTest() throws IOException {
68+
}
69+
70+
private static int getFreePort() throws IOException {
6871
try (ServerSocket socket = new ServerSocket(0)) {
6972
serverPort = socket.getLocalPort();
70-
} catch (IOException e) {
71-
fail("Failed to allocate a port");
7273
}
7374
assertNotEquals(0, serverPort);
7475
return serverPort;
@@ -118,7 +119,7 @@ public void testMultipleConnections() throws IOException, InterruptedException {
118119

119120
Date d2 = new Date();
120121

121-
assert d2.getTime() - d1.getTime() > delayTime * numConnections * 1000; // at least as long as the delay in the request
122+
assertTrue(d2.getTime() - d1.getTime() > delayTime * numConnections * 1000); // at least as long as the delay in the request
122123

123124
api = new HttpRosetteAPI.Builder().connectionConcurrency(numConnections)
124125
.url(String.format("http://localhost:%d/rest/v1", serverPort))
@@ -137,8 +138,8 @@ public void testMultipleConnections() throws IOException, InterruptedException {
137138

138139
d2 = new Date();
139140

140-
assert d2.getTime() - d1.getTime() < delayTime * numConnections * 1000; // less than (numConnections) serial requests
141-
assert d2.getTime() - d1.getTime() > delayTime * 1000; // but at least as long as one
141+
assertTrue(d2.getTime() - d1.getTime() < delayTime * numConnections * 1000); // less than (numConnections) serial requests
142+
assertTrue(d2.getTime() - d1.getTime() > delayTime * 1000); // but at least as long as one
142143
}
143144

144145
@Test
@@ -159,7 +160,8 @@ public void testHeaders() throws Exception {
159160
.url(String.format("http://localhost:%d/rest/v1", serverPort))
160161
.additionalHeader("X-Foo", "Bar")
161162
.build();
162-
api.ping();
163+
var resp = api.ping();
164+
assertEquals("5", resp.getExtendedInformation().get("X-RosetteAPI-Concurrency"));
163165
}
164166

165167
@Test

0 commit comments

Comments
 (0)