@Test public void getResultChunk_illegalInterval_IllegalArgumentException() throws Exception { final AbbyyInput abbyyInput = mock(AbbyyInput.class); final String resultUrl = "resultUrl"; final ExportFormat exportFormat = ExportFormat.XML; final int startByteIndex = 2; final int endByteIndex = startByteIndex - 1; this.exception.expect(IllegalArgumentException.class); this.sut.getResultChunk(abbyyInput, resultUrl, exportFormat, startByteIndex, endByteIndex); }
public String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat, int startByteIndex, int endByteIndex) throws AbbyySdkException, IOException, HttpClientException, URISyntaxException { if (startByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "startByteIndex")); } if (endByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "endByteIndex")); } if (startByteIndex > endByteIndex) { throw new IllegalArgumentException(ExceptionMsgs.INVALID_INTERVAL); } String headers = String.format(Headers.RANGE_TEMPLATE, startByteIndex, endByteIndex); HttpRequest httpRequest = new HttpClientRequest.Builder() .url(resultUrl) .tlsVersion(abbyyInput.getTlsVersion()) .allowedCyphers(abbyyInput.getAllowedCyphers()) .authType(Headers.AUTH_TYPE_ANONYMOUS) .preemptiveAuth(abbyyInput.isPreemptiveAuth()) .username(abbyyInput.getUsername()) .password(abbyyInput.getPassword()) .kerberosConfigFile(abbyyInput.getKerberosConfigFile()) .kerberosLoginConfFile(abbyyInput.getKerberosLoginConfFile()) .kerberosSkipPortForLookup(abbyyInput.getKerberosSkipPortForLookup()) .proxyHost(abbyyInput.getProxyHost()) .proxyPort(abbyyInput.getProxyPort()) .proxyUsername(abbyyInput.getProxyUsername()) .proxyPassword(abbyyInput.getProxyPassword()) .trustAllRoots(abbyyInput.isTrustAllRoots()) .x509HostnameVerifier(abbyyInput.getX509HostnameVerifier()) .trustKeystore(abbyyInput.getTrustKeystore()) .trustPassword(abbyyInput.getTrustPassword()) .keystore(abbyyInput.getKeystore()) .keystorePassword(abbyyInput.getKeystorePassword()) .connectTimeout(abbyyInput.getConnectTimeout()) .socketTimeout(abbyyInput.getSocketTimeout()) .useCookies(abbyyInput.isUseCookies()) .keepAlive(abbyyInput.isKeepAlive()) .connectionsMaxPerRoute(abbyyInput.getConnectionsMaxPerRoute()) .connectionsMaxTotal(abbyyInput.getConnectionsMaxTotal()) .headers(headers) .responseCharacterSet(StandardCharsets.UTF_8.displayName()) .followRedirects(abbyyInput.isFollowRedirects()) .queryParams(abbyyInput.getQueryParams()) .queryParamsAreURLEncoded(abbyyInput.isQueryParamsAreURLEncoded()) .queryParamsAreFormEncoded(abbyyInput.isQueryParamsAreFormEncoded()) .formParams(abbyyInput.getFormParams()) .formParamsAreURLEncoded(abbyyInput.isFormParamsAreURLEncoded()) .sourceFile(abbyyInput.getSourceFile()) .body(abbyyInput.getBody()) .contentType(abbyyInput.getContentType()) .requestCharacterSet(abbyyInput.getRequestCharacterSet()) .multipartBodies(abbyyInput.getMultipartBodies()) .multipartBodiesContentType(abbyyInput.getMultipartBodiesContentType()) .multipartFiles(abbyyInput.getMultipartFiles()) .multipartFilesContentType(abbyyInput.getMultipartFilesContentType()) .multipartValuesAreURLEncoded(abbyyInput.isMultipartValuesAreURLEncoded()) .chunkedRequestEntity(abbyyInput.isChunkedRequestEntity()) .method(HttpMethods.GET) .build(); HttpClientResponse httpResponse = HttpClient.execute(httpRequest); lastStatusCode = String.valueOf(httpResponse.getStatusCode()); if (httpResponse.getStatusCode() != 200 && httpResponse.getStatusCode() != 206) { throw new AbbyySdkException(String.format(ExceptionMsgs.PROCESSING_RESULT_COULD_NOT_BE_RETRIEVED, exportFormat)); } return httpResponse.getReturnResult(); }
AbbyyApi { public String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat, int startByteIndex, int endByteIndex) throws AbbyySdkException, IOException, HttpClientException, URISyntaxException { if (startByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "startByteIndex")); } if (endByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "endByteIndex")); } if (startByteIndex > endByteIndex) { throw new IllegalArgumentException(ExceptionMsgs.INVALID_INTERVAL); } String headers = String.format(Headers.RANGE_TEMPLATE, startByteIndex, endByteIndex); HttpRequest httpRequest = new HttpClientRequest.Builder() .url(resultUrl) .tlsVersion(abbyyInput.getTlsVersion()) .allowedCyphers(abbyyInput.getAllowedCyphers()) .authType(Headers.AUTH_TYPE_ANONYMOUS) .preemptiveAuth(abbyyInput.isPreemptiveAuth()) .username(abbyyInput.getUsername()) .password(abbyyInput.getPassword()) .kerberosConfigFile(abbyyInput.getKerberosConfigFile()) .kerberosLoginConfFile(abbyyInput.getKerberosLoginConfFile()) .kerberosSkipPortForLookup(abbyyInput.getKerberosSkipPortForLookup()) .proxyHost(abbyyInput.getProxyHost()) .proxyPort(abbyyInput.getProxyPort()) .proxyUsername(abbyyInput.getProxyUsername()) .proxyPassword(abbyyInput.getProxyPassword()) .trustAllRoots(abbyyInput.isTrustAllRoots()) .x509HostnameVerifier(abbyyInput.getX509HostnameVerifier()) .trustKeystore(abbyyInput.getTrustKeystore()) .trustPassword(abbyyInput.getTrustPassword()) .keystore(abbyyInput.getKeystore()) .keystorePassword(abbyyInput.getKeystorePassword()) .connectTimeout(abbyyInput.getConnectTimeout()) .socketTimeout(abbyyInput.getSocketTimeout()) .useCookies(abbyyInput.isUseCookies()) .keepAlive(abbyyInput.isKeepAlive()) .connectionsMaxPerRoute(abbyyInput.getConnectionsMaxPerRoute()) .connectionsMaxTotal(abbyyInput.getConnectionsMaxTotal()) .headers(headers) .responseCharacterSet(StandardCharsets.UTF_8.displayName()) .followRedirects(abbyyInput.isFollowRedirects()) .queryParams(abbyyInput.getQueryParams()) .queryParamsAreURLEncoded(abbyyInput.isQueryParamsAreURLEncoded()) .queryParamsAreFormEncoded(abbyyInput.isQueryParamsAreFormEncoded()) .formParams(abbyyInput.getFormParams()) .formParamsAreURLEncoded(abbyyInput.isFormParamsAreURLEncoded()) .sourceFile(abbyyInput.getSourceFile()) .body(abbyyInput.getBody()) .contentType(abbyyInput.getContentType()) .requestCharacterSet(abbyyInput.getRequestCharacterSet()) .multipartBodies(abbyyInput.getMultipartBodies()) .multipartBodiesContentType(abbyyInput.getMultipartBodiesContentType()) .multipartFiles(abbyyInput.getMultipartFiles()) .multipartFilesContentType(abbyyInput.getMultipartFilesContentType()) .multipartValuesAreURLEncoded(abbyyInput.isMultipartValuesAreURLEncoded()) .chunkedRequestEntity(abbyyInput.isChunkedRequestEntity()) .method(HttpMethods.GET) .build(); HttpClientResponse httpResponse = HttpClient.execute(httpRequest); lastStatusCode = String.valueOf(httpResponse.getStatusCode()); if (httpResponse.getStatusCode() != 200 && httpResponse.getStatusCode() != 206) { throw new AbbyySdkException(String.format(ExceptionMsgs.PROCESSING_RESULT_COULD_NOT_BE_RETRIEVED, exportFormat)); } return httpResponse.getReturnResult(); } }
AbbyyApi { public String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat, int startByteIndex, int endByteIndex) throws AbbyySdkException, IOException, HttpClientException, URISyntaxException { if (startByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "startByteIndex")); } if (endByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "endByteIndex")); } if (startByteIndex > endByteIndex) { throw new IllegalArgumentException(ExceptionMsgs.INVALID_INTERVAL); } String headers = String.format(Headers.RANGE_TEMPLATE, startByteIndex, endByteIndex); HttpRequest httpRequest = new HttpClientRequest.Builder() .url(resultUrl) .tlsVersion(abbyyInput.getTlsVersion()) .allowedCyphers(abbyyInput.getAllowedCyphers()) .authType(Headers.AUTH_TYPE_ANONYMOUS) .preemptiveAuth(abbyyInput.isPreemptiveAuth()) .username(abbyyInput.getUsername()) .password(abbyyInput.getPassword()) .kerberosConfigFile(abbyyInput.getKerberosConfigFile()) .kerberosLoginConfFile(abbyyInput.getKerberosLoginConfFile()) .kerberosSkipPortForLookup(abbyyInput.getKerberosSkipPortForLookup()) .proxyHost(abbyyInput.getProxyHost()) .proxyPort(abbyyInput.getProxyPort()) .proxyUsername(abbyyInput.getProxyUsername()) .proxyPassword(abbyyInput.getProxyPassword()) .trustAllRoots(abbyyInput.isTrustAllRoots()) .x509HostnameVerifier(abbyyInput.getX509HostnameVerifier()) .trustKeystore(abbyyInput.getTrustKeystore()) .trustPassword(abbyyInput.getTrustPassword()) .keystore(abbyyInput.getKeystore()) .keystorePassword(abbyyInput.getKeystorePassword()) .connectTimeout(abbyyInput.getConnectTimeout()) .socketTimeout(abbyyInput.getSocketTimeout()) .useCookies(abbyyInput.isUseCookies()) .keepAlive(abbyyInput.isKeepAlive()) .connectionsMaxPerRoute(abbyyInput.getConnectionsMaxPerRoute()) .connectionsMaxTotal(abbyyInput.getConnectionsMaxTotal()) .headers(headers) .responseCharacterSet(StandardCharsets.UTF_8.displayName()) .followRedirects(abbyyInput.isFollowRedirects()) .queryParams(abbyyInput.getQueryParams()) .queryParamsAreURLEncoded(abbyyInput.isQueryParamsAreURLEncoded()) .queryParamsAreFormEncoded(abbyyInput.isQueryParamsAreFormEncoded()) .formParams(abbyyInput.getFormParams()) .formParamsAreURLEncoded(abbyyInput.isFormParamsAreURLEncoded()) .sourceFile(abbyyInput.getSourceFile()) .body(abbyyInput.getBody()) .contentType(abbyyInput.getContentType()) .requestCharacterSet(abbyyInput.getRequestCharacterSet()) .multipartBodies(abbyyInput.getMultipartBodies()) .multipartBodiesContentType(abbyyInput.getMultipartBodiesContentType()) .multipartFiles(abbyyInput.getMultipartFiles()) .multipartFilesContentType(abbyyInput.getMultipartFilesContentType()) .multipartValuesAreURLEncoded(abbyyInput.isMultipartValuesAreURLEncoded()) .chunkedRequestEntity(abbyyInput.isChunkedRequestEntity()) .method(HttpMethods.GET) .build(); HttpClientResponse httpResponse = HttpClient.execute(httpRequest); lastStatusCode = String.valueOf(httpResponse.getStatusCode()); if (httpResponse.getStatusCode() != 200 && httpResponse.getStatusCode() != 206) { throw new AbbyySdkException(String.format(ExceptionMsgs.PROCESSING_RESULT_COULD_NOT_BE_RETRIEVED, exportFormat)); } return httpResponse.getReturnResult(); } AbbyyApi();  AbbyyApi(AbbyyResponseParser responseParser); }
AbbyyApi { public String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat, int startByteIndex, int endByteIndex) throws AbbyySdkException, IOException, HttpClientException, URISyntaxException { if (startByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "startByteIndex")); } if (endByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "endByteIndex")); } if (startByteIndex > endByteIndex) { throw new IllegalArgumentException(ExceptionMsgs.INVALID_INTERVAL); } String headers = String.format(Headers.RANGE_TEMPLATE, startByteIndex, endByteIndex); HttpRequest httpRequest = new HttpClientRequest.Builder() .url(resultUrl) .tlsVersion(abbyyInput.getTlsVersion()) .allowedCyphers(abbyyInput.getAllowedCyphers()) .authType(Headers.AUTH_TYPE_ANONYMOUS) .preemptiveAuth(abbyyInput.isPreemptiveAuth()) .username(abbyyInput.getUsername()) .password(abbyyInput.getPassword()) .kerberosConfigFile(abbyyInput.getKerberosConfigFile()) .kerberosLoginConfFile(abbyyInput.getKerberosLoginConfFile()) .kerberosSkipPortForLookup(abbyyInput.getKerberosSkipPortForLookup()) .proxyHost(abbyyInput.getProxyHost()) .proxyPort(abbyyInput.getProxyPort()) .proxyUsername(abbyyInput.getProxyUsername()) .proxyPassword(abbyyInput.getProxyPassword()) .trustAllRoots(abbyyInput.isTrustAllRoots()) .x509HostnameVerifier(abbyyInput.getX509HostnameVerifier()) .trustKeystore(abbyyInput.getTrustKeystore()) .trustPassword(abbyyInput.getTrustPassword()) .keystore(abbyyInput.getKeystore()) .keystorePassword(abbyyInput.getKeystorePassword()) .connectTimeout(abbyyInput.getConnectTimeout()) .socketTimeout(abbyyInput.getSocketTimeout()) .useCookies(abbyyInput.isUseCookies()) .keepAlive(abbyyInput.isKeepAlive()) .connectionsMaxPerRoute(abbyyInput.getConnectionsMaxPerRoute()) .connectionsMaxTotal(abbyyInput.getConnectionsMaxTotal()) .headers(headers) .responseCharacterSet(StandardCharsets.UTF_8.displayName()) .followRedirects(abbyyInput.isFollowRedirects()) .queryParams(abbyyInput.getQueryParams()) .queryParamsAreURLEncoded(abbyyInput.isQueryParamsAreURLEncoded()) .queryParamsAreFormEncoded(abbyyInput.isQueryParamsAreFormEncoded()) .formParams(abbyyInput.getFormParams()) .formParamsAreURLEncoded(abbyyInput.isFormParamsAreURLEncoded()) .sourceFile(abbyyInput.getSourceFile()) .body(abbyyInput.getBody()) .contentType(abbyyInput.getContentType()) .requestCharacterSet(abbyyInput.getRequestCharacterSet()) .multipartBodies(abbyyInput.getMultipartBodies()) .multipartBodiesContentType(abbyyInput.getMultipartBodiesContentType()) .multipartFiles(abbyyInput.getMultipartFiles()) .multipartFilesContentType(abbyyInput.getMultipartFilesContentType()) .multipartValuesAreURLEncoded(abbyyInput.isMultipartValuesAreURLEncoded()) .chunkedRequestEntity(abbyyInput.isChunkedRequestEntity()) .method(HttpMethods.GET) .build(); HttpClientResponse httpResponse = HttpClient.execute(httpRequest); lastStatusCode = String.valueOf(httpResponse.getStatusCode()); if (httpResponse.getStatusCode() != 200 && httpResponse.getStatusCode() != 206) { throw new AbbyySdkException(String.format(ExceptionMsgs.PROCESSING_RESULT_COULD_NOT_BE_RETRIEVED, exportFormat)); } return httpResponse.getReturnResult(); } AbbyyApi();  AbbyyApi(AbbyyResponseParser responseParser); String getLastStatusCode(); AbbyyResponse request(@NotNull AbbyyInput abbyyInput); AbbyyResponse getTaskStatus(@NotNull AbbyyInput abbyyInput, @NotNull String taskId); String getResult(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat,
                            @Nullable String downloadPath, boolean useSpecificCharSet); long getResultSize(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat); String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat,
                                 int startByteIndex, int endByteIndex); }
