Skip to content

Instantly share code, notes, and snippets.

View takawitter's full-sized avatar

Takao Nakaguchi takawitter

View GitHub Profile
@takawitter
takawitter / TestService.groovy
Last active February 12, 2016 08:45
The script which serve the service via JSON-RPC using Service Grid Service Container and Jetty.
@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);
}
@takawitter
takawitter / axis14.patch
Created January 5, 2015 06:20
A patch let axis1.4 support Java8 code when generating wsdl.
### Eclipse Workspace Patch 1.0
#P axis-rt-core
Index: src/main/java/org/apache/axis/utils/bytecode/ClassReader.java
===================================================================
--- src/main/java/org/apache/axis/utils/bytecode/ClassReader.java (revision 1649462)
+++ src/main/java/org/apache/axis/utils/bytecode/ClassReader.java (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
takawitter / CallTranslation.groovy
Last active February 23, 2017 23:02
The script that call Translation service on Language Grid.
@Grab('org.langrid:jp.go.nict.langrid.client.soap:1.0.8')
@Grab('org.langrid:jp.go.nict.langrid.service.language_1_2:1.0.8')
import jp.go.nict.langrid.client.soap.SoapClientFactory;
import jp.go.nict.langrid.service_1_2.translation.TranslationService;
println new SoapClientFactory().create(
TranslationService.class,
new URL("http://langrid.org/service_manager/invoker/TranslationServiceId"),
"yourid",
"yourpass").translate("en", "ja", "hello");
@takawitter
takawitter / CallServiceManagementSearchServices.groovy
Created May 12, 2015 19:09
The script that call searchServices method of ServiceManagement service.
@Grab('net.servicegrid:jp.go.nict.langrid.client.soap:1.0.5')
@Grab('net.servicegrid:jp.go.nict.langrid.service.management_1_2:1.0.5')
import jp.go.nict.langrid.client.soap.SoapClientFactory;
import jp.go.nict.langrid.service_1_2.foundation.MatchingCondition;
import jp.go.nict.langrid.service_1_2.foundation.Order;
import jp.go.nict.langrid.service_1_2.foundation.servicemanagement.ServiceManagementService;
new SoapClientFactory().create(
ServiceManagementService.class,
new URL("http://langrid.org/service_manager/services/ServiceManagement"),
@takawitter
takawitter / InvokeTranslation.js
Last active August 29, 2015 14:21
Codes to invoke Translation service on Language Grid.
/*
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@takawitter
takawitter / Sample.java
Last active August 29, 2015 14:22
書いてみた。executeメソッドのみ。元ネタ: http://bufferings.hatenablog.com/entry/2015/06/03/082323
public Result execute(Input in) throws IllegalArgumentException{
assertNotNull(in, "In must not be null.");
try{
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
takawitter / HtmlEncoderTest.java
Last active August 29, 2015 14:23
ちゃんと5回呼ばれるやつ(シングルクオートをバッククオートに修正)
import java.util.HashMap;
import java.util.Map;
public class HtmlEncoderTest {
static public void main(String[] args) {
System.out.println(new HtmlEncoder().encode("<script>alert('注意!');</script>"));
System.out.println(HtmlEncoder.count);
}
}
@takawitter
takawitter / EventListenerList.java
Created July 24, 2015 17:26
Typed and easily to fire event, EventListenerList
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.EventListener;
public class EventListenerList<T extends EventListener> extends javax.swing.event.EventListenerList{
public EventListenerList(Class<T> clazz){
this.clazz = clazz;
this.fireProxy = clazz.cast(Proxy.newProxyInstance(
Thread.currentThread().getContextClassLoader(),
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
public class JSONObjectExample {
@Test
public void java_json_literal() throws Throwable{
@takawitter
takawitter / LimitClassReferenceWhenDeserializingObject.java
Last active November 11, 2015 02:51
Limit class reference when deserializing object by using custom class loader.
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Paths;
import java.util.HashMap;