Skip to content

Commit

Permalink
start working on #109
Browse files Browse the repository at this point in the history
  • Loading branch information
gskorupa committed Sep 22, 2016
1 parent c51019c commit 1e53bf2
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(RestApiErrorCodes.class)
public @interface RestApiErrorCode {
public int code();
public String description();
}
29 changes: 29 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiErrorCodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RestApiErrorCodes {
RestApiErrorCode[] value();
}
37 changes: 37 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(RestApiParameters.class)
public @interface RestApiParameter {
public String name();
public String constraint();
public String description();
}
29 changes: 29 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiParameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RestApiParameters {
RestApiParameter[] value();
}
33 changes: 33 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RestApiResult {
public String description();
}
36 changes: 36 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiResultCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(RestApiResultCodes.class)
public @interface RestApiResultCode {
public int code();
public String description();
}
29 changes: 29 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiResultCodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RestApiResultCodes {
RestApiResultCode[] value();
}
34 changes: 34 additions & 0 deletions src/java/org/cricketmsf/annotation/RestApiUriVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2016 Grzegorz Skorupa <g.skorupa at gmail.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.cricketmsf.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* @author Grzegorz Skorupa <g.skorupa at gmail.com>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RestApiUriVariables {
public String path();
public String description();
}
22 changes: 21 additions & 1 deletion src/java/org/cricketmsf/services/EchoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import org.cricketmsf.out.log.LoggerAdapterIface;
import java.util.HashMap;
import org.cricketmsf.InboundAdapterHook;
import org.cricketmsf.annotation.RestApiErrorCode;
import org.cricketmsf.annotation.RestApiParameter;
import org.cricketmsf.annotation.RestApiResult;
import org.cricketmsf.annotation.RestApiResultCode;
import org.cricketmsf.annotation.RestApiUriVariables;
import org.cricketmsf.in.http.EchoHttpAdapterIface;
import org.cricketmsf.in.http.HtmlGenAdapterIface;
import org.cricketmsf.in.http.HttpAdapterIface;
Expand Down Expand Up @@ -156,7 +161,22 @@ public Object scheduleEvent(Event requestEvent) {
return sendEcho((RequestObject) requestEvent.getPayload());
}

@HttpAdapterHook(adapterName = "EchoAdapter", requestMethod = "*")
/**
* Handling request from EchoAdapter.
* The method is linked to the adapter by using @HttpAdapterHook annotation.
* Other annotations are for the API documentation only and has no result in the
* method or the service logic.
*
* @param requestEvent
* @return
*/
@HttpAdapterHook(adapterName = "EchoAdapter", requestMethod = "GET")
@RestApiUriVariables(path = "/{id}", description = "eg. object ID (here not used)")
@RestApiParameter(name = "name", constraint = "optional", description = "")
@RestApiParameter(name = "surname", constraint = "optional", description = "")
@RestApiResult(description = "StandardResult with copy of request parameters")
@RestApiResultCode(code = 200, description = "OK")
@RestApiErrorCode(code = 500, description = "error forced by request parameter")
public Object doGetEcho(Event requestEvent) {
return sendEcho((RequestObject) requestEvent.getPayload());
}
Expand Down

0 comments on commit 1e53bf2

Please sign in to comment.