Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SOAP Service and Client using language grid libraries and Groovy.
@Grab('org.eclipse.jetty:jetty-webapp:9.4.0.v20161208')
@Grab('org.langrid:jp.go.nict.langrid.service.language_1_2:1.0.10')
@Grab('org.langrid:jp.go.nict.langrid.servicecontainer.handler.axis:1.0.10')
import jp.go.nict.langrid.service_1_2.translation.TranslationService;
import jp.go.nict.langrid.servicecontainer.handler.annotation.Service;
import jp.go.nict.langrid.servicecontainer.handler.axis.SGAxisServlet;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class TestServiceImpl implements TranslationService{
public String translate(String sourceLang, String targetLang, String source){
return sourceLang + ":" + targetLang + ":" + source;
}
}
@Service(name="TestService", impl=TestServiceImpl.class, intf=TranslationService.class)
public class Servlet extends SGAxisServlet{}
WebAppContext webapp = new WebAppContext("./", "/app");
webapp.addServlet(Servlet.class, "/services/*");
Server server = new Server(8080);
server.setHandler(webapp);
server.start();
server.join();
@Grab('org.langrid:jp.go.nict.langrid.client.soap:1.0.10')
@Grab('org.langrid:jp.go.nict.langrid.service.language_1_2:1.0.10')
@Grab('org.langrid:jp.go.nict.langrid.servicecontainer.handler.axis:1.0.10')
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://127.0.0.1:8080/app/services/TestService")
).translate('en','ja','hello');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment