Skip to content

Commit

Permalink
TIKA-4238: replace deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
THausherr committed Apr 6, 2024
1 parent 6d47c6c commit 3b6b5ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand Down Expand Up @@ -104,13 +105,12 @@ public boolean isAvailable() {

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
try {
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/caption/image?beam_size=%1$d&max_caption_length=%2$d", captions,
maxCaptionLength));
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/caption/image?beam_size=%1$d&max_caption_length=%2$d", captions,
maxCaptionLength));

DefaultHttpClient client = new DefaultHttpClient();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpResponse response = client.execute(new HttpGet(healthUri));
available = response.getStatusLine().getStatusCode() == 200;

Expand All @@ -133,12 +133,10 @@ public List<CaptionObject> recognise(InputStream stream, ContentHandler handler,
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
List<CaptionObject> capObjs = new ArrayList<>();
try {
DefaultHttpClient client = new DefaultHttpClient();

try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpPost request = new HttpPost(getApiUri(metadata));

try (UnsynchronizedByteArrayOutputStream byteStream = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream byteStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
//TODO: convert this to stream, this might cause OOM issue
// InputStreamEntity is not working
// request.setEntity(new InputStreamEntity(stream, -1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.ContentHandler;
Expand Down Expand Up @@ -106,12 +107,11 @@ public boolean isAvailable() {

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
try {
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/classify/image?topn=%1$d&min_confidence=%2$f", topN, minConfidence));
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/classify/image?topn=%1$d&min_confidence=%2$f", topN, minConfidence));

DefaultHttpClient client = new DefaultHttpClient();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpResponse response = client.execute(new HttpGet(healthUri));
available = response.getStatusLine().getStatusCode() == 200;

Expand All @@ -134,12 +134,10 @@ public List<RecognisedObject> recognise(InputStream stream, ContentHandler handl
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
List<RecognisedObject> recObjs = new ArrayList<>();
try {
DefaultHttpClient client = new DefaultHttpClient();

try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpPost request = new HttpPost(getApiUri(metadata));

try (UnsynchronizedByteArrayOutputStream byteStream = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream byteStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
//TODO: convert this to stream, this might cause OOM issue
// InputStreamEntity is not working
// request.setEntity(new InputStreamEntity(stream, -1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -74,13 +75,12 @@ protected URI getApiUri(Metadata metadata) {

@Override
public void initialize(Map<String, Param> params) throws TikaConfigException {
try {
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/classify/video?topn=%1$d&min_confidence=%2$f&mode=%3$s", topN, minConfidence,
mode));
healthUri = URI.create(apiBaseUri + "/ping");
apiUri = URI.create(apiBaseUri + String.format(Locale.getDefault(),
"/classify/video?topn=%1$d&min_confidence=%2$f&mode=%3$s", topN, minConfidence,
mode));

DefaultHttpClient client = new DefaultHttpClient();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpResponse response = client.execute(new HttpGet(healthUri));
available = response.getStatusLine().getStatusCode() == 200;

Expand Down

0 comments on commit 3b6b5ed

Please sign in to comment.