perfsonar-dev - Res: Res: LS GUI
Subject: perfsonar development work
List archive
- From: Herbert Souza <>
- To: Maciej Glowiak <>
- Cc: Perfsonar Development List <>
- Subject: Res: Res: LS GUI
- Date: Wed, 14 Feb 2007 10:21:30 -0800 (PST)
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.br; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Message-ID; b=rO5Y/F8sh2I4/7D47R5fZ8bvu6VtzfvxGmpKKdOlZ0urtjNB1gZwZkqC86IUNX6XmRERTn2Ls4SxBIYKm7l7qzbarlJn6P6lKlC5g5vdZBN8rSvwUZyocjNNTV2GZcSY+WZbKexkGdkuzOcHIb1gl5VKDuF3dgnqgPup6fflPbM=;
Maciej,
I re-wrote the class "LSQueryRequestGenerator.java" using NMWG classes. I did
this because i want to make possible for the ICE (GUI) the access the LS. I
also did a class called "Proxy.java", to ease the access. In the attachments
you can find the two classes and other class like example.
Regards.
-------------------------------
Herbert Monteiro Souza
Cel Phone: +5571 88029549
Phone: +5571 33304658
-------------------------------
UNIFACS - UNIVERSIDADE SALVADOR
-------------------------------
NUPERC - NÚCLEO DE PESQUISA EM
REDES DE COMPUTADORES
-------------------------------
----- Mensagem original ----
De: Maciej Glowiak
<>
Para: Herbert Souza
<>
Cc: Perfsonar Development List
<>
Enviadas: Quarta-feira, 24 de Janeiro de 2007 9:53:17
Assunto: Re: Res: LS GUI
Herbert,
As I wrote before: in general there are two ways of generating message
1) by DOM Document (jDOM, Xerces, DOM4j, etc)
2) by NMWG classes
API for Query (such as LSQueryRequestGenerator.java) was using 1), but I
gave it up. This API is now not up to date, but I didn't have time to
re-write it with NMWG classes usage. That wasn't so urgent, because
nobody used it.
API for Registration uses 2) and, in my opinion, this should be used
also for generating other requests.
The namespace in NMWG classes can't be set manually (like in DOM
Document). The namespaces are hidden behind packages. Let me explain in
example (please focus on import clauses):
----------------------------------------------------------
org.ggf.ns.nmwg.base.v2_0.Subject
class is <nmwg:subject> tag
----------------------------------------------------------
and
----------------------------------------------------------
org.ggf.ns.nmwg.characteristic.utilization.v2_0.Subject
class is <utilization:subject> tag
----------------------------------------------------------
namespace prefixes are set in class constructors.
Regarding your second e-mail, I am not sure where the problem is:
> The Query LS explain is about of the Query Message, because I am not seeing
> in Query Message the xQuery expression like in old messages.
>
> <xquery:subject id="sub1">
> declare namespace nmwg="http://ggf.org/ns/nmwg/base/2.0/";;
> declare namespace
> perfsonar="http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/";;
> declare namespace
> psservice="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/";;
> declare namespace
> xquery="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/";;
>
>
> /nmwg:store/nmwg:metadata
> </xquery:subject>
That's XQuery expression inside <xquery:subject> element, and:
> <nmwg:eventType>service.lookup.xquery</nmwg:eventType>
that's query type inside <nmwg:eventType>.
Maciej
--
--------------------------------------------------------------------
| Maciej Glowiak Network Research and Development ||
|
Poznan Supercomputing and Networking Center ||
| (+48 61) 858 2024 http://monstera.man.poznan.pl/ ||
====================================================================
__________________________________________________
Fale com seus amigos de graça com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/
/* * Created on 2005-09-28 * */ package org.perfsonar.client.commons.requests.lookupService; import org.ggf.ns.nmwg.base.v2_0.Data; import org.ggf.ns.nmwg.base.v2_0.Element; import org.ggf.ns.nmwg.base.v2_0.EventType; import org.ggf.ns.nmwg.base.v2_0.Message; import org.ggf.ns.nmwg.tools.org.perfsonar.service.lookup.xquery.v1_0.Subject; import org.perfsonar.service.commons.exceptions.SystemException; import org.ggf.ns.nmwg.base.v2_0.Metadata; /** * @author Maciej Glowiak * * This class can generate simple LSQueryRequest as a DOM document (org.w3c.dom) * The only parameter you must set is "query" * * It can be set by constructor: * * new LSQueryRequestGenerator("xquery expression"); * or: * setParameter(QUERY, "xquery expression"); * or: * setQuery("xquery expression"); * * Optional parameter is QUERY_TYPE: * * It can be set by constructor: * * new LSQueryRequestGenerator("xquery expression", * "service.lookup.xquery"); * or: * setParameter(QUERY_TYPE, "service.lookup.xquery"); * or: * setQueryType("service.lookup.xquery"); * */ public class LSQueryRequestGenerator {// extends RequestGeneratorImpl { // ------------------------------------------------------------- Constants /** * Default query type to LS (characteristic element) */ private static final String DEFAULT_QUERY_TYPE = "service.lookup.xquery"; /** * Parameter that contains query type (characteristic) */ private String QUERY_TYPE = "queryType"; /** * Parameter that contains query (subject) */ private String QUERY = "query"; // ------------------------------------------------------------ Static code /** * Sets query and query type */ public LSQueryRequestGenerator(String query, String queryType) { super(); setQuery(query); setQueryType(queryType); } /** * Sets query. Query type is set to default - see: DEFAULT_QUERY_TYPE * @param query */ public LSQueryRequestGenerator(String query) { super(); setQuery(query); setQueryType(DEFAULT_QUERY_TYPE); } // --------------------------------------------------------- Public methods public Message generateRequest() throws SystemException { System.out.println("LSQueryRequestGenerator: generateRequest"); //message Message message = new Message(); message.setId("anId"); message.setType("LSQueryRequest"); //metadata Metadata metadata = new Metadata(); metadata.setPrefix("perfsonar"); metadata.setId("meta-1"); //data Data data = new Data(); data.setMetadataIdRef("meta-1"); message.setData(data); //subject Subject subject = new Subject(); subject.setPrefix("xquery"); subject.setId("id"); subject.setSubject(getQuery()); //event type EventType eventType = new EventType(); eventType.setEventType(getQueryType()); //set final parameters metadata.setSubject(subject); metadata.setEventType(eventType); message.setMetadata(metadata); //return message return message; } /** * Set query for LSQueryRequest * Can be set by: * setParameter(QUERY, query); * @param query */ public void setQuery(String query) { this.QUERY = query; } /** * Set query and type of query for LSQueryRequest. * Can be set by: * setParameter(QUERY, query); * setParameter(QUERY_TYPE, queryType); * @param query * @param queryType */ public void setQuery(String query, String queryType) { this.QUERY = query; this.QUERY_TYPE = queryType; } /** * Return query * @return */ public String getQuery() { return QUERY; } /** * Set query type for LSQueryRequest * Can be set by: * setParameter(QUERY_TYPE, queryType); */ public void setQueryType(String queryType) { this.QUERY_TYPE = queryType; } /** * Return query type * @return */ public String getQueryType() { return QUERY_TYPE; } /* // -------------- TEST --------------------------------------------------- public static void main(String[] args) throws SystemException { LSQueryRequestGenerator request = new LSQueryRequestGenerator("Q U E R Y"); Document doc = request.generateRequest(); System.out.println(serializeDocument(doc)); } */ } //LSQueryRequestGenerator
package org.perfsonar.client.commons.lookupServiceProxy; import java.io.IOException; import java.net.URL; import org.jdom.input.DOMBuilder; //import org.jdom.output.Format; import java.util.Map; import java.util.Vector; import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.message.SOAPBodyElement; import org.ggf.ns.nmwg.base.v2_0.Data; import org.ggf.ns.nmwg.base.v2_0.Datum; import org.ggf.ns.nmwg.base.v2_0.Message; import org.jdom.Element; import org.jdom.output.Format; import org.jdom.output.XMLOutputter; import org.perfsonar.client.commons.requests.lookupService.LSQueryRequestGenerator; import org.perfsonar.client.commons.requests.lookupService.LSRegisterRequestGenerator; import org.perfsonar.commons.auxiliary.AuxiliaryComponentManager; import org.perfsonar.commons.auxiliary.ComponentNames; import org.perfsonar.commons.auxiliary.components.configuration.ConfigurationComponent; import org.perfsonar.commons.util.XMLUtils; import org.perfsonar.service.commons.exceptions.SystemException; import org.w3c.dom.Document; public class proxy { // --------------------------------------------------------- Public methods /** * Creates NMWG Message that contains particular request * @return NMWG Message containing Request * * @throws SystemException */ public String LSRegister(String accessPoint, Map commomParameter, String[] metadataElements ) throws SystemException{ String result = null; try{ LSRegisterRequestGenerator register = new LSRegisterRequestGenerator(); register.setCommonParameters(commomParameter); register.setMetadataElements(metadataElements); System.out.println("1"); Service service = new Service(); Call call = (Call)service.createCall(); call.setTargetEndpointAddress(new URL(accessPoint)); call.setOperationName(new QName("http://soapinterop.org/","submit")); System.out.println("2"); Message Mem = register.generateRequestMessage(); System.out.println("3"); //convert response Message into Document Document responseDocument = XMLUtils. convertMessageToDOM( Mem ); //build a SOAPBodyElement from the document printXML(responseDocument); SOAPBodyElement requestMessage = new SOAPBodyElement(responseDocument.getDocumentElement()); // call on the end point Object resultObject = call.invoke(new Object[] {requestMessage}); // get the document SOAPBodyElement resultSBE; resultSBE = (SOAPBodyElement)((Vector)resultObject).get(0); //set result Document doc = resultSBE.getAsDocument(); printXML(doc); String parserFile = ((ConfigurationComponent) AuxiliaryComponentManager.getInstance(). getComponent(ComponentNames.CONFIG)). getProperty("service.sax_parser.config"); Message resultMessage = null; resultMessage = XMLUtils.convertToMessage( doc, parserFile); Data[] datas = resultMessage.getDataArray(); Data data = datas[0]; Vector datums = data.getDatum(); Datum datum = (Datum)datums.get(0); result = datum.getValue(); }catch(Exception e) { System.out.println("Proxy " +e); } return result; } public Document LSQuery(String accessPoint, String Query, String queryType ) throws SystemException{ Document result = null; try{ LSQueryRequestGenerator queryRequest = new LSQueryRequestGenerator(Query,queryType); Service service = new Service(); Call call = (Call)service.createCall(); call.setTargetEndpointAddress(new URL(accessPoint)); call.setOperationName(new QName("http://soapinterop.org/","submit")); Message Mem = queryRequest.generateRequest(); //convert response Message into Document Document responseDocument = XMLUtils. convertMessageToDOM( Mem ); //build a SOAPBodyElement from the document //printXML(responseDocument); SOAPBodyElement requestMessage = new SOAPBodyElement(responseDocument.getDocumentElement()); //call on the end point Object resultObject = call.invoke(new Object[] {requestMessage}); //get the document SOAPBodyElement resultSBE; resultSBE = (SOAPBodyElement)((Vector)resultObject).get(0); //set result result = resultSBE.getAsDocument(); printXML(result); }catch(Exception e) { System.out.println("Proxy " +e); } return result; } public Document find_psservice(String accessPoint, String psservice, String parameter) throws SystemException{ Document result = null; try{ String query = "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n"+ "declare namespace perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\";\n"+ "declare namespace psservice=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/\";\n"+ "declare namespace xquery=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/\";\n"+ "for $x in /nmwg:store/nmwg:metadata/perfsonar:subject/psservice:service\n"+ "where contains($x/psservice:"+psservice+", \""+parameter+"\")\n"+ "return $x\n"; LSQueryRequestGenerator queryRequest = new LSQueryRequestGenerator(query,"service.lookup.xquery"); Service service = new Service(); Call call = (Call)service.createCall(); call.setTargetEndpointAddress(new URL(accessPoint)); call.setOperationName(new QName("http://soapinterop.org/","submit")); Message Mem = queryRequest.generateRequest(); //convert response Message into Document Document responseDocument = XMLUtils. convertMessageToDOM( Mem ); //build a SOAPBodyElement from the document //printXML(responseDocument); SOAPBodyElement requestMessage = new SOAPBodyElement(responseDocument.getDocumentElement()); //call on the end point Object resultObject = call.invoke(new Object[] {requestMessage}); //get the document SOAPBodyElement resultSBE; resultSBE = (SOAPBodyElement)((Vector)resultObject).get(0); //set result result = resultSBE.getAsDocument(); printXML(result); }catch(Exception e) { System.out.println("Proxy " +e); } return result; } /** * Print a XML Tree based on the root element * @param el */ public void printXML(Element el) { try { XMLOutputter serializer = new XMLOutputter(); serializer.setFormat(Format.getPrettyFormat()); //serializer.outputString(doc); //serializer.output(doc, new FileWriter(new File("arquivo.txt"))); serializer.output(el, System.out); } catch (IOException e) { System.err.println(e); } } /** * Print a XML Tree based on the document object * @param doc */ public void printXML(org.w3c.dom.Document doc) { try { //StringWriter sw = new StringWriter(); DOMBuilder factory1 = new DOMBuilder(); org.jdom.Document domResult = factory1.build(doc); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(domResult,System.out); //sw.close(); } catch (IOException e) { System.err.println(e); } } }
//import java.net.URL; import java.util.HashMap; import java.util.Map; //import javax.xml.namespace.QName; //import org.apache.axis.client.Call; //import org.apache.axis.client.Service; //import org.apache.axis.message.SOAPBodyElement; //import org.ggf.ns.nmwg.base.v2_0.Message; //import org.perfsonar.client.commons.requests.lookupService.LSRegisterRequestGenerator; //import org.perfsonar.client.testHarness.SOAPClient; //import org.perfsonar.commons.util.XMLUtils; //import org.w3c.dom.Document; import org.perfsonar.client.commons.lookupServiceProxy.proxy; public class teste { public Map <String, String> commonParameters = new HashMap(); public void makeRequest(String[] args) { proxy LSProxy = new proxy(); System.out.println("Entrou"); String[] metadataElements = new String[1]; try{ //Map commomParameter = new Map<String, Integer>; //String[] metadataElements; commonParameters.put("access_point", "http://teste.com.br"); commonParameters.put("service_name", "teste"); commonParameters.put("service_type", "tipo teste"); commonParameters.put("service_description", "descri"); metadataElements[0] = "<nmwg:metadata id=\"meta1\">"+ "<perfsonar:subject id=\"subj1\" xmlns:perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\">"+ "<nmwgt:interface xmlns:nmwgt=\"http://ggf.org/ns/nmwg/topology/2.0/\">"+ "<nmwgt:hostName>atlang-hstnng.abilene.ucaid.edu</nmwgt:hostName>"+ "<nmwgt:ifName>unknown</nmwgt:ifName>"+ "<nmwgt:ifDescription>hstn:oc192(p2p)::show:intracloud</nmwgt:ifDescription>"+ "<nmwgt:ifAddress type=\"ipv4\">198.32.8.34</nmwgt:ifAddress>"+ "<nmwgt:direction>in</nmwgt:direction>"+ "<nmwgt:capacity>10000000000</nmwgt:capacity>"+ "</nmwgt:interface>"+ "</perfsonar:subject>"+ "<nmwg:eventType>utilization</nmwg:eventType>"+ "</nmwg:metadata>"; System.out.println("Antes"); /*String query = "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n"+ "declare namespace perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\";\n"+ "declare namespace psservice=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/\";\n"+ "declare namespace xquery=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/\";\n"+ "for $x in /nmwg:store/nmwg:metadata/perfsonar:subject/psservice:service\n"+ "where $x/psservice:serviceType=\"MA\"\n"+ "return $x\n"; */ queryForm que = new queryForm(); que.setVisible(true); String query = "declare namespace nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n"+ "declare namespace perfsonar=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/1.0/\";\n"+ "declare namespace psservice=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/1.0/\";\n"+ "declare namespace xquery=\"http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/\";\n"+ "for $x in /nmwg:store/nmwg:metadata/perfsonar:subject/psservice:service\n"+ "where contains($x/psservice:serviceType, \"MP\")\n"+ "return $x\n"; LSProxy.LSQuery("http://200.128.80.172:8080/axis/services/LookupService", query, "service.lookup.xquery"); //LSProxy.LSRegister("http://200.128.80.172:8080/axis/services/LookupService", commonParameters, metadataElements); //LSProxy.find_psservice("http://200.128.80.172:8080/axis/services/LookupService", "accessPoint", "http://localhost:8080/perfSONAR-SQL-MA-1.0-RC1-RNP_testing/services/MeasurementArchiveService"); System.out.println("Passou"); }catch(Exception e) { System.out.println(e); } } public static void main(String[] args) { teste doclitClient = new teste(); doclitClient.makeRequest(args); } }
- Res: Res: LS GUI, Herbert Souza, 02/14/2007
Archive powered by MHonArc 2.6.16.