参考:
先のPOST
Build Path周り:
を,含むプロジェクト全体の図.
- それぞれのjarは,先のPOSTを実行しているのであれば,$HOME/.m2/repositoryの下に入っています.
- 面倒なら先のプロジェクトに居候してしまえばパスは通っているので簡単かもしれません.
- コードをパッと見るとsadi-clientとjenaがあればよさそうですが,依存関係の都合で色々いれなくてはなりませんでした.
("slf4j-api-*.jar"だけでなく, "slf4j-log4j12-*.jar"が必要な場合もあるようです)
コード(Client.java):
package sample; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import ca.wilkinsonlab.sadi.SADIException; import ca.wilkinsonlab.sadi.client.ServiceImpl; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; public class Client { public static void main(String[] args) throws SADIException, IOException { Model inputModel = ModelFactory.createDefaultModel(); if (true) { Resource type = ResourceFactory .createResource("http://sadiframework.org/examples/hello.owl#NamedIndividual"); Resource s = inputModel .createResource( "http://sadiframework.org/examples/hello-input.rdf#1", type); s.addProperty( inputModel.createProperty("http://xmlns.com/foaf/0.1/name"), "Guy Incognito"); } else { inputModel.read(new FileInputStream(new File("./hello-input.rdf")), "", "RDF/XML"); } inputModel.write(System.out, "RDF/XML"); String serviceURI = "http://localhost:8080/sadi-services/hello"; ServiceImpl service = new ServiceImpl(serviceURI); Model outputModel = service.invokeServiceUnparsed(inputModel); outputModel.write(System.out, "RDF/XML"); } }
結果:
当たり前だけど, service側が動いている前提です.
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://xmlns.com/foaf/0.1/" xmlns:j.1="http://sadiframework.org/examples/hello.owl#" > <rdf:Description rdf:about="http://sadiframework.org/examples/hello-input.rdf#1"> <j.0:name>Guy Incognito</j.0:name> <rdf:type rdf:resource="http://sadiframework.org/examples/hello.owl#NamedIndividual"/> </rdf:Description> </rdf:RDF> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:j.0="http://sadiframework.org/examples/hello.owl#" > <rdf:Description rdf:about="http://sadiframework.org/examples/hello-input.rdf#1"> <j.0:greeting>Hello, Guy Incognito!</j.0:greeting> <rdf:type rdf:resource="http://sadiframework.org/examples/hello.owl#GreetedIndividual"/> </rdf:Description> </rdf:RDF>
































