[MOBY-l] Moby Client Example

Edward Kawas edward.kawas at gmail.com
Fri May 5 16:36:02 UTC 2006


Hi Carol,

I augmented one of our example clients available in moby-live/Java/src/Clients/

The following should be of some use:

/**	
 * This is the simplest Java MOBY client you can have.  A fully documented
version
 * is available in the TestRequest class, with all the proper error checking. 
 */

import org.biomoby.client.*;
import org.biomoby.shared.*;
import org.biomoby.shared.data.*;

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

        Central worker = new CentralImpl();
	  // replace with service name of your choice
        MobyService templateService = new MobyService("MOBYSHoundGetGenBankff");
        MobyService[] validServices = worker.findService(templateService);

	MobyRequest mr = new MobyRequest(worker);
	mr.setService(validServices[0]);
	mr.setInput(new MobyDataObject("NCBI_gi", "111076"));
	MobyContentInstance mobyContent = mr.invokeService();
	String response = mobyContent.toString();
	System.out.println("Response from service is:\n" + response);
	java.util.Iterator it = mobyContent.keySet().iterator();
	while (it.hasNext()) {
		Object o = mobyContent.get(it.next());
		System.out.println("result from calling get(key):\n" + o);
		System.out.println("classname: " + o.getClass());
		java.util.HashMap map = (java.util.HashMap)o;
		java.util.Iterator mobyContentIterator =
map.keySet().iterator();
		while (mobyContentIterator.hasNext()) {
			String key = (String)mobyContentIterator.next();
			System.out.println("key: " + key); // should be the
articlename, in this case is empty, but it shouldnt be in theory
			Object composite = map.get(key);
			System.out.println("value:\n" + composite);
			System.out.println("class: " + map.get(key).getClass());
			// map contains MobyDataComposite objects.
			// now get the members:
			java.util.Iterator compositeIterator =
((MobyDataComposite)composite).keySet().iterator();
			while (compositeIterator.hasNext()) {
				String compositeKey =
(String)compositeIterator.next();
				System.out.println("key: " + compositeKey); //
should be the articlename, in this case is empty, but it shouldnt be
				System.out.println("value:\n" +
((MobyDataComposite)composite).get(compositeKey));
				System.out.println("class: " +
((MobyDataComposite)composite).get(compositeKey).getClass());

			}
		}
	}
    }
}

Eddie 

> -----Original Message-----
> From: moby-l-bounces at lists.open-bio.org 
> [mailto:moby-l-bounces at lists.open-bio.org] On Behalf Of Carol 
> Lushbough
> Sent: Friday, May 05, 2006 6:22 AM
> To: moby-l at biomoby.org
> Subject: [MOBY-l] Moby Client Example
> 
> All,
> 
> I was wondering if someone could send me an example 
> demonstrating how a java client app retrieves output after 
> invoking a BioMoby service.  I'm trying to test a service 
> that returns a collection of BasicGFFSequenceFeature. The 
> following code segments are my attempts at retrieving the collection:
> 
>                 // First try
>            mr.invokeService();
>            MobyContentInstance output = mr.getOutput();
>            BasicGFFSequenceFeature[] values =
> (BasicGFFSequenceFeature[]) output.get("locations");
> 
>           // second try
>             MobyContentInstance responses = mr.invokeService();
> 
>         Iterator i = responses.keySet().iterator();
>         while(i.hasNext()){
>                 HashMap responseObjects = (HashMap) 
> responses.get(i.next());
>                  Iterator it = responseObjects.keySet().iterator();
>                  while(it.hasNext()){
>                     Object responseObject = it.next();
>                     // The response objects may either be 
> simple data, or data sets
>             if(responseObject instanceof MobyDataObject){
>             System.out.println("Plain simple instance is 
> "+((MobyDataInstance)responseObject).toXML());
>             }
>             else if(responseObject instanceof MobyDataObjectSet){
>             System.out.println("Found a collection:");
>             MobyDataObject[] simples = ((MobyDataObjectSet) 
> responseObject).getElementInstances();
>             for(int j = 0; j < simples.length; j++){
>                 System.out.println("  Member instance is 
> \n"+simples[j].toXML());
>             }
>             }
>             else{
>             System.out.println("Found funky data!" + 
> responseObject.toString());
>             }
>         }
>         }
> 
> Thank you for you help!
> 
> Carol
> 
> --
> Carol Lushbough
> Assistant Professor of Computer Science
> University of South Dakota
> Vermillion, SD 57069
> (605) 677-6138
> 
> _______________________________________________
> moby-l mailing list
> moby-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/moby-l




More information about the moby-l mailing list