Last active
February 12, 2016 08:45
-
-
Save takawitter/5a12059ef8ec971efa61 to your computer and use it in GitHub Desktop.
The script which serve the service via JSON-RPC using Service Grid Service Container and Jetty.
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
groovy service.groovy |
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
curl --globoff "http://127.0.0.1:8080/app/services/TestService?method=f¶ms=[3]&id=1" |
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
curl "http://127.0.0.1:8080/app/services/TestService" -d '{"method":"f","params":[3],"id":1}' |
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
@Grab('org.eclipse.jetty:jetty-webapp:9.3.0.M1') | |
@Grab('net.servicegrid:jp.go.nict.langrid.servicecontainer:1.0.6') | |
import jp.go.nict.langrid.servicecontainer.handler.annotation.Service; | |
import jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet; | |
import org.eclipse.jetty.server.Server; | |
import org.eclipse.jetty.webapp.WebAppContext; | |
public interface TestService{ | |
int f(int n); | |
} | |
public class TestServiceImpl implements TestService{ | |
public int f(int n){ return n + 2;} | |
} | |
@Service(name="TestService", impl=TestServiceImpl.class, intf=TestService.class) | |
public class Servlet extends JsonRpcServlet{} | |
WebAppContext webapp = new WebAppContext("./", "/app"); | |
webapp.addServlet(Servlet.class, "/services/*"); | |
Server server = new Server(8080); | |
server.setHandler(webapp); | |
server.start(); | |
server.join(); |
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
/// <reference path="jquery.d.ts" /> | |
class TestService{ | |
constructor(path: string){ | |
this.path = path; | |
} | |
public f(: number): number{ | |
return this.ajax("f", []); | |
} | |
private ajax(methodName: string, params: any[]): any{ | |
return $.ajax({ | |
type: "POST", url: this.path, | |
dataType: "json", data: JSON.stringify({ | |
method: methodName, | |
params: params | |
}) | |
}); | |
} | |
private path: string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TestService.ts will be generated when you access http://127.0.0.1:8080/app/services/TestService?ts after you launched the service.