Compare commits

...

60 Commits

Author SHA1 Message Date
Luca Frosini eec32da4d7 Merge pull request 'Fixed `getInputStream()` in a `GXInboundResponse` created from a connection, if is not a success response (HTTP code not in `2xx` and `3xx`)' (!1) from mauro.mugnaini/gx-rest:master into master
Reviewed-on: #1
Reviewed-by: Luca Frosini <luca.frosini@isti.cnr.it>
2024-05-14 15:48:08 +02:00
Mauro Mugnaini b3af1e29f8 Merge pull request 'Update from upstream' (#1) from gCubeSystem/gx-rest:master into master
Reviewed-on: mauro.mugnaini/gx-rest#1
2024-04-29 12:11:30 +02:00
Luca Frosini 74cb5bdaa5 Updated maven-parent 2023-10-05 11:34:36 +02:00
luca.frosini 0d7b341f8e Ignored MacOs File 2023-06-21 11:40:00 +02:00
Mauro Mugnaini 88d588b29c Fixed `getInputStream()` from connection if is not a success response (HTTP code not in `2xx` and `3xx`) 2023-03-22 13:41:47 +01:00
Luca Frosini 4bd280b1c5 Removed ide specific files 2023-03-02 12:07:21 +01:00
Luca Frosini d615a454bb Removed ide specific files 2023-03-02 12:00:13 +01:00
Luca Frosini 1da0e27c42 Cleaning code from dependencies which must be removed 2022-07-15 16:00:24 +02:00
Luca Frosini 2be6f3b7fd Fixed changelog 2022-07-08 15:15:32 +02:00
Luca Frosini 8573d2c6e3 Removed isExtCall because the authorization is not set automatically
anymore
2022-07-08 15:12:58 +02:00
Lucio Lelii 66ce9b8a23 porting to smartgears 4 2022-06-15 17:57:12 +02:00
Luca Frosini b4bbaf8816 Fixed gcube-bom version 2021-06-23 14:49:24 +02:00
Luca Frosini 6ef9d93725 Fixed versions for release 2021-06-23 14:22:19 +02:00
Luca Frosini f4c942ddb6 Removed -SNAPSHOT for release 2021-06-23 12:57:36 +02:00
Luca Frosini e9af3d2d23 Fixed CHANGELOG 2021-05-27 16:10:31 +02:00
Luca Frosini 2ea1c4f820 Merge branch 'master' of gitea@code-repo.d4science.org:gCubeSystem/gx-rest.git 2021-05-27 15:26:19 +02:00
Luca Frosini a26f583a0e Supporting new UMA token 2021-05-27 15:14:24 +02:00
Luca Frosini 86509bb7c3 Moved link from http to https in a comment refs #20779 2021-02-22 09:35:27 +01:00
Luca Frosini 60b9690890 Removed unused class member 2020-10-08 15:55:07 +02:00
Luca Frosini 744a92db82 Removed unused import 2020-10-08 15:54:46 +02:00
Luca Frosini b565aab839 Suppressed deprecation warning 2020-10-08 15:54:35 +02:00
Luca Frosini b84ac8b29b Closed scanner 2020-10-08 15:54:17 +02:00
Luca Frosini 3a6e2fc2ef Ignored generated directory 2020-10-08 14:45:06 +02:00
Luca Frosini 5b8695ba58 Fixed version 2020-08-06 17:48:32 +02:00
Luca Frosini ef270edbd5 Removed eclipse project files 2020-08-06 14:51:52 +02:00
Luca Frosini f027923cdf Switched JSON Management to gcube-jackson 2020-08-06 14:51:24 +02:00
Manuele Simi 93569cd265 Update CHANGELOG.md. 2020-07-23 14:58:02 +02:00
Manuele Simi 8948534883 Add CHANGELOG, README and LICENSE files to each module (as requested by the maven-parent). 2020-06-21 16:34:22 -04:00
Manuele Simi 9b4ff9774b Add tests for HTTPS requests. 2020-02-07 11:06:11 -05:00
Manuele Simi 3308729be3 Fix secure builder's name. 2020-02-07 11:02:21 -05:00
Manuele Simi a2b242d631 Allow clients to set the secure protocol, if needed. Use the default handshake negotiation if not set. 2020-02-07 10:59:24 -05:00
Massimiliano Assante d92bc514f0 Update 'gxJRS/src/main/java/org/gcube/common/gxrest/request/GXWebTargetAdapterRequest.java'
restored TLS 1.2 Setting
2020-02-07 12:23:12 +01:00
Massimiliano Assante 2cb8acd620 Fix for Bug #18556, gxJRS: SSL protocol mismatch in production 2020-02-07 09:57:05 +01:00
Luca Frosini e538b00c52 Removed snapshot for release 2020-02-06 12:02:52 +01:00
Luca Frosini 8b1325cb1d Fixed nested pom 2020-02-06 12:00:48 +01:00
Luca Frosini 8fd1bbf4f4 Switched frmo TLSv1 to TLSv1.2 refs #18556 2020-02-06 11:58:20 +01:00
Manuele Simi 6ea1ce9eb6 Fix parent URL. 2019-10-19 23:19:23 -04:00
Manuele Simi cba7557176 Merge remote-tracking branch 'origin/master' 2019-10-19 23:16:56 -04:00
Manuele Simi 8fd96259d1 Fix URL. 2019-10-19 23:14:03 -04:00
Roberto Cirillo ceb65c5016 Update 'pom.xml'
update gcube-bom to 1.3.1 version
2019-10-17 18:06:30 +02:00
Manuele Simi 2299ba14ca Merge remote-tracking branch 'origin/master' 2019-10-17 11:54:03 -04:00
Manuele Simi bed2e8a839 Adjust the scm links. 2019-10-17 11:50:57 -04:00
Roberto Cirillo 956d8f1b15 Update 'pom.xml'
removed SNAPSHOT from gcube-bom
2019-10-17 16:13:24 +02:00
Manuele Simi 74d55bc5ba Adjust dependency for release 1.1.2. 2019-10-17 09:03:55 -04:00
Manuele Simi 842aaee8fb Advance maven-parent to 1.1.0. 2019-07-09 21:20:36 -04:00
Manuele Simi 5313355ec4 Remove the unused information-system-bom. 2019-06-10 23:10:19 -04:00
Manuele Simi f0ac9586b7 Remove latest from BOM dependencies. 2019-06-09 08:34:34 -04:00
Manuele Simi b0037e99f7 Advance gcube-bom version. 2019-06-08 20:38:25 +02:00
Manuele Simi 202d342696 Advance dependency on information-system-bom. 2019-06-06 22:12:55 +02:00
Manuele Simi 555a101888 Merge remote-tracking branch 'origin/master' 2019-06-06 13:49:44 -04:00
Manuele Simi 84bf1513c4 Advance parent pom. 2019-06-06 13:49:30 -04:00
Manuele Simi 29b6095d54 Update 'README.md' 2019-05-09 22:16:18 +02:00
Manuele Simi b262824bfa Update the scm connection in the poms to refer the Git repo. 2019-04-09 23:08:19 -04:00
Manuele Simi bdcb217e65 Add target to gitignore. 2019-04-07 23:36:53 -04:00
Manuele Simi a019b08860 Adjust code in the readme. 2019-04-07 22:55:07 -04:00
Manuele Simi dcd653c36a Tweak README. 2019-04-07 15:35:51 -04:00
Manuele Simi 30fbd2cca5 Update README with some examples of use. 2019-04-07 15:33:55 -04:00
Manuele Simi 0811c73896 Update README. 2019-04-06 16:09:37 -04:00
Manuele Simi e3c4cdac3b Add REAME.md 2019-04-06 15:56:02 -04:00
Manuele Simi bf6dc1970b Add gitignore. 2019-04-06 15:43:32 -04:00
48 changed files with 1578 additions and 524 deletions

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
token.*
.svn
target
.classpath
.project
.settings/
/.DS_Store

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gxREST</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,2 +0,0 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

46
CHANGELOG.md Normal file
View File

@ -0,0 +1,46 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Changelog for gxREST
## [v2.0.0-SNAPSHOT]
- removed all the old providers
- removed set of gcube headers
- removed isExtCall because authorization headers are not added automatically anymore
## [v1.2.0]
- Managing new UMA token and not only old authz gcube token [#21525]
- Switched JSON management to gcube-jackson [#19737]
## [v1.1.3] [r4.20.0] - 2019-10-19
- Allow clients to set secure protocol
- Switch from TLSv1 to TLSv1.2
## [v1.1.2] [r4.20.0] - 2019-10-19
- Migration to Git
## [v1.1.1] [r4.0.0] - 2019-03-30
- Allow to set the media type for the returned entity in the Error Response.
## [v1.1.0] [r4.13.1] - 2019-02-26
- ...
## [v1.0.1] [r4.13.0] - 2018-11-20
- ...
## [v1.0.0] [r4.12.0] - 2018-06-20
- First Release

312
LICENSE.md Normal file
View File

@ -0,0 +1,312 @@
# European Union Public Licence V. 1.1
EUPL © the European Community 2007
This European Union Public Licence (the “EUPL”) applies to the Work or Software
(as defined below) which is provided under the terms of this Licence. Any use of
the Work, other than as authorised under this Licence is prohibited (to the
extent such use is covered by a right of the copyright holder of the Work).
The Original Work is provided under the terms of this Licence when the Licensor
(as defined below) has placed the following notice immediately following the
copyright notice for the Original Work:
Licensed under the EUPL V.1.1
or has expressed by any other mean his willingness to license under the EUPL.
## 1. Definitions
In this Licence, the following terms have the following meaning:
- The Licence: this Licence.
- The Original Work or the Software: the software distributed and/or
communicated by the Licensor under this Licence, available as Source Code and
also as Executable Code as the case may be.
- Derivative Works: the works or software that could be created by the Licensee,
based upon the Original Work or modifications thereof. This Licence does not
define the extent of modification or dependence on the Original Work required
in order to classify a work as a Derivative Work; this extent is determined by
copyright law applicable in the country mentioned in Article 15.
- The Work: the Original Work and/or its Derivative Works.
- The Source Code: the human-readable form of the Work which is the most
convenient for people to study and modify.
- The Executable Code: any code which has generally been compiled and which is
meant to be interpreted by a computer as a program.
- The Licensor: the natural or legal person that distributes and/or communicates
the Work under the Licence.
- Contributor(s): any natural or legal person who modifies the Work under the
Licence, or otherwise contributes to the creation of a Derivative Work.
- The Licensee or “You”: any natural or legal person who makes any usage of the
Software under the terms of the Licence.
- Distribution and/or Communication: any act of selling, giving, lending,
renting, distributing, communicating, transmitting, or otherwise making
available, on-line or off-line, copies of the Work or providing access to its
essential functionalities at the disposal of any other natural or legal
person.
## 2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
sub-licensable licence to do the following, for the duration of copyright vested
in the Original Work:
- use the Work in any circumstance and for all usage, reproduce the Work, modify
- the Original Work, and make Derivative Works based upon the Work, communicate
- to the public, including the right to make available or display the Work or
- copies thereof to the public and perform publicly, as the case may be, the
- Work, distribute the Work or copies thereof, lend and rent the Work or copies
- thereof, sub-license rights in the Work or copies thereof.
Those rights can be exercised on any media, supports and formats, whether now
known or later invented, as far as the applicable law permits so.
In the countries where moral rights apply, the Licensor waives his right to
exercise his moral right to the extent allowed by law in order to make effective
the licence of the economic rights here above listed.
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to
any patents held by the Licensor, to the extent necessary to make use of the
rights granted on the Work under this Licence.
## 3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as
Executable Code. If the Work is provided as Executable Code, the Licensor
provides in addition a machine-readable copy of the Source Code of the Work
along with each copy of the Work that the Licensor distributes or indicates, in
a notice following the copyright notice attached to the Work, a repository where
the Source Code is easily and freely accessible for as long as the Licensor
continues to distribute and/or communicate the Work.
## 4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from
any exception or limitation to the exclusive rights of the rights owners in the
Original Work or Software, of the exhaustion of those rights or of other
applicable limitations thereto.
## 5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and
obligations imposed on the Licensee. Those obligations are the following:
Attribution right: the Licensee shall keep intact all copyright, patent or
trademarks notices and all notices that refer to the Licence and to the
disclaimer of warranties. The Licensee must include a copy of such notices and a
copy of the Licence with every copy of the Work he/she distributes and/or
communicates. The Licensee must cause any Derivative Work to carry prominent
notices stating that the Work has been modified and the date of modification.
Copyleft clause: If the Licensee distributes and/or communicates copies of the
Original Works or Derivative Works based upon the Original Work, this
Distribution and/or Communication will be done under the terms of this Licence
or of a later version of this Licence unless the Original Work is expressly
distributed only under this version of the Licence. The Licensee (becoming
Licensor) cannot offer or impose any additional terms or conditions on the Work
or Derivative Work that alter or restrict the terms of the Licence.
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative
Works or copies thereof based upon both the Original Work and another work
licensed under a Compatible Licence, this Distribution and/or Communication can
be done under the terms of this Compatible Licence. For the sake of this clause,
“Compatible Licence” refers to the licences listed in the appendix attached to
this Licence. Should the Licensees obligations under the Compatible Licence
conflict with his/her obligations under this Licence, the obligations of the
Compatible Licence shall prevail.
Provision of Source Code: When distributing and/or communicating copies of the
Work, the Licensee will provide a machine-readable copy of the Source Code or
indicate a repository where this Source will be easily and freely available for
as long as the Licensee continues to distribute and/or communicate the Work.
Legal Protection: This Licence does not grant permission to use the trade names,
trademarks, service marks, or names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the copyright notice.
## 6. Chain of Authorship
The original Licensor warrants that the copyright in the Original Work granted
hereunder is owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each Contributor warrants that the copyright in the modifications he/she brings
to the Work are owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each time You accept the Licence, the original Licensor and subsequent
Contributors grant You a licence to their contributions to the Work, under the
terms of this Licence.
## 7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous
contributors. It is not a finished work and may therefore contain defects or
“bugs” inherent to this type of software development.
For the above reason, the Work is provided under the Licence on an “as is” basis
and without warranties of any kind concerning the Work, including without
limitation merchantability, fitness for a particular purpose, absence of defects
or errors, accuracy, non-infringement of intellectual property rights other than
copyright as stated in Article 6 of this Licence.
This disclaimer of warranty is an essential part of the Licence and a condition
for the grant of any rights to the Work.
## 8. Disclaimer of Liability
Except in the cases of wilful misconduct or damages directly caused to natural
persons, the Licensor will in no event be liable for any direct or indirect,
material or moral, damages of any kind, arising out of the Licence or of the use
of the Work, including without limitation, damages for loss of goodwill, work
stoppage, computer failure or malfunction, loss of data or any commercial
damage, even if the Licensor has been advised of the possibility of such
damage. However, the Licensor will be liable under statutory product liability
laws as far such laws apply to the Work.
## 9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to
conclude an additional agreement to offer, and charge a fee for, acceptance of
support, warranty, indemnity, or other liability obligations and/or services
consistent with this Licence. However, in accepting such obligations, You may
act only on your own behalf and on your sole responsibility, not on behalf of
the original Licensor or any other Contributor, and only if You agree to
indemnify, defend, and hold each Contributor harmless for any liability incurred
by, or claims asserted against such Contributor by the fact You have accepted
any such warranty or additional liability.
## 10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon “I agree”
placed under the bottom of a window displaying the text of this Licence or by
affirming consent in any other similar way, in accordance with the rules of
applicable law. Clicking on that icon indicates your clear and irrevocable
acceptance of this Licence and all of its terms and conditions.
Similarly, you irrevocably accept this Licence and all of its terms and
conditions by exercising any rights granted to You by Article 2 of this Licence,
such as the use of the Work, the creation by You of a Derivative Work or the
Distribution and/or Communication by You of the Work or copies thereof.
## 11. Information to the public
In case of any Distribution and/or Communication of the Work by means of
electronic communication by You (for example, by offering to download the Work
from a remote location) the distribution channel or media (for example, a
website) must at least provide to the public the information requested by the
applicable law regarding the Licensor, the Licence and the way it may be
accessible, concluded, stored and reproduced by the Licensee.
## 12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon
any breach by the Licensee of the terms of the Licence.
Such a termination will not terminate the licences of any person who has
received the Work from the Licensee under the Licence, provided such persons
remain in full compliance with the Licence.
## 13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete
agreement between the Parties as to the Work licensed hereunder.
If any provision of the Licence is invalid or unenforceable under applicable
law, this will not affect the validity or enforceability of the Licence as a
whole. Such provision will be construed and/or reformed so as necessary to make
it valid and enforceable.
The European Commission may publish other linguistic versions and/or new
versions of this Licence, so far this is required and reasonable, without
reducing the scope of the rights granted by the Licence. New versions of the
Licence will be published with a unique version number.
All linguistic versions of this Licence, approved by the European Commission,
have identical value. Parties can take advantage of the linguistic version of
their choice.
## 14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising
between the European Commission, as a Licensor, and any Licensee, will be
subject to the jurisdiction of the Court of Justice of the European Communities,
as laid down in article 238 of the Treaty establishing the European Community.
Any litigation arising between Parties, other than the European Commission, and
resulting from the interpretation of this License, will be subject to the
exclusive jurisdiction of the competent court where the Licensor resides or
conducts its primary business.
## 15. Applicable Law
This Licence shall be governed by the law of the European Union country where
the Licensor resides or has his registered office.
This licence shall be governed by the Belgian law if:
- a litigation arises between the European Commission, as a Licensor, and any
- Licensee; the Licensor, other than the European Commission, has no residence
- or registered office inside a European Union country.
## Appendix
“Compatible Licences” according to article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2
- Open Software License (OSL) v. 2.1, v. 3.0
- Common Public License v. 1.0
- Eclipse Public License v. 1.0
- Cecill v. 2.0

88
README.md Normal file
View File

@ -0,0 +1,88 @@
# gxREST
The gCube eXtensions to the Rest Protocol (gxRest) is a set of Java libraries designed to provide convenient round-trip interaction between a Restful web application (also known as "service") and its clients.
gxRest has the flexibility for different degrees of exploitation:
* it can be entirely adopted both at client and service side with full benefit of its conventions;
* it can be used to send REST requests based only on plain HTTP;
* it can be used only to return HTTP code/messagess from the service;
* it can be used only to throw Exceptions from the service to the client.
## Examples of use
Sending a request:
```java
GXHTTPRequest request = GXHTTPRequest.newRequest("http://host:port/service/").from("GXRequestTest");
//prepare some parameters
String context ="...";
Map<String,String> queryParams = new WeakHashMap<>();
queryParams.put("param name", "param value");
GXInboundResponse response = request.path("context")
.queryParams(queryParams).withBody(context).post();
```
Returning a success response:
```java
@POST
public Response create(...) {
//Resource successfully created
URI location = ... //URI of the new resource
return GXOutboundSuccessResponse.newCREATEResponse(location)
.withMessage("Resource successfully created.")
.ofType(MediaType.APPLICATION_JSON)
.build();
}
```
Throwing an exception:
```java
@POST
public Response create(...) {
//Oh no, something failed here
GXOutboundErrorResponse.throwException(new MyCustomException("Resource already exists."));
}
```
Parsing a response
```java
// invoke the remote method and get a response.
GXInboundResponse response = ...;
if (response.hasException())
throw response.getException();
//assuming a created (200) code was expected
if (response.hasCREATEDCode()) {
System.out.println("Resource successfully created!");
}
//access content as string
String value = response.getStreamedContentAsString();
//unmasharll content as json
Context returnedContext = response.tryConvertStreamedContentFromJson(Context.class);
```
## Modules
* [gxHTTP](https://wiki.gcube-system.org/gcube/GxRest/GxHTTP)
* [gxJRS](https://wiki.gcube-system.org/gcube/GxRest/GxJRS)
## Deployment
Notes about how to deploy this component on an infrastructure or link to wiki doc (if any).
## Documentation
See gxRest on [Wiki](https://wiki.gcube-system.org/gcube/GxRest).
## Built With
* [JAX-RS](https://github.com/eclipse-ee4j/jaxrs-api) - Java™ API for RESTful Web Services
* [Jersey](https://jersey.github.io/) - JAX-RS runtime
* [Maven](https://maven.apache.org/) - Dependency Management
## License
TBP

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

5
gxHTTP/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/.classpath
/bin/
.project
.settings/
target/

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gxHTTP</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

46
gxHTTP/CHANGELOG.md Normal file
View File

@ -0,0 +1,46 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Changelog for gxHTTP
## [v2.0.0-SNAPSHOT]
- removed all the old providers
- removed set of gcube headers
- removed isExtCall because authorization headers are not added automatically anymore
## [v1.2.0]
- Managing new UMA token and not only old authz gcube token [#21525]
- Switched JSON management to gcube-jackson [#19737]
## [v1.1.3] [r4.20.0] - 2019-10-19
- Allow clients to set secure protocol
- Switch from TLSv1 to TLSv1.2
## [v1.1.2] [r4.20.0] - 2019-10-19
- Migration to Git
## [v1.1.1] [r4.0.0] - 2019-03-30
- Allow to set the media type for the returned entity in the Error Response.
## [v1.1.0] [r4.13.1] - 2019-02-26
- ...
## [v1.0.1] [r4.13.0] - 2018-11-20
- ...
## [v1.0.0] [r4.12.0] - 2018-06-20
- First Release

312
gxHTTP/LICENSE.md Normal file
View File

@ -0,0 +1,312 @@
# European Union Public Licence V. 1.1
EUPL © the European Community 2007
This European Union Public Licence (the “EUPL”) applies to the Work or Software
(as defined below) which is provided under the terms of this Licence. Any use of
the Work, other than as authorised under this Licence is prohibited (to the
extent such use is covered by a right of the copyright holder of the Work).
The Original Work is provided under the terms of this Licence when the Licensor
(as defined below) has placed the following notice immediately following the
copyright notice for the Original Work:
Licensed under the EUPL V.1.1
or has expressed by any other mean his willingness to license under the EUPL.
## 1. Definitions
In this Licence, the following terms have the following meaning:
- The Licence: this Licence.
- The Original Work or the Software: the software distributed and/or
communicated by the Licensor under this Licence, available as Source Code and
also as Executable Code as the case may be.
- Derivative Works: the works or software that could be created by the Licensee,
based upon the Original Work or modifications thereof. This Licence does not
define the extent of modification or dependence on the Original Work required
in order to classify a work as a Derivative Work; this extent is determined by
copyright law applicable in the country mentioned in Article 15.
- The Work: the Original Work and/or its Derivative Works.
- The Source Code: the human-readable form of the Work which is the most
convenient for people to study and modify.
- The Executable Code: any code which has generally been compiled and which is
meant to be interpreted by a computer as a program.
- The Licensor: the natural or legal person that distributes and/or communicates
the Work under the Licence.
- Contributor(s): any natural or legal person who modifies the Work under the
Licence, or otherwise contributes to the creation of a Derivative Work.
- The Licensee or “You”: any natural or legal person who makes any usage of the
Software under the terms of the Licence.
- Distribution and/or Communication: any act of selling, giving, lending,
renting, distributing, communicating, transmitting, or otherwise making
available, on-line or off-line, copies of the Work or providing access to its
essential functionalities at the disposal of any other natural or legal
person.
## 2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
sub-licensable licence to do the following, for the duration of copyright vested
in the Original Work:
- use the Work in any circumstance and for all usage, reproduce the Work, modify
- the Original Work, and make Derivative Works based upon the Work, communicate
- to the public, including the right to make available or display the Work or
- copies thereof to the public and perform publicly, as the case may be, the
- Work, distribute the Work or copies thereof, lend and rent the Work or copies
- thereof, sub-license rights in the Work or copies thereof.
Those rights can be exercised on any media, supports and formats, whether now
known or later invented, as far as the applicable law permits so.
In the countries where moral rights apply, the Licensor waives his right to
exercise his moral right to the extent allowed by law in order to make effective
the licence of the economic rights here above listed.
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to
any patents held by the Licensor, to the extent necessary to make use of the
rights granted on the Work under this Licence.
## 3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as
Executable Code. If the Work is provided as Executable Code, the Licensor
provides in addition a machine-readable copy of the Source Code of the Work
along with each copy of the Work that the Licensor distributes or indicates, in
a notice following the copyright notice attached to the Work, a repository where
the Source Code is easily and freely accessible for as long as the Licensor
continues to distribute and/or communicate the Work.
## 4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from
any exception or limitation to the exclusive rights of the rights owners in the
Original Work or Software, of the exhaustion of those rights or of other
applicable limitations thereto.
## 5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and
obligations imposed on the Licensee. Those obligations are the following:
Attribution right: the Licensee shall keep intact all copyright, patent or
trademarks notices and all notices that refer to the Licence and to the
disclaimer of warranties. The Licensee must include a copy of such notices and a
copy of the Licence with every copy of the Work he/she distributes and/or
communicates. The Licensee must cause any Derivative Work to carry prominent
notices stating that the Work has been modified and the date of modification.
Copyleft clause: If the Licensee distributes and/or communicates copies of the
Original Works or Derivative Works based upon the Original Work, this
Distribution and/or Communication will be done under the terms of this Licence
or of a later version of this Licence unless the Original Work is expressly
distributed only under this version of the Licence. The Licensee (becoming
Licensor) cannot offer or impose any additional terms or conditions on the Work
or Derivative Work that alter or restrict the terms of the Licence.
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative
Works or copies thereof based upon both the Original Work and another work
licensed under a Compatible Licence, this Distribution and/or Communication can
be done under the terms of this Compatible Licence. For the sake of this clause,
“Compatible Licence” refers to the licences listed in the appendix attached to
this Licence. Should the Licensees obligations under the Compatible Licence
conflict with his/her obligations under this Licence, the obligations of the
Compatible Licence shall prevail.
Provision of Source Code: When distributing and/or communicating copies of the
Work, the Licensee will provide a machine-readable copy of the Source Code or
indicate a repository where this Source will be easily and freely available for
as long as the Licensee continues to distribute and/or communicate the Work.
Legal Protection: This Licence does not grant permission to use the trade names,
trademarks, service marks, or names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the copyright notice.
## 6. Chain of Authorship
The original Licensor warrants that the copyright in the Original Work granted
hereunder is owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each Contributor warrants that the copyright in the modifications he/she brings
to the Work are owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each time You accept the Licence, the original Licensor and subsequent
Contributors grant You a licence to their contributions to the Work, under the
terms of this Licence.
## 7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous
contributors. It is not a finished work and may therefore contain defects or
“bugs” inherent to this type of software development.
For the above reason, the Work is provided under the Licence on an “as is” basis
and without warranties of any kind concerning the Work, including without
limitation merchantability, fitness for a particular purpose, absence of defects
or errors, accuracy, non-infringement of intellectual property rights other than
copyright as stated in Article 6 of this Licence.
This disclaimer of warranty is an essential part of the Licence and a condition
for the grant of any rights to the Work.
## 8. Disclaimer of Liability
Except in the cases of wilful misconduct or damages directly caused to natural
persons, the Licensor will in no event be liable for any direct or indirect,
material or moral, damages of any kind, arising out of the Licence or of the use
of the Work, including without limitation, damages for loss of goodwill, work
stoppage, computer failure or malfunction, loss of data or any commercial
damage, even if the Licensor has been advised of the possibility of such
damage. However, the Licensor will be liable under statutory product liability
laws as far such laws apply to the Work.
## 9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to
conclude an additional agreement to offer, and charge a fee for, acceptance of
support, warranty, indemnity, or other liability obligations and/or services
consistent with this Licence. However, in accepting such obligations, You may
act only on your own behalf and on your sole responsibility, not on behalf of
the original Licensor or any other Contributor, and only if You agree to
indemnify, defend, and hold each Contributor harmless for any liability incurred
by, or claims asserted against such Contributor by the fact You have accepted
any such warranty or additional liability.
## 10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon “I agree”
placed under the bottom of a window displaying the text of this Licence or by
affirming consent in any other similar way, in accordance with the rules of
applicable law. Clicking on that icon indicates your clear and irrevocable
acceptance of this Licence and all of its terms and conditions.
Similarly, you irrevocably accept this Licence and all of its terms and
conditions by exercising any rights granted to You by Article 2 of this Licence,
such as the use of the Work, the creation by You of a Derivative Work or the
Distribution and/or Communication by You of the Work or copies thereof.
## 11. Information to the public
In case of any Distribution and/or Communication of the Work by means of
electronic communication by You (for example, by offering to download the Work
from a remote location) the distribution channel or media (for example, a
website) must at least provide to the public the information requested by the
applicable law regarding the Licensor, the Licence and the way it may be
accessible, concluded, stored and reproduced by the Licensee.
## 12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon
any breach by the Licensee of the terms of the Licence.
Such a termination will not terminate the licences of any person who has
received the Work from the Licensee under the Licence, provided such persons
remain in full compliance with the Licence.
## 13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete
agreement between the Parties as to the Work licensed hereunder.
If any provision of the Licence is invalid or unenforceable under applicable
law, this will not affect the validity or enforceability of the Licence as a
whole. Such provision will be construed and/or reformed so as necessary to make
it valid and enforceable.
The European Commission may publish other linguistic versions and/or new
versions of this Licence, so far this is required and reasonable, without
reducing the scope of the rights granted by the Licence. New versions of the
Licence will be published with a unique version number.
All linguistic versions of this Licence, approved by the European Commission,
have identical value. Parties can take advantage of the linguistic version of
their choice.
## 14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising
between the European Commission, as a Licensor, and any Licensee, will be
subject to the jurisdiction of the Court of Justice of the European Communities,
as laid down in article 238 of the Treaty establishing the European Community.
Any litigation arising between Parties, other than the European Commission, and
resulting from the interpretation of this License, will be subject to the
exclusive jurisdiction of the competent court where the Licensor resides or
conducts its primary business.
## 15. Applicable Law
This Licence shall be governed by the law of the European Union country where
the Licensor resides or has his registered office.
This licence shall be governed by the Belgian law if:
- a litigation arises between the European Commission, as a Licensor, and any
- Licensee; the Licensor, other than the European Commission, has no residence
- or registered office inside a European Union country.
## Appendix
“Compatible Licences” according to article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2
- Open Software License (OSL) v. 2.1, v. 3.0
- Common Public License v. 1.0
- Eclipse Public License v. 1.0
- Cecill v. 2.0

18
gxHTTP/README.md Normal file
View File

@ -0,0 +1,18 @@
gxHTTP
----
The gCube eXtensions to the HTTP protocol.
## Documentation
* [gxHTTP](https://wiki.gcube-system.org/gcube/GxRest/GxHTTP)
## Deployment
Notes about how to deploy this component on an infrastructure or link to wiki doc (if any).
## Built With
* [Jersey](https://jersey.github.io/) - JAX-RS runtime
* [Maven](https://maven.apache.org/) - Dependency Management
## License
See [LICENSE.md](LICENSE.md)

View File

@ -7,11 +7,11 @@
<parent>
<groupId>org.gcube.common</groupId>
<artifactId>gxREST</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId>
<packaging>jar</packaging>
<name>gCube eXtensions to REST with HTTP</name>
<description>gCube eXtensions to REST based on HTTP</description>
@ -22,21 +22,15 @@
</properties>
<scm>
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</developerConnection>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/gx-rest</url>
</scm>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -45,19 +39,5 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-servicearchive</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -14,7 +14,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -52,8 +51,7 @@ public class GXConnection {
private String body;
private InputStream bodyAsStream;
private Map<String, String> properties = new HashMap<>();
private boolean extCall = false;
public GXConnection(String address) {
this.address = address;
}
@ -118,17 +116,12 @@ public class GXConnection {
public HttpURLConnection send(HTTPMETHOD method) throws Exception {
return send(this.buildURL(), method);
}
private HttpURLConnection send(URL url, HTTPMETHOD method) throws Exception {
HttpURLConnection uConn = (HttpURLConnection) url.openConnection();
if (!this.extCall) {
String token = SecurityTokenProvider.instance.get();
if (Objects.isNull(token) || token.isEmpty())
throw new IllegalStateException("The security token in the current environment is null.");
uConn.setRequestProperty(org.gcube.common.authorization.client.Constants.TOKEN_HEADER_ENTRY,
token);
}
//uConn = addGCubeAuthorizationToken(uConn);
uConn.setDoOutput(true);
// uConn.setRequestProperty("Content-type", APPLICATION_JSON_CHARSET_UTF_8);
if(this.agent!=null) {
@ -172,7 +165,7 @@ public class GXConnection {
}
return uConn;
}
private URL getURL(String urlString) throws MalformedURLException {
URL url = new URL(urlString);
if (url.getProtocol().equals("https")) {
@ -245,19 +238,5 @@ public class GXConnection {
public void setProperty(String name, String value) {
this.properties.put(name, value);
}
/**
* @param extCall the extCall to set
*/
public void setExtCall(boolean extCall) {
this.extCall = extCall;
}
/**
* @return the extCall
*/
public boolean isExtCall() {
return extCall;
}
}

View File

@ -85,17 +85,6 @@ public interface GXHTTP<BODY,RESPONSE> {
* @throws Exception
*/
RESPONSE connect() throws Exception;
/**
* Overrides the default security token.
* @param token the new token
*/
void setSecurityToken(String token);
/**
* States if the service being called in an external service (not gCube).
* @param ext true if external, false otherwise
*/
void isExternalCall(boolean ext);
}

View File

@ -4,8 +4,8 @@ import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.Objects;
import org.gcube.common.gxhttp.reference.GXConnection.HTTPMETHOD;
import org.slf4j.Logger;
@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
* Builder for GXHTTP Requests.
*
* @author Manuele Simi (ISTI CNR)
* @author Luca Frosini (ISTI-CNR)
*
*/
public class GXHTTPRequestBuilder {
@ -74,19 +75,9 @@ public class GXHTTPRequestBuilder {
return this;
}
public static final String UUID_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}-[a-fA-F0-9]{8,9}){1}$";
/**
* Overrides the default security token.
*
* @param token
*/
public void setSecurityToken(String token) {
if (!this.connection.isExtCall())
this.connection.setProperty(org.gcube.common.authorization.client.Constants.TOKEN_HEADER_ENTRY, token);
else
throw new UnsupportedOperationException("Cannot set the security token on an external call");
}
/**
* Add headers to the request.
*
@ -196,12 +187,4 @@ public class GXHTTPRequestBuilder {
return this.connection.send(HTTPMETHOD.CONNECT);
}
/*
* (non-Javadoc)
*
* @see org.gcube.common.gxrest.request.GXHTTP#isExternalCall(boolean)
*/
public void isExternalCall(boolean ext) {
this.connection.setExtCall(ext);
}
}

View File

@ -83,20 +83,6 @@ class GXHTTPCommonRequest {
public HttpURLConnection connect() throws Exception {
return builder.connect();
}
/* (non-Javadoc)
* @see org.gcube.common.gxhttp.reference.GXHTTP#setSecurityToken(java.lang.String)
*/
public void setSecurityToken(String token) {
builder.setSecurityToken(token);
}
/* (non-Javadoc)
* @see org.gcube.common.gxhttp.reference.GXHTTP#isExternalCall(boolean)
*/
public void isExternalCall(boolean ext) {
builder.isExternalCall(ext);
}
/**
* Clear up the request.

View File

@ -1,6 +1,7 @@
package org.gcube.common.gxhttp;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@ -9,15 +10,9 @@ import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.gxhttp.util.ContentUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -55,30 +50,6 @@ public class GXHTTPStringRequestTest {
}
}
@BeforeClass
public static void beforeClass() throws Exception {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
}
SecurityTokenProvider.instance.set(token);
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
}
/**
* Test method for {@link org.gcube.common.gxhttp.request.GXHTTPStringRequest#newRequest(java.lang.String)}.
*/

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

5
gxJRS/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/.classpath
/bin/
.project
.settings/
target/

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gxRest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +0,0 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

45
gxJRS/CHANGELOG.md Normal file
View File

@ -0,0 +1,45 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Changelog for gxJRS
## [v2.0.0-SNAPSHOT]
- removed all the old providers
- removed set of gcube headers
- removed isExtCall because authorization headers are not added automatically anymore
## [v1.2.0]
- Managing new UMA token and not only old authz gcube token [#21525]
- Switched JSON management to gcube-jackson [#19737]
## [v1.1.3] [r4.20.0] - 2019-10-19
- Allow clients to set secure protocol
- Switch from TLSv1 to TLSv1.2
## [v1.1.2] [r4.20.0] - 2019-10-19
- Migration to Git
## [v1.1.1] [r4.0.0] - 2019-03-30
- Allow to set the media type for the returned entity in the Error Response.
## [v1.1.0] [r4.13.1] - 2019-02-26
- ...
## [v1.0.1] [r4.13.0] - 2018-11-20
- ...
## [v1.0.0] [r4.12.0] - 2018-06-20
- First Release

312
gxJRS/LICENSE.md Normal file
View File

@ -0,0 +1,312 @@
# European Union Public Licence V. 1.1
EUPL © the European Community 2007
This European Union Public Licence (the “EUPL”) applies to the Work or Software
(as defined below) which is provided under the terms of this Licence. Any use of
the Work, other than as authorised under this Licence is prohibited (to the
extent such use is covered by a right of the copyright holder of the Work).
The Original Work is provided under the terms of this Licence when the Licensor
(as defined below) has placed the following notice immediately following the
copyright notice for the Original Work:
Licensed under the EUPL V.1.1
or has expressed by any other mean his willingness to license under the EUPL.
## 1. Definitions
In this Licence, the following terms have the following meaning:
- The Licence: this Licence.
- The Original Work or the Software: the software distributed and/or
communicated by the Licensor under this Licence, available as Source Code and
also as Executable Code as the case may be.
- Derivative Works: the works or software that could be created by the Licensee,
based upon the Original Work or modifications thereof. This Licence does not
define the extent of modification or dependence on the Original Work required
in order to classify a work as a Derivative Work; this extent is determined by
copyright law applicable in the country mentioned in Article 15.
- The Work: the Original Work and/or its Derivative Works.
- The Source Code: the human-readable form of the Work which is the most
convenient for people to study and modify.
- The Executable Code: any code which has generally been compiled and which is
meant to be interpreted by a computer as a program.
- The Licensor: the natural or legal person that distributes and/or communicates
the Work under the Licence.
- Contributor(s): any natural or legal person who modifies the Work under the
Licence, or otherwise contributes to the creation of a Derivative Work.
- The Licensee or “You”: any natural or legal person who makes any usage of the
Software under the terms of the Licence.
- Distribution and/or Communication: any act of selling, giving, lending,
renting, distributing, communicating, transmitting, or otherwise making
available, on-line or off-line, copies of the Work or providing access to its
essential functionalities at the disposal of any other natural or legal
person.
## 2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
sub-licensable licence to do the following, for the duration of copyright vested
in the Original Work:
- use the Work in any circumstance and for all usage, reproduce the Work, modify
- the Original Work, and make Derivative Works based upon the Work, communicate
- to the public, including the right to make available or display the Work or
- copies thereof to the public and perform publicly, as the case may be, the
- Work, distribute the Work or copies thereof, lend and rent the Work or copies
- thereof, sub-license rights in the Work or copies thereof.
Those rights can be exercised on any media, supports and formats, whether now
known or later invented, as far as the applicable law permits so.
In the countries where moral rights apply, the Licensor waives his right to
exercise his moral right to the extent allowed by law in order to make effective
the licence of the economic rights here above listed.
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to
any patents held by the Licensor, to the extent necessary to make use of the
rights granted on the Work under this Licence.
## 3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as
Executable Code. If the Work is provided as Executable Code, the Licensor
provides in addition a machine-readable copy of the Source Code of the Work
along with each copy of the Work that the Licensor distributes or indicates, in
a notice following the copyright notice attached to the Work, a repository where
the Source Code is easily and freely accessible for as long as the Licensor
continues to distribute and/or communicate the Work.
## 4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from
any exception or limitation to the exclusive rights of the rights owners in the
Original Work or Software, of the exhaustion of those rights or of other
applicable limitations thereto.
## 5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and
obligations imposed on the Licensee. Those obligations are the following:
Attribution right: the Licensee shall keep intact all copyright, patent or
trademarks notices and all notices that refer to the Licence and to the
disclaimer of warranties. The Licensee must include a copy of such notices and a
copy of the Licence with every copy of the Work he/she distributes and/or
communicates. The Licensee must cause any Derivative Work to carry prominent
notices stating that the Work has been modified and the date of modification.
Copyleft clause: If the Licensee distributes and/or communicates copies of the
Original Works or Derivative Works based upon the Original Work, this
Distribution and/or Communication will be done under the terms of this Licence
or of a later version of this Licence unless the Original Work is expressly
distributed only under this version of the Licence. The Licensee (becoming
Licensor) cannot offer or impose any additional terms or conditions on the Work
or Derivative Work that alter or restrict the terms of the Licence.
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative
Works or copies thereof based upon both the Original Work and another work
licensed under a Compatible Licence, this Distribution and/or Communication can
be done under the terms of this Compatible Licence. For the sake of this clause,
“Compatible Licence” refers to the licences listed in the appendix attached to
this Licence. Should the Licensees obligations under the Compatible Licence
conflict with his/her obligations under this Licence, the obligations of the
Compatible Licence shall prevail.
Provision of Source Code: When distributing and/or communicating copies of the
Work, the Licensee will provide a machine-readable copy of the Source Code or
indicate a repository where this Source will be easily and freely available for
as long as the Licensee continues to distribute and/or communicate the Work.
Legal Protection: This Licence does not grant permission to use the trade names,
trademarks, service marks, or names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the copyright notice.
## 6. Chain of Authorship
The original Licensor warrants that the copyright in the Original Work granted
hereunder is owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each Contributor warrants that the copyright in the modifications he/she brings
to the Work are owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each time You accept the Licence, the original Licensor and subsequent
Contributors grant You a licence to their contributions to the Work, under the
terms of this Licence.
## 7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous
contributors. It is not a finished work and may therefore contain defects or
“bugs” inherent to this type of software development.
For the above reason, the Work is provided under the Licence on an “as is” basis
and without warranties of any kind concerning the Work, including without
limitation merchantability, fitness for a particular purpose, absence of defects
or errors, accuracy, non-infringement of intellectual property rights other than
copyright as stated in Article 6 of this Licence.
This disclaimer of warranty is an essential part of the Licence and a condition
for the grant of any rights to the Work.
## 8. Disclaimer of Liability
Except in the cases of wilful misconduct or damages directly caused to natural
persons, the Licensor will in no event be liable for any direct or indirect,
material or moral, damages of any kind, arising out of the Licence or of the use
of the Work, including without limitation, damages for loss of goodwill, work
stoppage, computer failure or malfunction, loss of data or any commercial
damage, even if the Licensor has been advised of the possibility of such
damage. However, the Licensor will be liable under statutory product liability
laws as far such laws apply to the Work.
## 9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to
conclude an additional agreement to offer, and charge a fee for, acceptance of
support, warranty, indemnity, or other liability obligations and/or services
consistent with this Licence. However, in accepting such obligations, You may
act only on your own behalf and on your sole responsibility, not on behalf of
the original Licensor or any other Contributor, and only if You agree to
indemnify, defend, and hold each Contributor harmless for any liability incurred
by, or claims asserted against such Contributor by the fact You have accepted
any such warranty or additional liability.
## 10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon “I agree”
placed under the bottom of a window displaying the text of this Licence or by
affirming consent in any other similar way, in accordance with the rules of
applicable law. Clicking on that icon indicates your clear and irrevocable
acceptance of this Licence and all of its terms and conditions.
Similarly, you irrevocably accept this Licence and all of its terms and
conditions by exercising any rights granted to You by Article 2 of this Licence,
such as the use of the Work, the creation by You of a Derivative Work or the
Distribution and/or Communication by You of the Work or copies thereof.
## 11. Information to the public
In case of any Distribution and/or Communication of the Work by means of
electronic communication by You (for example, by offering to download the Work
from a remote location) the distribution channel or media (for example, a
website) must at least provide to the public the information requested by the
applicable law regarding the Licensor, the Licence and the way it may be
accessible, concluded, stored and reproduced by the Licensee.
## 12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon
any breach by the Licensee of the terms of the Licence.
Such a termination will not terminate the licences of any person who has
received the Work from the Licensee under the Licence, provided such persons
remain in full compliance with the Licence.
## 13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete
agreement between the Parties as to the Work licensed hereunder.
If any provision of the Licence is invalid or unenforceable under applicable
law, this will not affect the validity or enforceability of the Licence as a
whole. Such provision will be construed and/or reformed so as necessary to make
it valid and enforceable.
The European Commission may publish other linguistic versions and/or new
versions of this Licence, so far this is required and reasonable, without
reducing the scope of the rights granted by the Licence. New versions of the
Licence will be published with a unique version number.
All linguistic versions of this Licence, approved by the European Commission,
have identical value. Parties can take advantage of the linguistic version of
their choice.
## 14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising
between the European Commission, as a Licensor, and any Licensee, will be
subject to the jurisdiction of the Court of Justice of the European Communities,
as laid down in article 238 of the Treaty establishing the European Community.
Any litigation arising between Parties, other than the European Commission, and
resulting from the interpretation of this License, will be subject to the
exclusive jurisdiction of the competent court where the Licensor resides or
conducts its primary business.
## 15. Applicable Law
This Licence shall be governed by the law of the European Union country where
the Licensor resides or has his registered office.
This licence shall be governed by the Belgian law if:
- a litigation arises between the European Commission, as a Licensor, and any
- Licensee; the Licensor, other than the European Commission, has no residence
- or registered office inside a European Union country.
## Appendix
“Compatible Licences” according to article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2
- Open Software License (OSL) v. 2.1, v. 3.0
- Common Public License v. 1.0
- Eclipse Public License v. 1.0
- Cecill v. 2.0

83
gxJRS/README.md Normal file
View File

@ -0,0 +1,83 @@
gxRest
----
The gCube eXtensions to the Rest Protocol (gxRest) is a set of Java libraries designed to provide convenient round-trip interaction between a Restful web application (also known as "service") and its clients.
gxRest has the flexibility for different degrees of exploitation:
* it can be entirely adopted both at client and service side with full benefit of its conventions;
* it can be used to send REST requests based only on plain HTTP;
* it can be used only to return HTTP code/messagess from the service;
* it can be used only to throw Exceptions from the service to the client.
## Examples of use
Sending a request:
```java
GXHTTPRequest request = GXHTTPRequest.newRequest("http://host:port/service/").from("GXRequestTest");
//prepare some parameters
String context ="...";
Map<String,String> queryParams = new WeakHashMap<>();
queryParams.put("param name", "param value");
GXInboundResponse response = request.path("context")
.queryParams(queryParams).withBody(context).post();
```
Returning a success response:
```java
@POST
public Response create(...) {
//Resource successfully created
URI location = ... //URI of the new resource
return GXOutboundSuccessResponse.newCREATEResponse(location)
.withMessage("Resource successfully created.")
.ofType(MediaType.APPLICATION_JSON)
.build();
}
```
Throwing an exception:
```java
@POST
public Response create(...) {
//Oh no, something failed here
GXOutboundErrorResponse.throwException(new MyCustomException("Resource already exists."));
}
```
Parsing a response
```java
// invoke the remote method and get a response.
GXInboundResponse response = ...;
if (response.hasException())
throw response.getException();
//assuming a created (200) code was expected
if (response.hasCREATEDCode()) {
System.out.println("Resource successfully created!");
}
//access content as string
String value = response.getStreamedContentAsString();
//unmasharll content as json
Context returnedContext = response.tryConvertStreamedContentFromJson(Context.class);
```
## Documentation
* [gxJRS](https://wiki.gcube-system.org/gcube/GxRest/GxJRS)
## Deployment
Notes about how to deploy this component on an infrastructure or link to wiki doc (if any).
## Built With
* [JAX-RS](https://github.com/eclipse-ee4j/jaxrs-api) - Java™ API for RESTful Web Services
* [Jersey](https://jersey.github.io/) - JAX-RS runtime
* [Maven](https://maven.apache.org/) - Dependency Management
## License
See [LICENSE.md](LICENSE.md)

42
gxJRS/gxJRS.iml Normal file
View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
<orderEntry type="module" module-name="gxHTTP" />
<orderEntry type="library" name="Maven: org.gcube.common:authorization-client:2.0.7" level="project" />
<orderEntry type="library" name="Maven: org.gcube.common:common-authorization:2.3.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.gcube.core:common-scope:1.3.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.gcube.core:common-configuration-scanner:1.1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.gcube.core:common-scope-maps:1.2.2-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.6.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.6.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.6.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.core:jersey-client:2.25.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.core:jersey-common:2.25.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.bundles.repackaged:jersey-guava:2.25.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2:hk2-api:2.5.0-b32" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2:hk2-utils:2.5.0-b32" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0-b32" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2.external:javax.inject:2.5.0-b32" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.hk2:hk2-locator:2.5.0-b32" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.27" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-classic:1.0.13" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-core:1.0.13" level="project" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.gcube.common</groupId>
<artifactId>gxREST</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>gxJRS</artifactId>
@ -19,10 +19,11 @@
</properties>
<scm>
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</developerConnection>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${parent.artifactId}/${project.artifactId}</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/gx-rest</url>
</scm>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey/jersey-bom -->
@ -36,14 +37,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-bom</artifactId>
<version>LATEST</version>
<version>3.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -55,32 +49,24 @@
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<artifactId>gcube-jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- Test Dependency -->
<dependency>
@ -103,25 +89,9 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-servicearchive</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -137,22 +137,6 @@ public class GXHTTPStreamRequest implements GXHTTP<InputStream,GXInboundResponse
return new GXInboundResponse(builder.connect());
}
/* (non-Javadoc)
* @see org.gcube.common.gxrest.request.GXHTTP#setSecurityToken(java.lang.String)
*/
@Override
public void setSecurityToken(String token) {
builder.setSecurityToken(token);
}
/* (non-Javadoc)
* @see org.gcube.common.gxrest.request.GXHTTP#isExternalCall(boolean)
*/
@Override
public void isExternalCall(boolean ext) {
builder.isExternalCall(ext);
}
/**
* @param string
* @return the request

View File

@ -155,22 +155,6 @@ public class GXHTTPStringRequest implements GXHTTP<String,GXInboundResponse> {
return new GXInboundResponse(builder.connect());
}
/* (non-Javadoc)
* @see org.gcube.common.gxrest.request.GXHTTP#setSecurityToken(java.lang.String)
*/
@Override
public void setSecurityToken(String token) {
builder.setSecurityToken(token);
}
/* (non-Javadoc)
* @see org.gcube.common.gxrest.request.GXHTTP#isExternalCall(boolean)
*/
@Override
public void isExternalCall(boolean ext) {
builder.isExternalCall(ext);
}
/**
* @param string

View File

@ -7,8 +7,8 @@ import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Map;
import java.util.Objects;
import java.util.Map.Entry;
import java.util.Objects;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
@ -25,7 +25,6 @@ import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.reference.GXHTTP;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
@ -45,7 +44,6 @@ public class GXWebTargetAdapterRequest implements GXHTTP<Entity<?>,GXInboundResp
private static final Logger logger = LoggerFactory.getLogger(GXWebTargetAdapterRequest.class);
private MediaType[] mediaType;
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
private boolean extCall = false;
/**
* Creates a new request.
@ -55,22 +53,42 @@ public class GXWebTargetAdapterRequest implements GXHTTP<Entity<?>,GXInboundResp
* @return the request
*/
public static GXWebTargetAdapterRequest newRequest(String address) {
return new GXWebTargetAdapterRequest(address, false);
return new GXWebTargetAdapterRequest(address, false, "Default");
}
/**
* Creates a new secure request.
*
* @param address
* the address of the web app to call
* @param tslprotocol
* the secure socket protocol to use in the call
* @return the request
*/
public static GXWebTargetAdapterRequest newHTTPSRequest(String address, String tslprotocol) {
return new GXWebTargetAdapterRequest(address, false, tslprotocol);
}
/**
* Creates a new request.
*
* @param address
* the address of the web app to call
* @return the request
*/
public static GXWebTargetAdapterRequest newHTTPSRequest(String address) {
return new GXWebTargetAdapterRequest(address, true);
return new GXWebTargetAdapterRequest(address, true,"Default");
}
/**
* @param address
*/
private GXWebTargetAdapterRequest(String address, boolean withHTTPS) {
private GXWebTargetAdapterRequest(String address, boolean withHTTPS, String tslprotocol ) {
Client client = ClientBuilder.newClient();
if (withHTTPS) {
try {
SSLContext sc = SSLContext.getInstance("TLSv1");
System.setProperty("https.protocols", "TLSv1");
SSLContext sc = SSLContext.getInstance(tslprotocol);
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
@ -101,26 +119,9 @@ public class GXWebTargetAdapterRequest implements GXHTTP<Entity<?>,GXInboundResp
}
}
this.adaptee = client.target(address);
this.headers.add(org.gcube.common.authorization.client.Constants.TOKEN_HEADER_ENTRY,
SecurityTokenProvider.instance.get());
this.headers.add("User-Agent", this.getClass().getSimpleName());
}
/**
* Overrides the default security token.
*
* @param token
* the new token
*/
@Override
public void setSecurityToken(String token) {
if (!this.extCall)
this.headers.add(org.gcube.common.authorization.client.Constants.TOKEN_HEADER_ENTRY, token);
else
throw new UnsupportedOperationException("Cannot set the security token on an external call");
}
/**
* Sets the identity user agent associated to the request.
*
@ -385,13 +386,4 @@ public class GXWebTargetAdapterRequest implements GXHTTP<Entity<?>,GXInboundResp
throw new UnsupportedOperationException("WebTarget does not support CONNECT");
}
/*
* (non-Javadoc)
*
* @see org.gcube.common.gxrest.request.GXHTTP#isExternalCall(boolean)
*/
@Override
public void isExternalCall(boolean ext) {
this.extCall = ext;
}
}

View File

@ -6,7 +6,7 @@ package org.gcube.common.gxrest.response.entity;
* of an ETag response header.
*
* @author Manuele Simi (ISTI CNR)
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11">HTTP/1.1 section 3.11</a>
* @see <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11">HTTP/1.1 section 3.11</a>
*/
public final class EntityTag {

View File

@ -115,7 +115,8 @@ public class SerializableErrorEntityTextReader implements MessageBodyReader<Seri
* @return the string read from the stream
*/
private static String convertStreamToString(InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
try (java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A")) {
return s.hasNext() ? s.next() : "";
}
}
}

View File

@ -104,7 +104,7 @@ public class GXInboundResponse {
// ContentUtils.toByteArray(connection.getInputStream());
if (this.contentType.equals(MediaType.TEXT_PLAIN)
|| this.contentType.equals(MediaType.APPLICATION_JSON)) {
this.body = ContentUtils.toString(ContentUtils.toByteArray(connection.getInputStream()));
this.body = ContentUtils.toString(ContentUtils.toByteArray(getInputStream()));
logger.trace("Response's content: " + this.body);
this.contentAlreadyConsumed = true;
}
@ -250,7 +250,7 @@ public class GXInboundResponse {
if(!this.contentAlreadyConsumed) {
if (this.fromConnection) {
contentAlreadyConsumed = true;
return connection.getInputStream();
return isSuccessResponse() ? connection.getInputStream() : connection.getErrorStream();
} else if (this.fromResponse) {
contentAlreadyConsumed = true;
return (InputStream) source.getEntity();

View File

@ -1,6 +1,6 @@
package org.gcube.common.gxrest.response.inbound;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
/**
* Manipulation of an {@link GXInboundResponse}'s content.

View File

@ -1,6 +1,5 @@
package org.gcube.common.gxrest.response.outbound;
import javax.print.attribute.standard.Media;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

View File

@ -1,6 +1,7 @@
package org.gcube.common.gxrest.request;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@ -8,10 +9,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.junit.AfterClass;
import org.junit.Before;
@ -20,8 +18,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import com.fasterxml.jackson.databind.JsonMappingException;
/**
* Test cases for {@link GXHTTPStringRequest}
*
@ -62,23 +58,17 @@ public class GXHTTPStringRequestTest {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
public static void setContext(String token) throws Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
}
SecurityTokenProvider.instance.set(token);
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
//SecurityTokenProvider.instance.set(token);
}
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
//SecurityTokenProvider.instance.reset();
}
/**
@ -122,7 +112,8 @@ public class GXHTTPStringRequestTest {
}
}
@Test(expected=com.fasterxml.jackson.databind.JsonMappingException.class)
@SuppressWarnings("deprecation")
@Test(expected=org.gcube.com.fasterxml.jackson.databind.JsonMappingException.class)
public void testPostNoBody() throws Exception {
if (skipTest)
throw new JsonMappingException("");

View File

@ -0,0 +1,173 @@
package org.gcube.common.gxrest.request;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
/**
* Test cases for {@link GXWebTargetAdapterRequest#newHTTPSRequest(String)}
*
* @author Manuele Simi (ISTI-CNR)
*
*/
@RunWith(BlockJUnit4ClassRunner.class)
public class GXWebTargetAdapterHTTPSRequestTest {
private GXWebTargetAdapterRequest request;
// private GXWebTargetAdapterRequest requestWithProtocol;
public static String DEFAULT_TEST_SCOPE = "";
static String DEFAULT_RM_URL = "";
static String DEFAULT_RR_URL = "";
private static boolean skipTest = false;
static {
Properties properties = new Properties();
try (InputStream input = GXWebTargetAdapterRequest.class.getClassLoader().getResourceAsStream("token.props")) {
// load the properties file
properties.load(input);
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
if (DEFAULT_TEST_SCOPE.isEmpty())
skipTest = true;
DEFAULT_RM_URL = properties.getProperty("RM_URL");
DEFAULT_RR_URL = properties.getProperty("RR_URL");
} catch (IOException | NullPointerException e) {
skipTest = true;
}
}
@BeforeClass
public static void beforeClass() throws Exception {
if (!skipTest)
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws Exception {
if (skipTest || DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
} else {
//SecurityTokenProvider.instance.set(token);
}
}
@AfterClass
public static void afterClass() throws Exception {
//SecurityTokenProvider.instance.reset();
}
/**
* Test method for {@link GXHTTPStringRequest#newRequest(String)}.
*/
@Before
public void testNewRequest() {
request = GXWebTargetAdapterRequest.newHTTPSRequest(DEFAULT_RM_URL).from("GXRequestTest");
// requestWithProtocol = GXWebTargetAdapterRequest.newHTTPSRequest(DEFAULT_RM_URL, "").from("GXRequestTest");
}
/**
* Test method for {@link GXWebTargetAdapterRequest#put()}.
*/
@Test
public void testPut() {
if (skipTest)
return;
//fail("Not yet implemented");
}
/**
* Test method for {@link GXWebTargetAdapterRequest#delete()}.
*/
@Test
public void testDelete() {
if (skipTest)
return;
//fail("Not yet implemented");
}
/**
* Test method for {@link GXWebTargetAdapterRequest#post()}.
*/
@Test
public void testPost() {
if (skipTest)
return;
String context ="{\"@class\":\"Context\",\"header\":{\"@class\":\"Header\",\"uuid\":\"6f86dc81-2f59-486b-8aa9-3ab5486313c4\",\"creator\":null,\"modifiedBy\":\"gxRestTest\",\"creationTime\":null,\"lastUpdateTime\":null},\"name\":\"gxTest\",\"parent\":null,\"children\":[]}";
Map<String,Object[]> queryParams = new WeakHashMap<>();
queryParams.put("rrURL", new String[]{DEFAULT_RR_URL});
try {
GXInboundResponse response = request.path("gxrest")
.header("User-Agent", this.getClass().getSimpleName())
.header("Another header", "another value")
.queryParams(queryParams).post(Entity.entity(context, MediaType.APPLICATION_JSON + ";charset=UTF-8"));
assertTrue("Unexpected returned code.", response.hasCREATEDCode());
if (response.hasGXError()) {
if (response.hasException()) {
try {
throw response.getException();
} catch (ClassNotFoundException e) {
//that's OK, we can tolerate this
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
} else {
if (response.hasCREATEDCode()) {
System.out.println("Resource successfully created!");
System.out.println("Returned message: " + response.getStreamedContentAsString());
} else {
System.out.println("Resource creation failed. Returned status:" + response.getHTTPCode());
//if you want to use the original responser
response.getSource();
//then consume the response
}
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed to send a POST request");
}
}
/**
* Test method for {@link GXWebTargetAdapterRequest#head()}.
*/
@Test
public void testHead() {
if (skipTest)
return;
//fail("Not yet implemented");
}
/**
* Test method for {@link GXWebTargetAdapterRequest#get()}.
*/
@Test
public void testGet() {
if (skipTest)
return;
//fail("Not yet implemented");
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.common.gxrest.request;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@ -11,10 +12,6 @@ import java.util.WeakHashMap;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.junit.AfterClass;
import org.junit.Before;
@ -62,24 +59,19 @@ public class GXWebTargetAdapterRequestTest {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
public static void setContext(String token) throws Exception {
if (skipTest || DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
} else {
SecurityTokenProvider.instance.set(token);
//SecurityTokenProvider.instance.set(token);
}
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
//SecurityTokenProvider.instance.reset();
}
/**

View File

@ -1 +0,0 @@
gxREST

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="gxHTTP" />
<module name="gxJRS" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/.." charset="UTF-8" />
<file url="file://$PROJECT_DIR$/../gxHTTP" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/../gxJRS" charset="UTF-8" />
</component>
</project>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/../pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnBranchConfigurationManager">
<option name="myConfigurationMap">
<map>
<entry key="$PROJECT_DIR$/..">
<value>
<SvnBranchConfiguration>
<option name="branchUrls">
<list>
<option value="https://svn.d4science.research-infrastructures.eu/gcube/branches" />
<option value="https://svn.d4science.research-infrastructures.eu/gcube/misc" />
<option value="https://svn.d4science.research-infrastructures.eu/gcube/private" />
<option value="https://svn.d4science.research-infrastructures.eu/gcube/tags" />
</list>
</option>
<option name="trunkUrl" value="https://svn.d4science.research-infrastructures.eu/gcube/trunk" />
</SvnBranchConfiguration>
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="svn" />
</component>
</project>

19
pom.xml
View File

@ -5,12 +5,12 @@
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>1.0.0</version>
<version>1.2.0</version>
</parent>
<groupId>org.gcube.common</groupId>
<artifactId>gxREST</artifactId>
<version>1.1.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>gCube eXtensions to REST</name>
<description>gCube eXtensions to REST</description>
@ -28,9 +28,9 @@
</properties>
<scm>
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</connection>
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</developerConnection>
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/${project.artifactId}</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/gx-rest</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/gx-rest</url>
</scm>
@ -47,14 +47,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.gcube.information-system</groupId>
<artifactId>information-system-bom</artifactId>
<version>LATEST</version>
<version>3.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>