Skip to content

Commit

Permalink
Merge branch '1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
vaites committed Jan 15, 2022
2 parents c8c09af + 83fa915 commit 2649149
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.2.1

* Fix known issues before parsing response (see [LOG4J2-2537](https://issues.apache.org/jira/browse/LOG4J2-2537))
* Tested up to Apache Tika 1.28 and 2.2.0

## v1.2.0

* Added specific methods to set OCR languages on web client (thanks to @aleksanm)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ to work with the new versions of the tool.
* Support for local and remote resources
* No heavyweight library dependencies
* Compatible with Apache Tika 1.15 or greater
* Tested up to 1.27 and 2.1.0
* Tested up to 1.28 and 2.2.0
* Works on Linux, macOS, Windows and probably on FreeBSD

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"supported-versions": [
"1.15", "1.16", "1.17", "1.18", "1.19", "1.19.1", "1.20",
"1.21", "1.22", "1.23", "1.24", "1.24.1", "1.25", "1.26",
"1.27", "2.0.0", "2.1.0"
"1.27", "1.28", "2.0.0", "2.1.0", "2.2.0"
]
}
}
23 changes: 22 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,25 @@ public function checkRequest(string $type, string $file = null): ?string
return $file;
}

/**
* Filter response to fix common issues
*
* @param string $response
* @return string
*/
protected function filterResponse(string $response): string
{
// fix Log4j2 warning
$response = trim(str_replace
(
'WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.',
'',
$response
));

return trim($response);
}

/**
* Parse the response returned by Apache Tika
*
Expand All @@ -550,6 +569,8 @@ protected function parseJsonResponse(string $response)
// exceptions if metadata is not valid
if(json_last_error())
{
dd($response);

$message = function_exists('json_last_error_msg') ? json_last_error_msg() : 'Error parsing JSON response';

throw new Exception($message, json_last_error());
Expand Down Expand Up @@ -639,5 +660,5 @@ abstract public function check(): void;
*
* @throws \Exception
*/
abstract public function request(string $type, string $file = null): string;
abstract public function request(string $type, string $file = null): ?string;
}
4 changes: 2 additions & 2 deletions src/Clients/CLIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function request(string $type, string $file = null): string
$this->cacheResponse($type, $response, $file);
}

return $response;
return $this->filterResponse($response);
}

/**
Expand Down Expand Up @@ -409,7 +409,7 @@ public function exec(string $command): ?string
throw new Exception("Unexpected exit value ($exit) for command $command");
}

return trim($this->response);
return $this->filterResponse($this->response);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Clients/WebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public function request(string $type, string $file = null): string
$this->error($status, $resource, $file);
}

return $response;
return $this->filterResponse($response);
}

/**
Expand Down

0 comments on commit 2649149

Please sign in to comment.