Skip to content

Commit

Permalink
Updated to jakarta EE and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Elbers committed Oct 31, 2024
1 parent 691352b commit 6838acd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 63 deletions.
37 changes: 7 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>de.uni_leipzig.asv</groupId>
<artifactId>clarin.webservices.pidservices2</artifactId>

<version>4.2-SNAPSHOT</version>
<version>5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>${project.groupId}.${project.artifactId}</name>

Expand All @@ -19,33 +19,15 @@
<artifactId>json-path</artifactId>
<version>0.9.1</version>
</dependency>
<!--
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client</artifactId>
<version>1.19.4</version>
<exclusions>
<exclusion>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.29.1</version>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>2.29.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<version>3.1.8</version>
</dependency>

<dependency>
Expand All @@ -54,6 +36,8 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

<!-- TODO: can this be replaced by jackson? -->
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
Expand Down Expand Up @@ -92,13 +76,6 @@
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
Expand Down Expand Up @@ -165,7 +142,7 @@
</execution>
</executions>
</plugin>
<plugin>
<!--plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
Expand All @@ -182,7 +159,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin-->

</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.uni_leipzig.asv.clarin.webservices.pidservices2;

/**
*
* @author wilelb
*/
public class PidApiException extends Exception {
public PidApiException(String message) {
super(message);
}

public PidApiException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.uni_leipzig.asv.clarin.webservices.pidservices2.impl;

import de.uni_leipzig.asv.clarin.webservices.pidservices2.Configuration;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import de.uni_leipzig.asv.clarin.webservices.pidservices2.HandleField;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.PidObject;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.interfaces.PidResolver;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.HttpException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.uni_leipzig.asv.clarin.webservices.pidservices2.Configuration;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.HandleField;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.PidApiException;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.interfaces.PidWriter;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

Expand All @@ -31,7 +29,7 @@ public class PidWriterImpl extends AbstractPidClient implements PidWriter {

@Override
public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap, String suffix)
throws HttpException, IllegalArgumentException {
throws PidApiException, IllegalArgumentException {
LOG.debug("Try to create handle {} at {} with values: {}", suffix, configuration.getServiceBaseURL(), fieldMap);

// validate the requested PID
Expand All @@ -52,7 +50,7 @@ public String registerNewPID(final Configuration configuration, Map<HandleField,

@Override
public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap)
throws HttpException {
throws PidApiException {
LOG.debug("Try to create handle at {} with values: {}", configuration.getServiceBaseURL(), fieldMap);

final WebTarget webTarget = getWebtarget(configuration,configuration.getHandlePrefix());
Expand All @@ -66,10 +64,10 @@ public String registerNewPID(final Configuration configuration, Map<HandleField,
}

private String processCreateResponse(final Response response, final Configuration configuration)
throws HttpException, RuntimeException {
throws PidApiException, RuntimeException {
if(response.getStatus() != 201) {
LOG.debug("Invalid API respose: code="+response.getStatus()+", message="+response.getStatusInfo().getReasonPhrase());
throw new HttpException("Invalid API response" + response.getStatus());
throw new PidApiException("Invalid API response" + response.getStatus());
}

String base = configuration.getServiceBaseURL();
Expand All @@ -84,7 +82,7 @@ private String processCreateResponse(final Response response, final Configuratio

@Override
public void modifyPid(final Configuration configuration, final String pid, Map<HandleField, String> fieldMap)
throws HttpException {
throws PidApiException {
LOG.debug("Try to modify handle \"" + pid + "\" at " + configuration.getServiceBaseURL() + " with new values: "
+ fieldMap);

Expand All @@ -97,7 +95,7 @@ public void modifyPid(final Configuration configuration, final String pid, Map<H

if(response.getStatus() != 201) {
LOG.debug("Invalid API respose: code="+response.getStatus()+", message="+response.getStatusInfo().getReasonPhrase());
throw new HttpException("Invalid API response: "+response.getStatus());
throw new PidApiException("Invalid API response: "+response.getStatus());
} else {
LOG.debug("Successfully modified PID: "+pid);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package de.uni_leipzig.asv.clarin.webservices.pidservices2.interfaces;

import java.util.Map;

import javax.xml.ws.http.HTTPException;

import org.apache.commons.httpclient.HttpException;

import de.uni_leipzig.asv.clarin.webservices.pidservices2.Configuration;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.HandleField;
import de.uni_leipzig.asv.clarin.webservices.pidservices2.PidApiException;

/**
* Registers new handles at handle server or modifies existing handles
Expand All @@ -24,13 +20,12 @@ public interface PidWriter {
* @param pid
* PID to be created, must match (see PID_INPUT_PATTERN)
* @return registered handle identifier
* @throws HttpException
* if the PID could not be created, for instance because the requested PID already exists
* @throws de.uni_leipzig.asv.clarin.webservices.pidservices2.PidApiException
* @throws IllegalArgumentException
* if the provided PID does not match (see PID_INPUT_PATTERN)
*/
public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap, String pid)
throws HttpException;
throws PidApiException;

/**
* Try to register a new PID at handle server.Returns registered handle if successful.
Expand All @@ -39,11 +34,11 @@ public String registerNewPID(final Configuration configuration, Map<HandleField,
* @param fieldMap
* handle mapping field to value
* @return registered handle identifier
* @throws org.apache.commons.httpclient.HttpException
* @throws de.uni_leipzig.asv.clarin.webservices.pidservices2.PidApiException
* @throws HTTPException
*/
public String registerNewPID(final Configuration configuration, Map<HandleField, String> fieldMap)
throws HttpException;
throws PidApiException;

/**
* Modify existing PID.This method overwrites all existing fields! Fields that should remain stored for the PID have to be added to fieldMap.
Expand All @@ -53,8 +48,8 @@ public String registerNewPID(final Configuration configuration, Map<HandleField,
* Persistent identifier that will be modified/overwritten
* @param fieldMap
* new field values: mapping handle field to value
* @throws org.apache.commons.httpclient.HttpException
* @throws de.uni_leipzig.asv.clarin.webservices.pidservices2.PidApiException
*/
public void modifyPid(final Configuration configuration, final String pid, Map<HandleField, String> fieldMap)
throws HttpException;
throws PidApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected String getJsonHandleField(HandleField type, String data) {
}

@Test
public void testPIDWriting() throws IOException {
public void testPIDWriting() throws IOException, PidApiException {
stubFor(put(urlEqualTo(String.format("%s/%s/%s", TEST_API_PATH, TEST_HANDLE_PREFIX, TEST_NEW_HANDLE_SUFFIX)))
.withBasicAuth(TEST_API_USER, TEST_API_PASSWORD)
.withHeader("Accept", containing("application/json"))
Expand Down

0 comments on commit 6838acd

Please sign in to comment.