Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "XDI4j Tutorial 4"

 
Line 36: Line 36:
 
// we create an HTTP client that can talk to one of our endpoints
 
// we create an HTTP client that can talk to one of our endpoints
  
XDIClient client = new XDIHttpClient("http://graceland.parityinc.net/xdi-endpoint/hibernate-graph-ver");
+
XDIClient client = new XDIHttpClient("http://graceland.parityinc.net/xdi-endpoint/mem-graph-ver");
  
 
// let's say we want to know =drummond's synonyms
 
// let's say we want to know =drummond's synonyms

Latest revision as of 11:50, 1 September 2009

{{#eclipseproject:technology.higgins|eclipse_custom_style.css}}

Higgins logo 76Wx100H.jpg

Example

This example app shows how to send XDI messages to an endpoint and how to view results.

package org.eclipse.higgins.xdi4j.tutorial;

import java.util.Iterator;

import org.eclipse.higgins.xdi4j.Graph;
import org.eclipse.higgins.xdi4j.Reference;
import org.eclipse.higgins.xdi4j.io.XDIWriter;
import org.eclipse.higgins.xdi4j.io.XDIWriterRegistry;
import org.eclipse.higgins.xdi4j.messaging.Message;
import org.eclipse.higgins.xdi4j.messaging.MessageEnvelope;
import org.eclipse.higgins.xdi4j.messaging.MessageResult;
import org.eclipse.higgins.xdi4j.messaging.Operation;
import org.eclipse.higgins.xdi4j.messaging.client.XDIClient;
import org.eclipse.higgins.xdi4j.messaging.client.http.XDIHttpClient;
import org.eclipse.higgins.xdi4j.xri3.impl.XRI3Segment;

/**
 * This example app shows how to send XDI messages to
 * an endpoint and how to view results.
 * 
 * @author msabadello at parityinc dot not
 *
 */
public class Tutorial4 {

	public static void main(String[] args) throws Exception {

		// we create an HTTP client that can talk to one of our endpoints

		XDIClient client = new XDIHttpClient("http://graceland.parityinc.net/xdi-endpoint/mem-graph-ver");

		// let's say we want to know =drummond's synonyms

		// we create a message envelope and a message with a message sender

		MessageEnvelope envelope = MessageEnvelope.newInstance();
		Message message = envelope.newMessage(new XRI3Segment("=markus"));

		// create a $get operation in the message

		Operation operation = message.createGetOperation();

		// create a statement in the operation to ask for =drummond's synonyms

		Graph operationGraph = operation.createOperationGraph(null);

		operationGraph.createStatement(new XRI3Segment("=drummond"), new XRI3Segment("$is"));

		// let's output the message for debug purposes before we send it

		XDIWriter writer = XDIWriterRegistry.forFormat("X3 Simple");
		writer.write(envelope.getGraph(), System.out, null);

		// send the message

		MessageResult result = client.send(envelope, null);

		// output the results

		for (Iterator<Reference> references = result.getGraph().getReferences(); references.hasNext(); ) {

			Reference reference = references.next();

			System.out.println("Synonym: " + reference.getReferenceXri());
		}
	}
}

Copyright © Eclipse Foundation, Inc. All Rights Reserved.