AbbyyApi { public String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat, int startByteIndex, int endByteIndex) throws AbbyySdkException, IOException, HttpClientException, URISyntaxException { if (startByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "startByteIndex")); } if (endByteIndex < 0) { throw new IllegalArgumentException(String.format(ExceptionMsgs.NEGATIVE_NUMBER, "endByteIndex")); } if (startByteIndex > endByteIndex) { throw new IllegalArgumentException(ExceptionMsgs.INVALID_INTERVAL); } String headers = String.format(Headers.RANGE_TEMPLATE, startByteIndex, endByteIndex); HttpRequest httpRequest = new HttpClientRequest.Builder() .url(resultUrl) .tlsVersion(abbyyInput.getTlsVersion()) .allowedCyphers(abbyyInput.getAllowedCyphers()) .authType(Headers.AUTH_TYPE_ANONYMOUS) .preemptiveAuth(abbyyInput.isPreemptiveAuth()) .username(abbyyInput.getUsername()) .password(abbyyInput.getPassword()) .kerberosConfigFile(abbyyInput.getKerberosConfigFile()) .kerberosLoginConfFile(abbyyInput.getKerberosLoginConfFile()) .kerberosSkipPortForLookup(abbyyInput.getKerberosSkipPortForLookup()) .proxyHost(abbyyInput.getProxyHost()) .proxyPort(abbyyInput.getProxyPort()) .proxyUsername(abbyyInput.getProxyUsername()) .proxyPassword(abbyyInput.getProxyPassword()) .trustAllRoots(abbyyInput.isTrustAllRoots()) .x509HostnameVerifier(abbyyInput.getX509HostnameVerifier()) .trustKeystore(abbyyInput.getTrustKeystore()) .trustPassword(abbyyInput.getTrustPassword()) .keystore(abbyyInput.getKeystore()) .keystorePassword(abbyyInput.getKeystorePassword()) .connectTimeout(abbyyInput.getConnectTimeout()) .socketTimeout(abbyyInput.getSocketTimeout()) .useCookies(abbyyInput.isUseCookies()) .keepAlive(abbyyInput.isKeepAlive()) .connectionsMaxPerRoute(abbyyInput.getConnectionsMaxPerRoute()) .connectionsMaxTotal(abbyyInput.getConnectionsMaxTotal()) .headers(headers) .responseCharacterSet(StandardCharsets.UTF_8.displayName()) .followRedirects(abbyyInput.isFollowRedirects()) .queryParams(abbyyInput.getQueryParams()) .queryParamsAreURLEncoded(abbyyInput.isQueryParamsAreURLEncoded()) .queryParamsAreFormEncoded(abbyyInput.isQueryParamsAreFormEncoded()) .formParams(abbyyInput.getFormParams()) .formParamsAreURLEncoded(abbyyInput.isFormParamsAreURLEncoded()) .sourceFile(abbyyInput.getSourceFile()) .body(abbyyInput.getBody()) .contentType(abbyyInput.getContentType()) .requestCharacterSet(abbyyInput.getRequestCharacterSet()) .multipartBodies(abbyyInput.getMultipartBodies()) .multipartBodiesContentType(abbyyInput.getMultipartBodiesContentType()) .multipartFiles(abbyyInput.getMultipartFiles()) .multipartFilesContentType(abbyyInput.getMultipartFilesContentType()) .multipartValuesAreURLEncoded(abbyyInput.isMultipartValuesAreURLEncoded()) .chunkedRequestEntity(abbyyInput.isChunkedRequestEntity()) .method(HttpMethods.GET) .build(); HttpClientResponse httpResponse = HttpClient.execute(httpRequest); lastStatusCode = String.valueOf(httpResponse.getStatusCode()); if (httpResponse.getStatusCode() != 200 && httpResponse.getStatusCode() != 206) { throw new AbbyySdkException(String.format(ExceptionMsgs.PROCESSING_RESULT_COULD_NOT_BE_RETRIEVED, exportFormat)); } return httpResponse.getReturnResult(); } AbbyyApi();  AbbyyApi(AbbyyResponseParser responseParser); String getLastStatusCode(); AbbyyResponse request(@NotNull AbbyyInput abbyyInput); AbbyyResponse getTaskStatus(@NotNull AbbyyInput abbyyInput, @NotNull String taskId); String getResult(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat,
                            @Nullable String downloadPath, boolean useSpecificCharSet); long getResultSize(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat); String getResultChunk(@NotNull AbbyyInput abbyyInput, @NotNull String resultUrl, @NotNull ExportFormat exportFormat,
                                 int startByteIndex, int endByteIndex);  }