Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Change: Made API class easier to work with #1374

Merged
merged 17 commits into from
May 6, 2019

Conversation

kwek20
Copy link
Contributor

@kwek20 kwek20 commented Mar 14, 2019

Description

The API.java class is currently very unmaintainable.
This PR will externalize the REST client used, and switch from pure undertow to resteasy with undertow impl for easy switching later on.
API commands are no longer run from inside a switch, but according to the method proposed in #392

Backwards compatible as no changes are made to the request/result requirements.

Fixes #920

The following files are not yet used, but will be needed for #874

  • restserver/resteasy/ApiPath.java
  • restserver/resteasy/RootPath.java
  • restserver/ApiCall.java

Not sure what to do with them

Type of change

  • Enhancement (a non-breaking change which adds functionality)
  • Documentation Fix

How Has This Been Tested?

Added tests for new classes, node ran and API called.

Checklist:

  • My code follows the style guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@@ -1,6 +1,6 @@
package com.iota.iri.service;

public class ValidationException extends Exception {
public class ValidationException extends RuntimeException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required so that the functional command routing doesnt need try/catch -> throw another error

@kwek20 kwek20 changed the title Cleaned up API Change: Made API class easier to work with Mar 15, 2019
@jakubcech jakubcech added this to the Varanasi milestone Mar 18, 2019
@jakubcech jakubcech modified the milestones: Varanasi, Udaipur Apr 1, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
@iotaledger iotaledger deleted a comment Apr 17, 2019
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better than before
Please delete experimental classes that don't seem to serve functionality (i.e. the one with jax-rs annotations)

src/main/java/com/iota/iri/IRI.java Show resolved Hide resolved
src/main/java/com/iota/iri/service/ApiCommand.java Outdated Show resolved Hide resolved
src/main/java/com/iota/iri/service/restserver/ApiCall.java Outdated Show resolved Hide resolved
src/main/java/com/iota/iri/service/API.java Outdated Show resolved Hide resolved
src/main/java/com/iota/iri/service/API.java Show resolved Hide resolved
throw new IllegalStateException(e);
}
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice,

So in later PRs, wall those statement methods can be moved to their own services so that the API will only be about declarations and initial parameter processing/validation.

src/main/java/com/iota/iri/service/ApiCommand.java Outdated Show resolved Hide resolved
private AbstractResponse process() {
return AbstractResponse.createEmptyResponse();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you couldn't get JAX-RS to work you shouldn't have added your experiments to the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make it work, but it would change all API paths and calling method. So i left it at this for now.

I left it for us to decide what to do with them. Ill stash them in a local branch

*
*/
@ApplicationPath("")
public class RestEasy extends Application implements RestConnector {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made your own resteasy implementation?
Does it have anything to do with this
https://github.com/resteasy/Resteasy/ ?

Because the name is confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it uses the RestEasy implementation provided through UndertowJaxrsServer, what name would you give it? UndertowJaxrsRestEasy? :)

@@ -125,6 +125,19 @@
<artifactId>undertow-websockets-jsr</artifactId>
<version>${undertow.version}</version>
</dependency>

<!-- RESTEasy Undertow Integration -->
Copy link
Contributor

@alon-e alon-e Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add digest rules to the enforcer:

iri/pom.xml

Lines 369 to 383 in 9821a60

<digestRule implementation="uk.co.froot.maven.enforcer.DigestRule">
<!-- Create a snapshot to build the list of URNs below -->
<buildSnapshot>true</buildSnapshot>
<!-- List of required hashes -->
<!-- Format is URN of groupId:artifactId:version:type:classifier:scope:hash -->
<!-- classifier is "null" if not present -->
<urns>
<urn>
org.apache.commons:commons-lang3:3.5:jar:null:compile:6c6c702c89bfff3cd9e80b04d668c5e190d588c6
</urn>
<!-- http://repo2.maven.org/maven2/org/slf4j/slf4j-api/1.7.25/ -->
<urn>
org.slf4j:slf4j-api:1.7.25:jar:null:compile:da76ca59f6a57ee3102f8f9bd9cee742973efa8a

@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 24, 2019
@iotaledger iotaledger deleted a comment Apr 25, 2019
Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 little changes and that is all :-)

API still has some reworking to do but we shall wait for #874

try {
return getTransactionsToApproveStatement(depth, reference);
} catch (Exception e) {
throw new IllegalStateException(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you drill down to getTransactionsToApproveStatement you will see that it doesn't really throw any exception. So you can remove this wrapping.

log.error("API Validation failed: " + e.getLocalizedMessage());
return ExceptionResponse.create(e.getLocalizedMessage());
} catch (final IllegalStateException e) {
log.error("API Exception: " + e.getLocalizedMessage());
return ExceptionResponse.create(e.getLocalizedMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a clause for unexpected problems we don't foresee

catch (RuntimeException e) {
  log.error("Unexpected API Exception: " + e.getLocalizedMessage());
  return ExceptionResponse.create(e.getLocalizedMessage());
}

While you are at it, please remove those annoying final from the other catch clauses.

@iotaledger iotaledger deleted a comment Apr 29, 2019
@GalRogozinski GalRogozinski mentioned this pull request May 5, 2019
3 tasks
@GalRogozinski GalRogozinski merged commit 6a0606e into iotaledger:dev May 6, 2019
@jakubcech jakubcech mentioned this pull request May 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use RESTEasy implementation of JAX-RS
4 participants