[MOBY-guts] biomoby commit

Eddie Kawas kawas at pub.open-bio.org
Mon Jun 13 18:14:36 UTC 2005


kawas
Mon Jun 13 14:14:35 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/rdfagent/verifier
In directory pub.open-bio.org:/tmp/cvs-serv26234/org/biomoby/registry/rdfagent/verifier

Modified Files:
	Communicator.java 
Log Message:
Fixed a bug that crashed the agent when an RDF document retrieved from an author contained invalid xml. Eddie

moby-live/Java/src/main/org/biomoby/registry/rdfagent/verifier Communicator.java,1.4,1.5
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/rdfagent/verifier/Communicator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/rdfagent/verifier/Communicator.java	2005/04/16 14:32:12	1.4
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/registry/rdfagent/verifier/Communicator.java	2005/06/13 18:14:35	1.5
@@ -1,4 +1,3 @@
-
 package org.biomoby.registry.rdfagent.verifier;
 
 import java.io.BufferedReader;
@@ -25,223 +24,260 @@
 import com.hp.hpl.jena.rdf.model.Model;
 import com.hp.hpl.jena.rdf.model.ModelFactory;
 import com.hp.hpl.jena.rdf.model.RDFException;
+import com.hp.hpl.jena.shared.JenaException;
+
 /**
  * @author Nina Opushneva
- *
- * The Communicator class  allows a Java application to communicate with 
- * servers of service providers by HTTP protocol, and with SMTP server by message
+ * 
+ * The Communicator class allows a Java application to communicate with servers
+ * of service providers by HTTP protocol, and with SMTP server by message
  */
 public class Communicator {
 
-/** get RDF model of service by  signatureURL
-    * (make HTTP connect to server, open a file,read a file into a streem, build the model)
-	* @param signURL - the URL of resource (signatureURL)
-	* @param servNames - set of service names located at this signatureURL
-	* @return Model the RDF model of services located at this signatureURL
-	*/
-	
-	public static Model getServiceRDF(String servNames,String signURL){
-		
-		 Model model = ModelFactory.createDefaultModel();
-         String mes1 = "";
-        try {
-             URL u = new URL(signURL);
-          
-             HttpURLConnection huc = (HttpURLConnection) u.openConnection();
-             huc.connect();
-            
-             int code = huc.getResponseCode();
-             Log.info("GET   <"+signURL+" >  - HTTP CODE: "+ code);
-			 Report.doWrite("");
-             Report.doWrite("GET SIGNATURE_URL  <"+signURL+" >  - HTTP CODE: "+ code);
-			 Report.add("GET SIGNATURE_URL  <"+signURL+" >  - HTTP CODE: "+ code);
-            
-             if (code == 200 || code == 202 ) { 
-
-             	try{             		
-					model.read(huc.getInputStream(),"");         	
-             	}catch(RDFException e){
-            		Log.severe("Failed : "+e);
-            		Report.add("Error 1: "+e);
-//                    e.getMessage();	
-             	}catch(IOException e){
-				  Log.severe("Failed : "+e);
-				  Report.add("Error 3: "+e);
-//				  e.getMessage();	
-			}
-                                
-             }
-             else {
-				if (code == 400){
-				  Log.warning("The request had bad syntax or was inherently impossible to be satisfied.");
-				  Report.add("The request had bad syntax or was inherently impossible to be satisfied.");
-				}
-				else if (code == 401){
-					Log.warning("The parameter to this message gives a specification of authorization schemes which are acceptable.");
-					Report.add("The parameter to this message gives a specification of authorization schemes which are acceptable.");
-				}
-				else if (code == 402){
-					Report.add("The parameter to this message gives a specification of charging schemes acceptable.");
-				}
-				else if (code == 403){
-					Report.add("The request is for something forbidden. Authorization will not help.");
-                    mes1 = "The request is for something forbidden.";
-				}
-				else if (code == 404){
-					Report.doWrite("The server has not found anything matching the URI given");
-					Report.add("The server has not found anything matching the URI given");
-                     mes1 = "The RDF file was not found on the server";
+	/**
+	 * get RDF model of service by signatureURL (make HTTP connect to server,
+	 * open a file,read a file into a streem, build the model)
+	 * 
+	 * @param signURL -
+	 *            the URL of resource (signatureURL)
+	 * @param servNames -
+	 *            set of service names located at this signatureURL
+	 * @return Model the RDF model of services located at this signatureURL
+	 */
+
+	public static Model getServiceRDF(String servNames, String signURL) {
+
+		Model model = ModelFactory.createDefaultModel();
+		String mes1 = "";
+		try {
+			URL u = new URL(signURL);
+
+			HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+			huc.connect();
+
+			int code = huc.getResponseCode();
+			Log.info("GET   <" + signURL + " >  - HTTP CODE: " + code);
+			Report.doWrite("");
+			Report.doWrite("GET SIGNATURE_URL  <" + signURL
+					+ " >  - HTTP CODE: " + code);
+			Report.add("GET SIGNATURE_URL  <" + signURL + " >  - HTTP CODE: "
+					+ code);
+			if (code == 200 || code == 202) {
+
+				try {
+					model.read(huc.getInputStream(), "");
+				} catch (RDFException e) {
+					Log.severe("Failed : " + e);
+					Report.add("Error 1: " + e);
+					
+
+					//                    e.getMessage();
+				} catch (JenaException e) {
+					//reset code to
+					code = 417;
 				}
-				else if (code == 500){
+				//http://www.w3.org/RDF/Validator/RDF/Validator/ARPServlet?URI=
+			}
+			
+			//////////////////////////
+			// no else if here purposely, because i reset the code if an
+			// exception is thrown due to invalid rdfs being returned.
+			//////////////////////////
+			if (code != 200 && code != 202)
+				if (code == 400) {
+					Log
+							.warning("The request had bad syntax or was inherently impossible to be satisfied.");
+					Report
+							.add("The request had bad syntax or was inherently impossible to be satisfied.");
+				} else if (code == 401) {
+					Log
+							.warning("The parameter to this message gives a specification of authorization schemes which are acceptable.");
+					Report
+							.add("The parameter to this message gives a specification of authorization schemes which are acceptable.");
+				} else if (code == 402) {
+					Report
+							.add("The parameter to this message gives a specification of charging schemes acceptable.");
+				} else if (code == 403) {
+					Report
+							.add("The request is for something forbidden. Authorization will not help.");
+					mes1 = "The request is for something forbidden.";
+				} else if (code == 404) {
+					Report
+							.doWrite("The server has not found anything matching the URI given");
+					Report
+							.add("The server has not found anything matching the URI given");
+					mes1 = "The RDF file was not found on the server";
+				} else if (code == 417) {
+					Report.add(" RDF Parsing error. Possible reason being that multiple <rdf:RDF> tags found in the same file.");
+					mes1 = " RDF Parsing error. Multiple <rdf:RDF> tags found.";
+				} else if (code == 500) {
 					Report.add(" Internal Error");
-                    mes1 = " Internal Error";
+					mes1 = " Internal Error";
+				}
+			int num = DataMngr.getServErrorNum(signURL, code);
+
+			if (num > 0) {
+				if (num < 3) {
+					DataMngr.updErrCount(signURL, code);
+				} else {
+
+					String servList = DataMngr.getServListByURL(signURL);
+					String s[] = servList.split(",");
+					Report.add("THE CONNECT TO   < " + signURL
+							+ " >  WAS REFUSED WITH HTTP CODE " + code
+							+ " THREE TIMES IN ROW. ");
+					Report
+							.add("THE SERVICES LOCATED AT  < "
+									+ signURL
+									+ " >  WILL BE DEREGISTERED FROM mobycentral REGISTRY.");
+					String m1 = "THE CONNECT TO   < " + signURL
+							+ " >  WAS REFUSED WITH HTTP CODE " + code
+							+ " THREE TIMES IN ROW. ";
+					String m2 = "THE SERVICES LOCATED AT  < "
+							+ signURL
+							+ " >  WILL BE DEREGISTERED FROM mobycentral REGISTRY.";
+					String msg = m1 + " " + m2;
+
+					Report.doWrite("DELETED SERVICES :");
+					for (int i = s.length - 1; i >= 0; i--) {
+						Report.doWrite(i + ". " + s[i]);
+					}
+					DataMngr.delServiceSetByURL(signURL);
+					DataMngr.delServErrors(signURL);
+					Report.add("THE CONNECT TO   < " + signURL
+							+ " >  WAS REFUSED WITH HTTP CODE " + code
+							+ " THREE TIMES IN ROW. ");
+					Report
+							.add("THE SERVICES LOCATED AT  < "
+									+ signURL
+									+ " >  WILL BE DEREGISTERED FROM mobycentral REGISTRY");
+					Report
+							.doWrite("=======================================================================================");
 				}
-             	int num  = DataMngr.getServErrorNum(signURL,code);
 
-             	if (num > 0){ 
-             		if (num < 3){
-             			DataMngr.updErrCount(signURL,code);
-             		}else{
-                       
-                        String servList = DataMngr.getServListByURL(signURL);
-						String s[] = servList.split(",");
-						Report.add("THE CONNECT TO   < "+signURL+" >  WAS REFUSED WITH HTTP CODE "+code+" THREE TIMES IN ROW. ");
-						Report.add("THE SERVICES LOCATED AT  < "+signURL+" >  WILL BE DEREGISTERED FROM mobycentral REGISTRY.");
-                        String m1 = "THE CONNECT TO   < "+signURL+" >  WAS REFUSED WITH HTTP CODE "+code+" THREE TIMES IN ROW. ";
-                        String m2 = "THE SERVICES LOCATED AT  < "+signURL+" >  WILL BE DEREGISTERED FROM mobycentral REGISTRY.";
-                        String msg = m1+" "+m2;
-
-						Report.doWrite("DELETED SERVICES :");
-                        for (int i = s.length - 1; i >=0; i --) {							                           
-	                        Report.doWrite(i+". "+s[i]);
-                        } 
-                        DataMngr.delServiceSetByURL(signURL); 
-                        DataMngr.delServErrors(signURL);
-            			Report.add("THE CONNECT TO   < "+signURL+" >  WAS REFUSED WITH HTTP CODE "+code+" THREE TIMES IN ROW. ");
-                        Report.add("THE SERVICES LOCATED AT  < "+signURL+" >  WILL BE DEREGISTERED FROM mobycentral REGISTRY");
-						Report.doWrite("=======================================================================================");
-             		}
-             		
-             	}else{
-					DataMngr.insErrCount(signURL,code);
-             	}	           
-		
-             }
-
-              huc.disconnect();
-        }
-        catch (IOException e) {        	
-			Log.severe("Failed : "+e);
-			Report.add("Error 2: "+e);
-//			e.getMessage();	
-        }
+			} else {
+				DataMngr.insErrCount(signURL, code);
+			}
+			huc.disconnect();
+		} catch (IOException e) {
+			Log.severe("Failed : " + e);
+			Report.add("Error 2: " + e);
+			//			e.getMessage();
+		}
+
+		return model;
 
-         return model;
-		
 	}
 
-/** a SMTP client that allows The SMTP client establishes a connection with an SMTP server
-    *  and waits for the server to respond . The client is then ready to construct a mail 
-    *  message. 
-	* (make HTTP connect to server, open a file,read a file into a streem, build a model)
-	* @param to - where  is the target of the e-mail message to be sent.
-	* @param subj - the subject of this MailMessage.
-	* @param msgStr - the text data that is to be included in this MailMessage.
-	* @param from - where  is the e-mail address of the message transmitter.
-	* 
-	*/
-	
-	
-	public static void sendMail(String to,String subj,String msgStr,String from){
-
-        try {
-     
-	        Properties prop = new Properties();
-            prop.put("mail.smtp.host",Constants.MB_MAIL_SERVER);			
+	/**
+	 * a SMTP client that allows The SMTP client establishes a connection with
+	 * an SMTP server and waits for the server to respond . The client is then
+	 * ready to construct a mail message. (make HTTP connect to server, open a
+	 * file,read a file into a streem, build a model)
+	 * 
+	 * @param to -
+	 *            where is the target of the e-mail message to be sent.
+	 * @param subj -
+	 *            the subject of this MailMessage.
+	 * @param msgStr -
+	 *            the text data that is to be included in this MailMessage.
+	 * @param from -
+	 *            where is the e-mail address of the message transmitter.
+	 *  
+	 */
+
+	public static void sendMail(String to, String subj, String msgStr,
+			String from) {
+
+		try {
+
+			Properties prop = new Properties();
+			prop.put("mail.smtp.host", Constants.MB_MAIL_SERVER);
 			Session ses = Session.getDefaultInstance(prop, null);
-            MimeMessage msg = new MimeMessage(ses);
-            msg.setFrom(new InternetAddress(from));
-            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
-            msg.setSubject(subj);
-            msg.setSentDate(new Date());
-            msg.setText(msgStr);
-            if (Constants.MB_MAIL_PSWD != null){
-              Transport transport = ses.getTransport("smtp"); //for usage a password
-              transport.connect(Constants.MB_MAIL_SERVER,Constants.MB_MAIL_USER,Constants.MB_MAIL_PSWD);
-            }
-            Transport.send(msg);
-            Report.doWrite("The message have been sent to "+to);
-        } catch (MessagingException e) {
-//			Log.severe(e.getMessage()+" sendmail"); 
-			e.getMessage();	
-        }
+			MimeMessage msg = new MimeMessage(ses);
+			msg.setFrom(new InternetAddress(from));
+			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
+			msg.setSubject(subj);
+			msg.setSentDate(new Date());
+			msg.setText(msgStr);
+			if (Constants.MB_MAIL_PSWD != null) {
+				Transport transport = ses.getTransport("smtp"); //for usage a
+																// password
+				transport.connect(Constants.MB_MAIL_SERVER,
+						Constants.MB_MAIL_USER, Constants.MB_MAIL_PSWD);
+			}
+			Transport.send(msg);
+			Report.doWrite("The message have been sent to " + to);
+		} catch (MessagingException e) {
+			//			Log.severe(e.getMessage()+" sendmail");
+			e.getMessage();
+		}
 
-    }
+	}
 
-	public static String readFromURL(String url){
+	public static String readFromURL(String url) {
 		String list = "";
 		try {
-		 URL u = new URL(url);
-          
-		 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
-		 huc.connect();
-           
-		 int code = huc.getResponseCode();
-		 Log.info("GET   <"+url+" >  - HTTP CODE: "+ code);
-		 Report.doWrite("");
-		 Report.doWrite("GET SIGNATURE_URL  <"+url+" >  - HTTP CODE: "+ code);
-		 Report.add("GET SIGNATURE_URL  <"+url+" >  - HTTP CODE: "+ code);
-            
-		 if (code == 200 || code == 202 ) { 
+			URL u = new URL(url);
 
-		 }else {
-					
-		 }			
-		 }catch (IOException e) {        	
-			  Log.severe("Failed : "+e);
-			  Report.add("Error 2: "+e);
-//			  e.getMessage();	
-		  }
+			HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+			huc.connect();
+
+			int code = huc.getResponseCode();
+			Log.info("GET   <" + url + " >  - HTTP CODE: " + code);
+			Report.doWrite("");
+			Report.doWrite("GET SIGNATURE_URL  <" + url + " >  - HTTP CODE: "
+					+ code);
+			Report.add("GET SIGNATURE_URL  <" + url + " >  - HTTP CODE: "
+					+ code);
+
+			if (code == 200 || code == 202) {
+
+			} else {
+
+			}
+		} catch (IOException e) {
+			Log.severe("Failed : " + e);
+			Report.add("Error 2: " + e);
+			//			  e.getMessage();
+		}
 		return list;
-	}	
+	}
+
+	public static Hashtable readFromFile(String file) {
 
-	 public static Hashtable readFromFile(String file) {
-	 	
-	 	Hashtable list = new Hashtable();
+		Hashtable list = new Hashtable();
 		//...checks on aFile are elided
-//		StringBuffer contents = new StringBuffer();
+		//		StringBuffer contents = new StringBuffer();
 
 		//declared here only to make visible to finally clause
 		BufferedReader input = null;
 		try {
-		  //use buffering
-		  //this implementation reads one line at a time
-		  input = new BufferedReader( new FileReader(file) );
-		  String line = null; //not declared within while loop
-		  while (( line = input.readLine()) != null){
-			list.put(line,"");
-//			contents.append(line);
-//			contents.append(System.getProperty("line.separator"));
-		  }
-		}
-		catch (FileNotFoundException ex) {
-		  ex.printStackTrace();
-		}
-		catch (IOException ex){
-		  ex.printStackTrace();
-		}
-		finally {
-		  try {
-			if (input!= null) {
-			  //flush and close both "input" and its underlying FileReader
-			  input.close();
+			//use buffering
+			//this implementation reads one line at a time
+			input = new BufferedReader(new FileReader(file));
+			String line = null; //not declared within while loop
+			while ((line = input.readLine()) != null) {
+				list.put(line, "");
+				//			contents.append(line);
+				//			contents.append(System.getProperty("line.separator"));
 			}
-		  }
-		  catch (IOException ex) {
+		} catch (FileNotFoundException ex) {
+			ex.printStackTrace();
+		} catch (IOException ex) {
 			ex.printStackTrace();
-		  }
+		} finally {
+			try {
+				if (input != null) {
+					//flush and close both "input" and its underlying
+					// FileReader
+					input.close();
+				}
+			} catch (IOException ex) {
+				ex.printStackTrace();
+			}
 		}
 		return list;
-	  }
+	}
 
-}
+}
\ No newline at end of file




More information about the MOBY-guts mailing list