// Path: rahub-cross-cutting-concerns/src/main/java/net/jotorren/microservices/rs/ExceptionRestHandler.java
// public class ExceptionRestHandler implements ExceptionMapper<Exception>{
// 
// 	public class ErrorDetails {
// 		private int code;
// 		private String message;
// 		private String stack;
// 		
// 		public ErrorDetails(int code, String message, String stack){
// 			this.code = code;
// 			this.message = message;			
// 			this.stack = stack;
// 		}
// 
// 		public int getCode() {
// 			return code;
// 		}
// 
// 		public String getMessage() {
// 			return message;
// 		}
// 		
// 		public String getStack() {
// 			return stack;
// 		}
// 	}
// 	
// 	@Override
// 	public Response toResponse(Exception exception) {
// 		return toResponse(exception, Response.Status.INTERNAL_SERVER_ERROR);
// 	}
// 		
// 	public Response toResponse(Exception exception, Response.Status status) {
// 		return Response.status(status).entity(
// 				new ErrorDetails(status.getStatusCode(), exception.getMessage(), toString(exception))).build();
// 	}
// 
// 	public String toString(Exception exception) {
// 		StringWriter sw = new StringWriter();
// 		PrintWriter pw = new PrintWriter(sw);
// 		exception.printStackTrace(pw);
// 		String stack = sw.toString();
// 		pw.close();
// 		
// 		return stack;
// 	}
// }


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import net.jotorren.microservices.rs.ExceptionRestHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
		getCompositeTransactionParticipantService().cancel(txid);
		
		LOG.info("Transaction [{}] rolled back", txid);
	}

	@PUT
	@Path("/tcc/{txid}")
	@Consumes("application/tcc")
    @ApiOperation(
    		code = 204,
    		response = String.class,
            value = "Commit a given composite transaction",
            notes = "See https://www.atomikos.com/Blog/TransactionManagementAPIForRESTTCC",
            consumes = "application/tcc"
        )
	@ApiResponses(value = {
			@ApiResponse(code=404, message="Error committing transaction", response = String.class)
	})
	public void confirm(
			@ApiParam(value = "Id of the composite transaction to commit", required = true) @PathParam("txid") String txid
		){
		LOG.info("Trying to commit transaction [{}]", txid);
		
		try {
			getCompositeTransactionParticipantService().confirm(txid);
		
			LOG.info("Transaction [{}] committed", txid);
		} catch(Exception e){
			// See com.atomikos.icatch.tcc.rest.ParticipantAdapterImp.callConfirmOnJaxrsClient()
			Response response =	Response.status(Response.Status.NOT_FOUND)
// Path: rahub-cross-cutting-concerns/src/main/java/net/jotorren/microservices/rs/ExceptionRestHandler.java
// public class ExceptionRestHandler implements ExceptionMapper<Exception>{
// 
// 	public class ErrorDetails {
// 		private int code;
// 		private String message;
// 		private String stack;
// 		
// 		public ErrorDetails(int code, String message, String stack){
// 			this.code = code;
// 			this.message = message;			
// 			this.stack = stack;
// 		}
// 
// 		public int getCode() {
// 			return code;
// 		}
// 
// 		public String getMessage() {
// 			return message;
// 		}
// 		
// 		public String getStack() {
// 			return stack;
// 		}
// 	}
// 	
// 	@Override
// 	public Response toResponse(Exception exception) {
// 		return toResponse(exception, Response.Status.INTERNAL_SERVER_ERROR);
// 	}
// 		
// 	public Response toResponse(Exception exception, Response.Status status) {
// 		return Response.status(status).entity(
// 				new ErrorDetails(status.getStatusCode(), exception.getMessage(), toString(exception))).build();
// 	}
// 
// 	public String toString(Exception exception) {
// 		StringWriter sw = new StringWriter();
// 		PrintWriter pw = new PrintWriter(sw);
// 		exception.printStackTrace(pw);
// 		String stack = sw.toString();
// 		pw.close();
// 		
// 		return stack;
// 	}
// }


// Path: rahub-cross-cutting-concerns/src/main/java/net/jotorren/microservices/tx/CompositeTransactionParticipantController.java
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import net.jotorren.microservices.rs.ExceptionRestHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

		getCompositeTransactionParticipantService().cancel(txid);
		
		LOG.info("Transaction [{}] rolled back", txid);
	}

	@PUT
	@Path("/tcc/{txid}")
	@Consumes("application/tcc")
    @ApiOperation(
    		code = 204,
    		response = String.class,
            value = "Commit a given composite transaction",
            notes = "See https://www.atomikos.com/Blog/TransactionManagementAPIForRESTTCC",
            consumes = "application/tcc"
        )
	@ApiResponses(value = {
			@ApiResponse(code=404, message="Error committing transaction", response = String.class)
	})
	public void confirm(
			@ApiParam(value = "Id of the composite transaction to commit", required = true) @PathParam("txid") String txid
		){
		LOG.info("Trying to commit transaction [{}]", txid);
		
		try {
			getCompositeTransactionParticipantService().confirm(txid);
		
			LOG.info("Transaction [{}] committed", txid);
		} catch(Exception e){
			// See com.atomikos.icatch.tcc.rest.ParticipantAdapterImp.callConfirmOnJaxrsClient()
			Response response =	Response.status(Response.Status.NOT_FOUND)
					.entity(new ExceptionRestHandler().toString(e)).type(MediaType.TEXT_PLAIN).build();