diff --git a/README.md b/README.md index 046759a..17d2b57 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ A convenient Java library to work with Pathway Commons web services. -We've just cut the cpath-client module from the cpath2 multi-module Maven project, refatored and moved here to make possible maintaining it separately from the server code (cpath2). +We've just cut the cpath-client module from the cpath2 multimodule Maven project, refatored and moved here to make possible maintaining it separately from the server code (cpath2). -This ia a fluent API Java client library for using Pathway Commons' RESTful [web services](http://www.pathwaycommons.org/pc2/), our large integrated BioPAX L3 database, from other Java projects, such as Cytoscape desctop (apps). But feel free to use another tool or develop own web client for Pathway Commons if you wish. +This ia a fluent API Java client library for using Pathway Commons' RESTful [web services](https://www.pathwaycommons.org/pc2/), our large integrated BioPAX L3 database, from other Java projects, such as Cytoscape desctop (apps). But feel free to use another tool or develop own web client for Pathway Commons if you wish. -# Use # +## Use ``` //using the Pathway Commons cPath2 web service URL (default): @@ -19,33 +19,32 @@ CPathClient client = CPathClient.newInstance(); in a Maven project, add to the pom.xml the following: ``` - - - ossrh - OSSRH Repository - https://oss.sonatype.org/content/groups/public/ - - - + + + ossrh + OSSRH Repository + https://oss.sonatype.org/content/groups/public/ + + + - pathwaycommons.cpath - cpath-client - 10.0.1-SNAPSHOT + pathwaycommons.cpath + cpath-client + 10.1.0-SNAPSHOT - org.biopax.paxtools - paxtools-core - 5.3.0-SNAPSHOT + org.biopax.paxtools + paxtools-core + 5.3.0 - + ``` -See also: -* the project's [tests](https://github.com/PathwayCommons/cpath2-client/blob/master/src/test/java/cpath/client/CPathClientTest.java) can be used as example; +## See also: +* http://www.biopax.org/paxtools +* [tests](https://github.com/PathwayCommons/cpath2-client/blob/master/src/test/java/cpath/client/CPathClientIT.java) as an example; -Alternatively, one can add the cpath-client _fat_ jar with dependencies to a Java (or JPype) project: grab the latest fat-jar ([from here](https://oss.sonatype.org/content/groups/public/pathwaycommons/cpath/cpath-client/)). +One can add the cpath-client _fat_ jar with dependencies to a Java (or JPype) project: grab the latest fat-jar ([from here](https://oss.sonatype.org/content/groups/public/pathwaycommons/cpath/cpath-client/)). - -# See also # - * http://www.biopax.org/paxtools - +## ToDo: +* Implement cPath2 v14 APIv2 (coming soon) client methods (only HTTP POST and JSON request body are used in the v2 API) diff --git a/pom.xml b/pom.xml index 3046be1..896e9f9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ pathwaycommons.cpath cpath-client - 10.0.1-SNAPSHOT + 10.1.0-SNAPSHOT jar cpath2 client @@ -47,12 +47,12 @@ org.biopax.paxtools paxtools-core - 5.3.0-SNAPSHOT + 5.3.0 org.springframework spring-web - 5.1.2.RELEASE + 5.3.31 commons-logging @@ -63,12 +63,12 @@ org.springframework spring-oxm - 5.1.2.RELEASE + 5.3.31 com.fasterxml.jackson.core jackson-core - 2.13.3 + 2.15.3 junit @@ -83,9 +83,9 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.11.0 - 8 + 11 diff --git a/src/main/java/cpath/client/CPathClient.java b/src/main/java/cpath/client/CPathClient.java index 39516eb..378f501 100644 --- a/src/main/java/cpath/client/CPathClient.java +++ b/src/main/java/cpath/client/CPathClient.java @@ -32,7 +32,7 @@ public class CPathClient // one can set the JVM property: -DcPath2Url="http://some_URL" public static final String JVM_PROPERTY_ENDPOINT_URL = "cPath2Url"; - public static final String DEFAULT_ENDPOINT_URL = "http://www.pathwaycommons.org/pc2/"; + public static final String DEFAULT_ENDPOINT_URL = "https://www.pathwaycommons.org/pc2/"; private RestTemplate restTemplate; private String endPointURL; //official external public cpath2 web service url @@ -63,19 +63,19 @@ public static CPathClient newInstance() { */ public static CPathClient newInstance(String url) { CPathClient client = new CPathClient(); - // create a new REST template - client.restTemplate = new RestTemplate(); + // create a new REST template + client.restTemplate = new RestTemplate(); // add custom cPath2 XML message converter as the first one (accepts 'application/xml' content type) // because one of existing/default msg converters, XML root element based jaxb2, does not work for ServiceResponce types... client.restTemplate.getMessageConverters().add(0, new ServiceResponseHttpMessageConverter()); // add BioPAX http message converter - // (SimpleIOHandler is not thread-safe; so we cannot share the thread-safe restTemplate) - client.restTemplate.getMessageConverters().add(1, new BioPAXHttpMessageConverter(new SimpleIOHandler())); - // set the cpath2 server URL (or default one or from the java option) + // (SimpleIOHandler is not thread-safe; so we cannot share the thread-safe restTemplate) + client.restTemplate.getMessageConverters().add(1, new BioPAXHttpMessageConverter(new SimpleIOHandler())); + // set the cpath2 server URL (or default one or from the java option) if(url == null || url.isEmpty()) - client.endPointURL = System.getProperty(JVM_PROPERTY_ENDPOINT_URL, DEFAULT_ENDPOINT_URL); - else - client.endPointURL = url; + client.endPointURL = System.getProperty(JVM_PROPERTY_ENDPOINT_URL, DEFAULT_ENDPOINT_URL); + else + client.endPointURL = url; return client; } @@ -101,11 +101,6 @@ public T post(String requestPath, MultiValueMap requestParam try { return restTemplate.postForObject(url, requestParams, responseType); -// } catch (UnknownHttpStatusCodeException e) { -// if (e.getRawStatusCode() == 460) { -// return null; //empty result -// } else -// throw new CPathException(url + " and " + requestParams, e); } catch (RestClientException e) { throw new CPathException(url + " and " + requestParams, e); } @@ -113,7 +108,7 @@ public T post(String requestPath, MultiValueMap requestParam /** - * Sends a HTTP GET request to the cpath2 server. + * Sends an HTTP GET request to the cPath2 server. * * Note: using {@link #post(String, MultiValueMap, Class)} is the preferred * and more reliable method, especially with complex queries that use URIs or diff --git a/src/main/java/cpath/client/query/CPathTraverseQuery.java b/src/main/java/cpath/client/query/CPathTraverseQuery.java index 18bea77..3e6121a 100644 --- a/src/main/java/cpath/client/query/CPathTraverseQuery.java +++ b/src/main/java/cpath/client/query/CPathTraverseQuery.java @@ -27,7 +27,7 @@ public final class CPathTraverseQuery extends BaseCPathQuery i * @return the request */ protected MultiValueMap getRequestParams() { - MultiValueMap request = new LinkedMultiValueMap(); + MultiValueMap request = new LinkedMultiValueMap<>(); if(source == null || source.length == 0) throw new IllegalArgumentException("Required 'source' (URIs) parameter cannot be null or empty."); request.put(CmdArgs.uri.name(), Arrays.asList(source)); diff --git a/src/test/java/cpath/client/CPathClientTest.java b/src/test/java/cpath/client/CPathClientIT.java similarity index 87% rename from src/test/java/cpath/client/CPathClientTest.java rename to src/test/java/cpath/client/CPathClientIT.java index a405ce5..d745f58 100644 --- a/src/test/java/cpath/client/CPathClientTest.java +++ b/src/test/java/cpath/client/CPathClientIT.java @@ -15,22 +15,18 @@ import static org.junit.Assert.*; /** - * INFO: when "cPath2Url" Java property is not set, - * (e.g., -DcPath2Url="http://localhost:8080/pc2/") - * the default cpath2 endpoint URL is {@link CPathClient#DEFAULT_ENDPOINT_URL} - * So, it is possible that the default (official) service still provides - * an older cpath2 API than this PC2 client expects. - * Take care. + * INFO: when "cPath2Url" Java property is not set (e.g., -DcPath2Url="http://localhost:8080/"), + * the default cpath2 endpoint URL is {@link CPathClient#DEFAULT_ENDPOINT_URL}. + * Run with JVM opts: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED */ @Ignore //these tests depend on the data, thus disabled by default (not for daily builds) -public class CPathClientTest { +public class CPathClientIT { static CPathClient client; static { -// client = CPathClient.newInstance("http://www.pathwaycommons.org/pc2/"); - client = CPathClient.newInstance("http://beta.pathwaycommons.org/pc2/"); - client.setName("CPathClientTest"); + client = CPathClient.newInstance(null); //use the URL from -DcPath2Url= JVM option or the default PC2 URL + client.setName("CPathClientIT"); } final String testBioSourceUri = "http://identifiers.org/taxonomy/9606"; @@ -40,7 +36,6 @@ public class CPathClientTest { @Test public final void testBiopaxMediaType() { String biopaxContentType = "application/vnd.biopax.rdf+xml"; -// MimeTypeUtils.parseMimeType("application/vnd.biopax.rdf+xml"); MediaType mediaType = MediaType.parseMediaType(biopaxContentType); assertNotNull(mediaType); assertEquals(biopaxContentType, mediaType.toString()); @@ -48,10 +43,8 @@ public final void testBiopaxMediaType() { @Test public final void testConnectionEtc() throws CPathException { - String endPointURL = client.getEndPointURL(); - System.out.println("cpath2 instance: " + endPointURL - + " (actual location: " + client.getActualEndPointURL() + ")"); + System.out.println("cpath2 instance: " + endPointURL + " (actual location: " + client.getActualEndPointURL() + ")"); String res = client.post("help/types", null, String.class); assertTrue(res.contains("BioSource")); @@ -59,7 +52,6 @@ public final void testConnectionEtc() throws CPathException { assertTrue(res.contains("BioSource")); } - @Test public final void testGetTopPathways() throws CPathException { SearchResponse result = null; @@ -71,13 +63,11 @@ public final void testGetTopPathways() throws CPathException { result = null; try { result = client.createTopPathwaysQuery().datasourceFilter(new String[]{"foo"}).result(); - } catch (CPathException e) { - } -// since pc9 beta; it sends "empty" data result... + } catch (CPathException e) {} + // since pc9 beta; it sends "empty" data result... assertTrue(result == null || result.isEmpty()); } - @Test public final void testTraverse() { // must get a result w/o problems @@ -104,7 +94,7 @@ public final void testTraverse() { .propertyPath("Named/name") .sources(new String[]{"bla-bla"}) .result(); - //it does not anymore sends error response; it returns "empty" result + //it does not anymore send error response; it returns "empty" result // fail("must throw CPathException now, for all error responses: 460, 452, 500..."); } catch (CPathException e) { } @@ -134,7 +124,6 @@ public final void testTraverse() { assertFalse(resp.isEmpty()); } - @Test public final void testSearch() { ServiceResponse resp = null; @@ -165,7 +154,6 @@ public final void testSearch() { assertFalse(((SearchResponse) resp).getSearchHit().isEmpty()); } - @Test //this test is even more dependent on the data there public final void testGetByUri() throws CPathException { String id = "BRCA2"; @@ -189,7 +177,6 @@ public final void testGetByUri() throws CPathException { assertTrue(res.contains("