-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/nta restapi #68
Open
Amila17
wants to merge
21
commits into
jbosstm:main
Choose a base branch
from
Amila17:Feature/NTA_Restapi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ec7006d
Feature/NTA_Restapi
Amila17 79ede8e
Feature/NTA_Restapi
Amila17 85de14d
Feature/NTA_Restapi
Amila17 20d6dba
Feature/NTA_Restapi
Amila17 e783120
Merge branch 'master' of github.com:Amila17/transaction-analyser into…
Amila17 f6988c3
Feature/NTA_Restapi
Amila17 2eda659
Feature/NTA_Restapi
Amila17 75705f3
Feature/NTA_Restapi
Amila17 a40be5e
Feature/NTA_Restapi
Amila17 ea88e19
Feature/NTA_Restapi
Amila17 00b3e27
Feature/NTA_Restapi
Amila17 abdbff5
Feature/NTA_Restapi
Amila17 645f367
Feature/NTA_Restapi
Amila17 d5f3f64
Feature/NTA_Restapi
Amila17 2ae5734
Feature/NTA_Restapi
Amila17 a42c657
Feature/NTA_Restapi
Amila17 9dd4a8d
Merge branch 'master' of github.com:jbosstm/transaction-analyser into…
Amila17 3d7364c
Feature/NTA_Restapi
Amila17 ee291be
Feature/NTA_Restapi
Amila17 c43e27a
Feature/NTA_Restapi
Amila17 c4c4578
Feature/NTA_Restapi
Amila17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ target | |
.project | ||
.settings | ||
.classpath | ||
*.orig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>nta-all</artifactId> | ||
<groupId>io.narayana.nta</groupId> | ||
<version>1.0.0.Alpha3-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>restapi</artifactId> | ||
<name>Narayana Transaction Analyser REST API</name> | ||
<description>Contains the REST API component of the tool</description> | ||
<packaging>war</packaging> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.spec</groupId> | ||
<artifactId>jboss-javaee-7.0</artifactId> | ||
<version>1.0.0.Final</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.narayana.nta</groupId> | ||
<artifactId>core</artifactId> | ||
<version>1.0.0.Alpha3-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.spec.javax.servlet</groupId> | ||
<artifactId>jboss-servlet-api_3.1_spec</artifactId> | ||
<version>1.0.0.Final</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jaxrs</artifactId> | ||
<version>2.3.2.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-cdi</artifactId> | ||
<version>2.3.2.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<version>1.0-SP4</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<version>1.1.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<version>5.0.3.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.wildfly</groupId> | ||
<artifactId>wildfly-controller-client</artifactId> | ||
<version>8.0.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of white space here... |
||
|
||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<version>${version.war.plugin}</version> | ||
<configuration> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${version.compiler.plugin}</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${version.maven.surefire}</version> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
restapi/src/main/java/io/narayana/nta/restapi/apis/Root.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.narayana.nta.restapi.apis; | ||
|
||
import io.narayana.nta.restapi.models.URIConstants; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to add the standard copyright and author details. See other files for examples. |
||
* Created with IntelliJ IDEA. | ||
* User: Amila | ||
* Date: 04/05/14 | ||
* Time: 17:52 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@ApplicationPath(URIConstants.RootURI) | ||
public class Root extends Application | ||
{ | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
restapi/src/main/java/io/narayana/nta/restapi/apis/TracerAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.narayana.nta.restapi.apis; | ||
|
||
import io.narayana.nta.restapi.models.Response.BaseResponse; | ||
import io.narayana.nta.restapi.models.URIConstants; | ||
import io.narayana.nta.restapi.services.TraceLoggingService; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Amila | ||
* Date: 14/05/14 | ||
* Time: 23:01 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@Path(URIConstants.TracerURI) | ||
public class TracerAPI | ||
{ | ||
@Inject | ||
private TraceLoggingService traceLoggingService; | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getTraceStatus() | ||
{ | ||
boolean tracingStatus = traceLoggingService.getTraceLoggingEnable(); | ||
|
||
BaseResponse baseResponse = new BaseResponse(); | ||
baseResponse.setMessage(String.valueOf(tracingStatus)); | ||
baseResponse.setStatus(Response.Status.OK); | ||
return Response.ok(baseResponse).build(); | ||
} | ||
|
||
@POST | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response setTransactionStatus(@QueryParam("enable") boolean enable) | ||
{ | ||
traceLoggingService.setTraceLoggingEnable(enable); | ||
|
||
String status = enable ? "Enabled" : "Disabled"; | ||
BaseResponse baseResponse = new BaseResponse(); | ||
baseResponse.setMessage("Trace logging has been " + status); | ||
baseResponse.setStatus(Response.Status.OK); | ||
|
||
return Response.ok(baseResponse).build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
restapi/src/main/java/io/narayana/nta/restapi/apis/TransactionAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.narayana.nta.restapi.apis; | ||
|
||
import io.narayana.nta.persistence.enums.Status; | ||
import io.narayana.nta.restapi.models.Response.PayloadResponse; | ||
import io.narayana.nta.restapi.models.URIConstants; | ||
import io.narayana.nta.restapi.services.TransactionService; | ||
|
||
import javax.inject.Inject; | ||
import javax.validation.constraints.NotNull; | ||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Amila | ||
* Date: 04/05/14 | ||
* Time: 17:52 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@Path(URIConstants.TransactionURI) | ||
public class TransactionAPI | ||
{ | ||
@Inject | ||
private TransactionService transactionService; | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getTransactions( | ||
@QueryParam("status") | ||
String status) | ||
{ | ||
PayloadResponse payloadResponse = new PayloadResponse(); | ||
payloadResponse.setStatus(Response.Status.OK); | ||
|
||
if(status == null) | ||
{ | ||
payloadResponse.setPayload(transactionService.getTransactions()); | ||
return Response.ok(payloadResponse).build(); | ||
} | ||
|
||
Status requestedTransactionStatus = Status.valueOf(status.toUpperCase()); | ||
payloadResponse.setPayload(transactionService.getTransactions(requestedTransactionStatus)); | ||
return Response.ok(payloadResponse).build(); | ||
} | ||
|
||
@GET | ||
@Path("/{id}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response getTransactionById( | ||
@PathParam("id") | ||
@NotNull | ||
Long id) | ||
{ | ||
PayloadResponse payloadResponse = new PayloadResponse(); | ||
payloadResponse.setStatus(Response.Status.OK); | ||
payloadResponse.setPayload(transactionService.getTransaction(id)); | ||
return Response.ok(payloadResponse).build(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/io/narayana/nta/restapi/handlers/exceptions/ApplicationExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.narayana.nta.restapi.handlers.exceptions; | ||
|
||
import io.narayana.nta.restapi.models.Response.ErrorResponse; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Amila | ||
* Date: 27/05/14 | ||
* Time: 22:51 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
@Provider | ||
public class ApplicationExceptionHandler implements ExceptionMapper<Exception> | ||
{ | ||
@Override | ||
public Response toResponse(Exception exception) | ||
{ | ||
ErrorResponse errorResponse = new ErrorResponse(); | ||
errorResponse.setMessage(exception.getMessage()); | ||
errorResponse.setExceptionClass(exception.getClass()); | ||
errorResponse.setException(exception); | ||
if(exception.getCause() != null) | ||
{ | ||
errorResponse.setCause(exception.getCause().toString()); | ||
} | ||
|
||
if(exception instanceof IllegalArgumentException) | ||
{ | ||
errorResponse.setStatus(Response.Status.BAD_REQUEST); | ||
return BadRequestResponse(errorResponse); | ||
} | ||
|
||
errorResponse.setStatus(Response.Status.INTERNAL_SERVER_ERROR); | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorResponse).type(MediaType.APPLICATION_JSON).build(); | ||
} | ||
|
||
private Response BadRequestResponse(ErrorResponse errorResponse) | ||
{ | ||
return Response.status(Response.Status.BAD_REQUEST).entity(errorResponse).type(MediaType.APPLICATION_JSON).build(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...src/main/java/io/narayana/nta/restapi/handlers/exceptions/ValidationExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.narayana.nta.restapi.handlers.exceptions; | ||
|
||
import io.narayana.nta.restapi.models.Response.ErrorResponse; | ||
|
||
import javax.validation.ConstraintViolationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Amila | ||
* Date: 27/05/14 | ||
* Time: 23:30 | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class ValidationExceptionHandler implements ExceptionMapper<ConstraintViolationException> | ||
{ | ||
@Override | ||
public Response toResponse(ConstraintViolationException exception) | ||
{ | ||
ErrorResponse errorResponse = new ErrorResponse(); | ||
errorResponse.setMessage(exception.getMessage()); | ||
errorResponse.setExceptionClass(exception.getClass()); | ||
errorResponse.setException(exception); | ||
errorResponse.setViolations(exception.getConstraintViolations().toString()); | ||
if(exception.getCause() != null) | ||
{ | ||
errorResponse.setCause(exception.getCause().toString()); | ||
} | ||
errorResponse.setStatus(Response.Status.BAD_REQUEST); | ||
|
||
return Response.status(Response.Status.BAD_REQUEST).entity(errorResponse).type(MediaType.APPLICATION_JSON).build(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave the web-console on /nta? Maybe change the rest api to be on /nta/rest or something? Is there a defacto standard for that url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will revert the url change made on web-console and update the rest url to nta/rest. There is no defacto standard but the preferred standard is "host/project/rest/api/version/endpoint". This can be seen in the following line: https://github.com/Amila17/transaction-analyser/blob/Feature/NTA_Restapi/restapi/src/main/java/io/narayana/nta/restapi/models/URIConstants.java#L12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so switching the context root to "nta/rest" should fix the problem without breaking your URL? Assuming it works of course. Overlapping context roots might not be allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The over lapping context root url might be a problem, I will need to test it to confirm on that.