11/*
2- * Copyright 2022 Basis Technology Corp.
2+ * Copyright 2024 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.
7979import static java .net .HttpURLConnection .HTTP_OK ;
8080
8181/**
82- * Access to the RosetteAPI via HTTP.
82+ * Access to the Analytics API via HTTP.
8383 */
8484public class HttpRosetteAPI extends AbstractRosetteAPI {
8585
86- public static final String DEFAULT_URL_BASE = "https://api.rosette .com/rest/v1" ;
87- public static final String SERVICE_NAME = "RosetteAPI " ;
86+ public static final String DEFAULT_URL_BASE = "https://analytics.babelstreet .com/rest/v1" ;
87+ public static final String SERVICE_NAME = "Babel-Street-Analytics-API " ;
8888 public static final String BINDING_VERSION = getVersion ();
8989 public static final String USER_AGENT_STR = SERVICE_NAME + "-Java/" + BINDING_VERSION + "/"
9090 + System .getProperty ("java.version" );
9191 private static final Logger LOG = LoggerFactory .getLogger (HttpRosetteAPI .class );
92- private static final String IO_EXCEPTION_MESSAGE = "IO Exception communicating with the Rosette API" ;
92+ private static final String IO_EXCEPTION_MESSAGE = "IO Exception communicating with the Babel Street Analytics API" ;
9393 private static final Pattern TRAILING_SLASHES = Pattern .compile ("/+$" );
9494 private String urlBase = DEFAULT_URL_BASE ;
9595 private int failureRetries = 1 ;
@@ -104,16 +104,16 @@ private HttpRosetteAPI() {
104104 }
105105
106106 /**
107- * Constructs a Rosette API instance using the builder syntax.
107+ * Constructs an Analytics API instance using the builder syntax.
108108 *
109- * @param key Rosette API key. This may be null for use with an on-premise deployment
110- * of the Rosette API.
111- * @param urlToCall Alternate Rosette API URL. {@code null} uses the default, public, URL.
109+ * @param key Analytics API key. This may be null for use with an on-premise deployment
110+ * of the Analytics API.
111+ * @param urlToCall Alternate Analytics API URL. {@code null} uses the default, public, URL.
112112 * @param failureRetries Number of times to retry in case of failure; {@code null} uses the
113113 * default value: 1.
114114 * @param connectionConcurrency Number of concurrent connections. Pass this if have subscribed
115115 * to a plan that supports enhanced concurrency, or if you are using
116- * an on-premise deployment of the Rosette API. {@code null} uses the
116+ * an on-premise deployment of the Analytics API. {@code null} uses the
117117 * default value: 2.
118118 * @throws HttpRosetteAPIException Problem with the API request
119119 */
@@ -197,7 +197,10 @@ private void initHeaders(String key, List<Header> additionalHeaders) {
197197 this .additionalHeaders .add (new BasicHeader (HttpHeaders .USER_AGENT , USER_AGENT_STR ));
198198 this .additionalHeaders .add (new BasicHeader (HttpHeaders .ACCEPT_ENCODING , "gzip" ));
199199 if (key != null ) {
200- this .additionalHeaders .add (new BasicHeader ("X-RosetteAPI-Key" , key ));
200+ this .additionalHeaders .add (new BasicHeader ("X-BabelStreetAPI-Key" , key ));
201+ this .additionalHeaders .add (new BasicHeader ("X-BabelStreetAPI-Binding" , "java" ));
202+ this .additionalHeaders .add (new BasicHeader ("X-BabelStreetAPI-Binding-Version" , BINDING_VERSION ));
203+ // TODO: Remove in a future release.
201204 this .additionalHeaders .add (new BasicHeader ("X-RosetteAPI-Binding" , "java" ));
202205 this .additionalHeaders .add (new BasicHeader ("X-RosetteAPI-Binding-Version" , BINDING_VERSION ));
203206 }
@@ -216,32 +219,32 @@ public int getFailureRetries() {
216219 }
217220
218221 /**
219- * Gets information about the Rosette API, returns name, version, build number and build time.
222+ * Gets information about the Analytics API, returns name, version, build number and build time.
220223 *
221224 * @return InfoResponse
222- * @throws HttpRosetteAPIException Rosette specific exception
225+ * @throws HttpRosetteAPIException Analytics specific exception
223226 * @throws IOException General IO exception
224227 */
225228 public InfoResponse info () throws IOException , HttpRosetteAPIException {
226229 return sendGetRequest (urlBase + INFO_SERVICE_PATH , InfoResponse .class );
227230 }
228231
229232 /**
230- * Pings the Rosette API for a response indicating that the service is available.
233+ * Pings the Analytics API for a response indicating that the service is available.
231234 *
232235 * @return PingResponse
233- * @throws HttpRosetteAPIException Rosette specific exception
236+ * @throws HttpRosetteAPIException Analytics specific exception
234237 * @throws IOException General IO exception
235238 */
236239 public PingResponse ping () throws IOException , HttpRosetteAPIException {
237240 return sendGetRequest (urlBase + PING_SERVICE_PATH , PingResponse .class );
238241 }
239242
240243 /**
241- * Gets the set of language and script codes supported by the specified Rosette API endpoint.
244+ * Gets the set of language and script codes supported by the specified Analytics API endpoint.
242245 *
243246 * @return SupportedLanguagesResponse
244- * @throws HttpRosetteAPIException for an error returned from the Rosette API.
247+ * @throws HttpRosetteAPIException for an error returned from the Analytics API.
245248 */
246249 @ Override
247250 public SupportedLanguagesResponse getSupportedLanguages (String endpoint ) throws HttpRosetteAPIException {
@@ -254,12 +257,12 @@ public SupportedLanguagesResponse getSupportedLanguages(String endpoint) throws
254257 }
255258
256259 /**
257- * Gets the set of language, script codes and transliteration scheme pairs supported by the specified Rosette API
260+ * Gets the set of language, script codes and transliteration scheme pairs supported by the specified Analytics API
258261 * endpoint.
259262 *
260- * @param endpoint Rosette API endpoint.
263+ * @param endpoint Analytics API endpoint.
261264 * @return SupportedLanguagePairsResponse
262- * @throws HttpRosetteAPIException for an error returned from the Rosette API.
265+ * @throws HttpRosetteAPIException for an error returned from the Analytics API.
263266 */
264267 @ Override
265268 public SupportedLanguagePairsResponse getSupportedLanguagePairs (String endpoint ) throws HttpRosetteAPIException {
@@ -279,7 +282,7 @@ public SupportedLanguagePairsResponse getSupportedLanguagePairs(String endpoint)
279282 * @param <RequestType> the type of the request object.
280283 * @param <ResponseType> the type of the response object.
281284 * @return the response.
282- * @throws HttpRosetteAPIException for an error returned from the Rosette API.
285+ * @throws HttpRosetteAPIException for an error returned from the Analytics API.
283286 * @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
284287 */
285288 @ Override
@@ -300,7 +303,7 @@ public <RequestType extends Request, ResponseType extends Response> ResponseType
300303 * @param request the data for the request.
301304 * @param <RequestType> the type of the request object.
302305 * @return the response, {@link com.basistech.rosette.dm.AnnotatedText}.
303- * @throws HttpRosetteAPIException for an error returned from the Rosette API.
306+ * @throws HttpRosetteAPIException for an error returned from the Analytics API.
304307 * @throws RosetteRuntimeException for other errors, such as communications problems with HTTP.
305308 */
306309 @ Override
@@ -326,11 +329,11 @@ public <RequestType extends Request> AnnotatedText perform(String endpoint, Requ
326329 }
327330
328331 /**
329- * Sends a GET request to Rosette API.
332+ * Sends a GET request to Analytics API.
330333 * <p>
331334 * Returns a Response.
332335 *
333- * @param urlStr Rosette API end point.
336+ * @param urlStr Analytics API end point.
334337 * @param clazz Response class
335338 * @return Response
336339 * @throws HttpRosetteAPIException
@@ -351,11 +354,11 @@ private <T extends Response> T sendGetRequest(String urlStr, Class<T> clazz) thr
351354 }
352355
353356 /**
354- * Sends a POST request to Rosette API.
357+ * Sends a POST request to Analytics API.
355358 * <p>
356359 * Returns a Response.
357360 *
358- * @param urlStr Rosette API end point.
361+ * @param urlStr Analytics API end point.
359362 * @param clazz Response class
360363 * @return Response
361364 * @throws IOException
@@ -401,10 +404,15 @@ private <T> T sendPostRequest(Object request, String urlStr, Class<T> clazz)
401404 while (numRetries -- > 0 ) {
402405 try (CloseableHttpResponse response = httpClient .execute (post )) {
403406 T resp = getResponse (response , clazz );
407+ // TODO: Remove in a future release
404408 Header ridHeader = response .getFirstHeader ("X-RosetteAPI-DocumentRequest-Id" );
405409 if (ridHeader != null && ridHeader .getValue () != null ) {
406410 LOG .debug ("DocumentRequest ID {}" , ridHeader .getValue ());
407411 }
412+ Header bsidHeader = response .getFirstHeader ("X-BabelStreetAPI-DocumentRequest-Id" );
413+ if (bsidHeader != null && bsidHeader .getValue () != null ) {
414+ LOG .debug ("DocumentRequest ID {}" , bsidHeader .getValue ());
415+ }
408416 if (resp instanceof Response ) {
409417 responseHeadersToExtendedInformation ((Response )resp , response );
410418 }
@@ -556,21 +564,37 @@ private <T extends Object> T getResponse(HttpResponse httpResponse, Class<T> cla
556564 InputStream stream = httpResponse .getEntity ().getContent ();
557565 InputStream inputStream = "gzip" .equalsIgnoreCase (encoding ) ? new GZIPInputStream (stream ) : stream ) {
558566 String ridHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-RosetteAPI-DocumentRequest-Id" ));
567+ String bsidHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-BabelStreetAPI-DocumentRequest-Id" ));
559568 if (HTTP_OK != status ) {
560- String ecHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-RosetteAPI-Status-Code" ));
561- String emHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-RosetteAPI-Status-Message" ));
569+ String ecHeader ;
570+ if (headerValueOrNull (httpResponse .getFirstHeader ("X-BabelStreetAPI-Status-Code" )) != null ) {
571+ ecHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-BabelStreetAPI-Status-Code" ));
572+ } else {
573+ // TODO: Remove in a future release
574+ ecHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-RosetteAPI-Status-Code" ));
575+ }
576+ String emHeader ;
577+ if (headerValueOrNull (httpResponse .getFirstHeader ("X-BabelStreetAPI-Status-Message" )) != null ) {
578+ emHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-BabelStreetAPI-Status-Message" ));
579+ } else {
580+ // TODO: Remove in a future release
581+ emHeader = headerValueOrNull (httpResponse .getFirstHeader ("X-RosetteAPI-Status-Message" ));
582+ }
562583 String responseContentType = headerValueOrNull (httpResponse .getFirstHeader (HttpHeaders .CONTENT_TYPE ));
563584 if ("application/json" .equals (responseContentType )) {
564585 ErrorResponse errorResponse = mapper .readValue (inputStream , ErrorResponse .class );
565586 if (ridHeader != null ) {
566587 LOG .debug ("DocumentRequest ID {}" , ridHeader );
567588 }
589+ if (bsidHeader != null ) {
590+ LOG .debug ("DocumentRequest ID {}" , bsidHeader );
591+ }
568592 if (ecHeader != null ) {
569593 errorResponse .setCode (ecHeader );
570594 }
571595 if (429 == status ) {
572596 String concurrencyMessage = "You have exceeded your plan's limit on concurrent calls. "
573- + "This could be caused by multiple processes or threads making Rosette API calls "
597+ + "This could be caused by multiple processes or threads making Analytics API calls "
574598 + "in parallel, or if your httpClient is configured with higher concurrency "
575599 + "than your plan allows." ;
576600 if (emHeader == null ) {
0 commit comments