Skip to content

Commit

Permalink
Merge pull request #7 from SBI-/master
Browse files Browse the repository at this point in the history
Fix routing NPE and use google styling
  • Loading branch information
SBI- authored Jul 23, 2018
2 parents d0c3511 + c5cfa00 commit 072ef1a
Show file tree
Hide file tree
Showing 32 changed files with 1,725 additions and 1,728 deletions.
2 changes: 1 addition & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Base
Bundle-SymbolicName: com.siemens.bt.jazz.services.base;singleton:=true
Bundle-Version: 3.0.2.qualifier
Bundle-Version: 3.0.3.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: com.siemens.bt.jazz.services.base,
com.siemens.bt.jazz.services.base.rest,
Expand Down
23 changes: 10 additions & 13 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.siemens.bt.jazz.services.base</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>com.siemens.bt.jazz.services.base</groupId>
<artifactId>com.siemens.bt.jazz.services.base.parent</artifactId>
<version>3.0.2-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.siemens.bt.jazz.services.base</artifactId>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>com.siemens.bt.jazz.services.base</groupId>
<artifactId>com.siemens.bt.jazz.services.base.parent</artifactId>
<version>3.0.3-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,121 +5,100 @@
import com.siemens.bt.jazz.services.base.rest.RestAction;
import com.siemens.bt.jazz.services.base.rest.RestActionBuilder;
import com.siemens.bt.jazz.services.base.rest.parameters.RestRequest;
import com.siemens.bt.jazz.services.base.router.map.MapRouter;
import com.siemens.bt.jazz.services.base.router.Router;

