Skip to content

Instantly share code, notes, and snippets.


Takao Nakaguchi takawitter

View GitHub Profile
takawitter /
Last active Aug 29, 2015
public Result execute(Input in) throws IllegalArgumentException{
assertNotNull(in, "In must not be null.");
Integer productId = in.getSelected();
assertNotNull(productId, "ProductId must not be null.");
assertInRange(productId, 1, 10, "ProductId must be in the range 1-10.");
Product product = dao.findById(productId);
assertNotNull(product, "Product doesn't exist.");
List<Integer> coins = in.getCoins();
takawitter / InvokeTranslation.js
Last active Aug 29, 2015
Codes to invoke Translation service on Language Grid.
View InvokeTranslation.js
Copyright 2015 Takao Nakaguchi.
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
Unless required by applicable law or agreed to in writing, software
takawitter / CallServiceManagementSearchServices.groovy
Created May 12, 2015
The script that call searchServices method of ServiceManagement service.
View CallServiceManagementSearchServices.groovy
import jp.go.nict.langrid.client.soap.SoapClientFactory;
new SoapClientFactory().create(
new URL(""),
takawitter / CallTranslation.groovy
Last active Feb 23, 2017
The script that call Translation service on Language Grid.
View CallTranslation.groovy
import jp.go.nict.langrid.client.soap.SoapClientFactory;
import jp.go.nict.langrid.service_1_2.translation.TranslationService;
println new SoapClientFactory().create(
new URL(""),
"yourpass").translate("en", "ja", "hello");
takawitter / axis14.patch
Created Jan 5, 2015
A patch let axis1.4 support Java8 code when generating wsdl.
View axis14.patch
### Eclipse Workspace Patch 1.0
#P axis-rt-core
Index: src/main/java/org/apache/axis/utils/bytecode/
--- src/main/java/org/apache/axis/utils/bytecode/ (revision 1649462)
+++ src/main/java/org/apache/axis/utils/bytecode/ (working copy)
@@ -59,6 +59,10 @@
private static final int CONSTANT_Double = 6;
private static final int CONSTANT_NameAndType = 12;
private static final int CONSTANT_Utf8 = 1;
takawitter / TestService.groovy
Last active Feb 12, 2016
The script which serve the service via JSON-RPC using Service Grid Service Container and Jetty.
View TestService.groovy
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);
import net.arnx.jsonic.JSON;
import org.jsonman.Node;
import org.jsonman.NodeFactory;
import org.jsonman.NodeFinder;
import org.jsonman.node.MapNode;
import org.junit.Assert;
import org.junit.Test;
public class NodeFinderTest{
import org.fluentd.logger.FluentLogger;
public class FluentLoggerTest {
public static class Log{
public Log(String name, String msg){ = name;
this.msg = msg;
public String getName() {
return name;
takawitter /
Created Jul 15, 2013 の続き。パラメータの型のマッチングにも対応してみた。 パラメータの型が一致するメソッドが見つかった場合はそれを、見つからない場合はパラメータの型の祖先を持つもの(f(Integer v)に対するf(Number v)とか)を検索して実行する。どちらの場合もIllegalAccessExceptionが発生した場合はインタフェースから同じメソッドを探して実行する。 但し、パラメータの型の祖先も対象にする場合は、複数のメソッドがマッチする可能性があり、その場合は例外を投げるべきかもしれないが、それを検出するにはメソッド全部調べる必要がありコストが高い。
public class MethodInvoker{
public static Object invoke(
Object instance, String methodName, Object... args)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
Class<?> clazz = instance.getClass();
Class<?>[] argTypes = new Class<?>[args.length];
for(int i = 0; i < args.length; i++){
argTypes[i] = args[i].getClass();
takawitter /
Last active Dec 19, 2015 の続き。こんな感じでメソッドを検索して、安全に実行できるものを見つけてやる。実際のケースではパラメータのマッチングが加わるから、より複雑なコードになるけど。あと、最初に見つかった(呼ぶとIllegalAccessExceptionになる)メソッドでも、setAccessible(true)してやるとたいてい呼べる。但し呼べるかどうかはSecurityManager次第なので、この方法の方が安全。
import java.lang.reflect.Method;
public class InvokeSafely{
public static Object invokeSafely(Object obj, String method) throws Throwable{
Class<?> c = obj.getClass();
Method m = c.getMethod(method);
return m.invoke(obj);
} catch(IllegalAccessException e){