Skip to content

Commit

Permalink
EA-4015 Update set client to use http5, remove all spring dependency …
Browse files Browse the repository at this point in the history
…from client, update other modules to adapt tghe new HTTpConnection

class, added annotation for deserialising the response
  • Loading branch information
SrishtiSingh-eu committed Nov 28, 2024
1 parent 6eeefd0 commit 291f697
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 691 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@

<springdoc.version>1.6.14</springdoc.version>

<version.httpClient>3.1</version.httpClient>
<version.httpClient5>5.4.1</version.httpClient5>
<version.javax.annotation>1.3.2</version.javax.annotation>
<version.jettison>1.3</version.jettison>
<version.jaxb>2.3.1</version.jaxb>
<version.junit>5.7.2</version.junit>
<version.commonsIO>2.8.0</version.commonsIO>

<jackson.version>2.18.1</jackson.version>
<!-- java version properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
27 changes: 21 additions & 6 deletions set-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,30 @@
<artifactId>jettison</artifactId>
<version>${version.jettison}</version>
</dependency>


<!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>4.0.0</version>
</dependency>

<!-- To fix : "Provider for jakarta.ws.rs.ext.RuntimeDelegate cannot be found error"
This issue is tagged with version 2.30 but it doesn't look like it was ever fixed in newer versions as well-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<!--
<version>${spring-framework.version}</version>
-->
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>3.1.2</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-webmvc</artifactId>-->
<!-- &lt;!&ndash;-->
<!-- <version>${spring-framework.version}</version>-->
<!-- &ndash;&gt;-->
<!-- </dependency>-->

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import eu.europeana.set.client.config.ClientConfiguration;
import eu.europeana.set.client.connection.UserSetApiConnection;
import eu.europeana.set.client.exception.SetApiClientException;
import eu.europeana.set.client.exception.TechnicalRuntimeException;
import eu.europeana.set.common.http.HttpConnection;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.io.IOException;