import com.siemens.bt.jazz.services.base.router.map.MapRouter;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* Entry point for the ExampleService, called by the Jazz class loader.
*
* <p>
* This class must be implemented for enabling plugins to run inside Jazz. The implemented interface corresponds to
* the component in {@code plugin.xml}, and this service is therefore the provided service by the interface.
* </p>
* <p>This class must be implemented for enabling plugins to run inside Jazz. The implemented
* interface corresponds to the component in {@code plugin.xml}, and this service is therefore the
* provided service by the interface.
*/
public abstract class BaseService extends TeamRawService {

protected final Router router = new MapRouter();
protected final Router router = new MapRouter();

/**
* Constructs a new ClearQuestService
*
* <p>
* This constructor is only called by the Jazz class loader.
* </p>
*/
public BaseService() {
super();
}
/**
* Constructs a new ClearQuestService
*
* <p>This constructor is only called by the Jazz class loader.
*/
public BaseService() {
super();
}

/**
* Called when a HTTP GET request is sent.
*/
@Override
public void perform_GET(
String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
performAction(uri, request, response);
}
/** Called when a HTTP GET request is sent. */
@Override
public void perform_GET(String uri, HttpServletRequest request, HttpServletResponse response)
throws IOException {
performAction(uri, request, response);
}

/**
* Called when a HTTP POST request is sent.
*/
@Override
public void perform_POST(
String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
performAction(uri, request, response);
}
/** Called when a HTTP POST request is sent. */
@Override
public void perform_POST(String uri, HttpServletRequest request, HttpServletResponse response)
throws IOException {
performAction(uri, request, response);
}

/**
* Called when a HTTP PUT request is sent.
*/
@Override
public void perform_PUT(
String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
performAction(uri, request, response);
}
/** Called when a HTTP PUT request is sent. */
@Override
public void perform_PUT(String uri, HttpServletRequest request, HttpServletResponse response)
throws IOException {
performAction(uri, request, response);
}

/**
* Called when a HTTP PUT request is sent.
*/
@Override
public void perform_DELETE(
String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
performAction(uri, request, response);
}
/** Called when a HTTP PUT request is sent. */
@Override
public void perform_DELETE(String uri, HttpServletRequest request, HttpServletResponse response)
throws IOException {
performAction(uri, request, response);
}

/**
* Calls the requested method and handles errors.
*
* <p>
* With the current architecture, it's easier to have dummy public methods and handle them all with this single
* function. Error handling in jazz is a bit special, and to guarantee that the service is functionally sound,
* all errors except {@code 501} and {@code IOExceptions} should be handled internally. If not handled and logged,
* a generic {@code 500} exception is returned with little help for debugging.
* </p>
*
* @param uri Relative URI to which the request was sent
* @param request ServletRequest object that contains all request information
* @param response A wrapped IO Handler for responses
* @throws IOException Only exception thrown back to Jazz, corresponding with the contract from the inherited method.
*/
protected void performAction(
String uri,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
try {
RestActionBuilder builder = prepareRequest(uri, request, response);
RestAction action = builder.create();
action.execute();
} catch (IOException e) {
throw e;
} catch (Exception e) {
// catch everything and log. Makes sure that there is no checked exception from our service back
// to jazz, except for the expected IOException when the response isn't writable. We need to make
// sure that our plug-in conforms to the contract that no exceptions bubble out into the system.
super.getLog().error(e);
this.http500return(request, response, e);
}
/**
* Calls the requested method and handles errors.
*
* <p>With the current architecture, it's easier to have dummy public methods and handle them all
* with this single function. Error handling in jazz is a bit special, and to guarantee that the
* service is functionally sound, all errors except {@code 501} and {@code IOExceptions} should be
* handled internally. If not handled and logged, a generic {@code 500} exception is returned with
* little help for debugging.
*
* @param uri Relative URI to which the request was sent
* @param request ServletRequest object that contains all request information
* @param response A wrapped IO Handler for responses
* @throws IOException Only exception thrown back to Jazz, corresponding with the contract from
* the inherited method.
*/
protected void performAction(String uri, HttpServletRequest request, HttpServletResponse response)
throws IOException {
try {
RestActionBuilder builder = prepareRequest(uri, request, response);
RestAction action = builder.create();
action.execute();
} catch (IOException e) {
throw e;
} catch (Exception e) {
// catch everything and log. Makes sure that there is no checked exception from our service
// back
// to jazz, except for the expected IOException when the response isn't writable. We need to
// make
// sure that our plug-in conforms to the contract that no exceptions bubble out into the
// system.
super.getLog().error(e);
this.http500return(request, response, e);
}
}

protected final RestActionBuilder prepareRequest(
String uri,
HttpServletRequest request,
HttpServletResponse response) {
HttpMethod method = HttpMethod.fromString(request.getMethod());
@SuppressWarnings("unchecked")
RestRequest restRequest = new RestRequest(method, uri, request.getParameterMap());
return router.prepareAction(this, this.getLog(), request, response, restRequest);
}
protected final RestActionBuilder prepareRequest(
String uri, HttpServletRequest request, HttpServletResponse response) {
HttpMethod method = HttpMethod.fromString(request.getMethod());
@SuppressWarnings("unchecked")
RestRequest restRequest = new RestRequest(method, uri, request.getParameterMap());
return router.prepareAction(this, this.getLog(), request, response, restRequest);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.siemens.bt.jazz.services.base.rest;


/**
* <p>Interface for the command pattern of calling actions.</p>
* <p>The command pattern is described with this name by the Gang of Four.</p>
* Interface for the command pattern of calling actions.
*
* <p>The command pattern is described with this name by the Gang of Four.
*
* @see <a href="https://en.wikipedia.org/wiki/Command_pattern">Wikipedia: Command Pattern</a>
*/
public interface RestAction {
/**
* Executes the implemented action.
*
* @throws Exception Any exception that occurs while executing a service action.
*/
void execute() throws Exception;
/**
* Executes the implemented action.
*
* @throws Exception Any exception that occurs while executing a service action.
*/
void execute() throws Exception;
}
Loading

0 comments on commit 072ef1a

Please sign in to comment.