Expand All @@ -25,8 +26,8 @@ public class BaseUserSetApi {

protected BaseUserSetApi(ClientConfiguration configuration) throws SetApiClientException {
this.configuration = configuration;
if (this.configuration.getServiceUri() == null && this.configuration.getApiKey() == null) {
throw new SetApiClientException(" Set Api Endpoint not provide !!!");
if (this.configuration.getServiceUri() == null) {
throw new SetApiClientException(" Set Api Endpoint not provided !!!");
}

if (this.configuration.getOauthServiceUri() == null || this.configuration.getOauthRequestParams() == null) {
Expand All @@ -43,27 +44,27 @@ public BaseUserSetApi() throws SetApiClientException {
this(new ClientConfiguration());
}

private String getOauthToken(String oauthServiceUri, String oauthRequestParams ) {
private String getOauthToken(String oauthServiceUri, String oauthRequestParams ) throws SetApiClientException{
try {
String ACCESS_TOKEN = "access_token";
HttpConnection connection = new HttpConnection();
ResponseEntity<String> response;
response = connection.post(oauthServiceUri, oauthRequestParams, "application/x-www-form-urlencoded");

if (HttpStatus.OK == response.getStatusCode()) {
String body = response.getBody();
CloseableHttpResponse response = connection.post(oauthServiceUri, oauthRequestParams, "application/x-www-form-urlencoded", null);
String body = EntityUtils.toString(response.getEntity());

System.out.println(body);
if (HttpStatus.SC_OK == response.getCode()) {
JSONObject json = new JSONObject(body);
if (json.has(ACCESS_TOKEN)) {
return "Bearer " + json.getString(ACCESS_TOKEN);
} else {
throw new TechnicalRuntimeException(
"Cannot extract authentication token from reponse:" + body);
throw new SetApiClientException("Cannot extract authentication token from reponse:" + body);
}
} else {
throw new TechnicalRuntimeException("Error occured when calling oath service! " + response);
throw new SetApiClientException("Error occured when calling oath service! " + response);
}
} catch (IOException | JSONException e) {
throw new TechnicalRuntimeException("Cannot retrieve authentication token!", e);
} catch (IOException | JSONException | ParseException e) {
throw new SetApiClientException("Cannot retrieve authentication token!", 0 , e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package eu.europeana.set.client;

import java.io.IOException;

import eu.europeana.api.commons.definitions.search.result.impl.ResultsPageImpl;
import eu.europeana.set.client.config.ClientConfiguration;
import eu.europeana.set.client.exception.SetApiClientException;
import eu.europeana.set.client.web.SearchUserSetApi;
import eu.europeana.set.client.web.WebUserSetApi;
import org.springframework.http.ResponseEntity;

import eu.europeana.set.client.exception.TechnicalRuntimeException;
import eu.europeana.set.definitions.model.UserSet;

/**
* Implementation of client api
Expand Down Expand Up @@ -40,70 +37,33 @@ public SearchUserSetApi getSearchUserSetApi() {
*/
private class WebUserSetClient implements WebUserSetApi {
@Override
public ResponseEntity<String> createUserSet(String set, String profile) {
ResponseEntity<String> res;
try {
res = getApiConnection().createUserSet(set, profile);
} catch (IOException e) {
throw new TechnicalRuntimeException(
"Exception occured when invoking the UserSetJsonApi createUserSet method", e);
}
return res;
public UserSet createUserSet(String set, String profile) throws SetApiClientException {
return getApiConnection().createUserSet(set, profile);

}

@Override
public ResponseEntity<String> deleteUserSet(String identifier) {
ResponseEntity<String> res;
try {
res = getApiConnection().deleteUserSet(identifier);
} catch (IOException e) {
throw new TechnicalRuntimeException(
"Exception occured when invoking the UserSetJsonApi deleteUserSet method", e);
}

return res;
public String deleteUserSet(String identifier) throws SetApiClientException {
return getApiConnection().deleteUserSet(identifier);
}

@Override
public ResponseEntity<String> getUserSet(String identifier, String profile) {
ResponseEntity<String> res;
try {
res = getApiConnection().getUserSet(identifier, profile);
} catch (IOException e) {
throw new TechnicalRuntimeException("Exception occured when invoking the UserSetJsonApi getUserSet method",
e);
}

return res;
public UserSet getUserSet(String identifier, String profile) throws SetApiClientException {
return getApiConnection().getUserSet(identifier, profile);
}

@Override
public ResponseEntity<String> updateUserSet(String identifier, String set, String profile) {
ResponseEntity<String> res;
try {
res = getApiConnection().updateUserSet(identifier, set, profile);
} catch (IOException e) {
throw new TechnicalRuntimeException(
"Exception occured when invoking the UserSetJsonApi updateUserSet method", e);
}

return res;
public UserSet updateUserSet(String identifier, String set, String profile) throws SetApiClientException {
return getApiConnection().updateUserSet(identifier, set, profile);
}
}

private class SearchUserSetClient implements SearchUserSetApi {

@Override
public ResponseEntity<String> searchUserSet(String query, String[] qf,
String sort, int page, int pageSize, String facet, int facetLimit, String profile) {
ResponseEntity<String> res;
try {
res = getApiConnection().searchUserSet(query, qf, sort, page, pageSize, facet, facetLimit, profile);
} catch (IOException e) {
throw new TechnicalRuntimeException(
"Exception occured when invoking the UserSetSearch API searchUserSet method", e);
}
return res;
public ResultsPageImpl<? extends UserSet> searchUserSet(String query, String[] qf,
String sort, int page, int pageSize, String facet, int facetLimit, String profile) throws SetApiClientException{
return getApiConnection().searchUserSet(query, qf, sort, page, pageSize, facet, facetLimit, profile);
}
}

Expand Down
Loading

0 comments on commit 291f697

Please sign in to comment.