You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by es...@apache.org on 2012/02/26 20:52:43 UTC

svn commit: r1293922 - in /incubator/openmeetings/branches/jira-plugin/src: main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java

Author: eschwert
Date: Sun Feb 26 19:52:43 2012
New Revision: 1293922

URL: http://svn.apache.org/viewvc?rev=1293922&view=rev
Log:
OPENMEETINGS-60 Close BufferedReader

Modified:
    incubator/openmeetings/branches/jira-plugin/src/main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java
    incubator/openmeetings/branches/jira-plugin/src/test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java

Modified: incubator/openmeetings/branches/jira-plugin/src/main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/branches/jira-plugin/src/main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java?rev=1293922&r1=1293921&r2=1293922&view=diff
==============================================================================
--- incubator/openmeetings/branches/jira-plugin/src/main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java (original)
+++ incubator/openmeetings/branches/jira-plugin/src/main/java/org/openmeetings/jira/plugin/gateway/OmRestService.java Sun Feb 26 19:52:43 2012
@@ -140,6 +140,8 @@ public class OmRestService {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			throw new Exception("DocumentException by SAXReader in REST Service");
+		}finally{
+			br.close();
 		}
 	    
         Element root = document.getRootElement(); 

Modified: incubator/openmeetings/branches/jira-plugin/src/test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/branches/jira-plugin/src/test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java?rev=1293922&r1=1293921&r2=1293922&view=diff
==============================================================================
--- incubator/openmeetings/branches/jira-plugin/src/test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java (original)
+++ incubator/openmeetings/branches/jira-plugin/src/test/java/org/openmeetings/jira/plugin/gateway/OmRestServiceTest.java Sun Feb 26 19:52:43 2012
@@ -1,8 +1,11 @@
 package org.openmeetings.jira.plugin.gateway;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
 
 import org.junit.Test;
 import org.junit.After;
@@ -25,8 +28,12 @@ import org.dom4j.DocumentException;
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
 
+import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URL;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
+
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriBuilder;
 
@@ -114,7 +121,7 @@ new OmRestService();
     }
     
     
-    @Test
+    //@Test
     public void testCallApacheCommons() throws SAXException, IOException, ParserConfigurationException, XPathExpressionException, DocumentException {
         
     	try{   	
@@ -237,4 +244,138 @@ new OmRestService();
     	}
     }
     
+    private  String getEncodetURI(String url) throws MalformedURLException {
+		return new URL(url).toString().replaceAll(" ","%20");
+	}
+    
+    @Test
+	public void callTestExceptions() throws Exception
+	{	
+    	String request= "http://localhost:5080/openmeetings/services/UserService/getSession";
+
+		HttpClient client = new HttpClient();
+        GetMethod method = null;
+        
+		try {
+			method = new GetMethod(getEncodetURI(request).toString());
+		} catch (MalformedURLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		int statusCode = 0;
+		try {
+			statusCode = client.executeMethod(method);
+		} catch (HttpException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("Connection to OpenMeetings refused. Please check your OpenMeetings configuration. HttpException");
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("Connection to OpenMeetings refused. Please check your OpenMeetings configuration. IOException");
+		}
+		
+		
+		switch (statusCode) {
+	    
+		    case 200: {		    	
+			    System.out.println("Success connection");			    
+			    break;	
+		    }
+		    case 400: {		    	
+				throw new Exception("Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect.");
+	    	
+			    //System.out.println("Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect."); 
+		     
+				//break;
+	
+		    }	
+		    case 403: {
+				throw new Exception("Forbidden. You do not have permission to access this resource, or are over your rate limit.");
+	
+				//System.out.println("Forbidden. You do not have permission to access this resource, or are over your rate limit.");
+	
+				//break;
+		
+		    }		
+		    case 503: {
+				throw new Exception("Service unavailable. An internal problem prevented us from returning data to you.");
+
+				//System.out.println("Service unavailable. An internal problem prevented us from returning data to you.");
+		
+			    //break;
+		
+		    }			    
+		    default:{ 
+					throw new Exception("Your call to OpenMeetings! Web Services returned an unexpected  HTTP status of: " + statusCode);
+	
+			    	//System.out.println("Your call to OpenMeetings! Web Services returned an unexpected  HTTP status of: " + statusCode);
+		    }
+		    
+	    }
+        
+		
+        InputStream rstream = null;
+
+        try {
+			rstream = method.getResponseBodyAsStream();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("No Response Body");
+
+		}
+
+        BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
+        
+        SAXReader reader = new SAXReader();
+	    String line;
+	    Document document = null;
+	    try {
+			while ((line = br.readLine()) != null) {
+				document = reader.read(new ByteArrayInputStream(line.getBytes("UTF-8")));
+				//System.out.println("line"+line);
+			
+			}
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("UnsupportedEncodingException by SAXReader");
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("IOException by SAXReader in REST Service");
+		} catch (DocumentException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			throw new Exception("DocumentException by SAXReader in REST Service");
+		}finally{
+			br.close();
+		}
+	    
+        Element root = document.getRootElement(); 
+        
+        LinkedHashMap<String,Element> elementMap = new LinkedHashMap<String,Element>();       	                    
+        
+        for ( @SuppressWarnings("unchecked")Iterator<Element> i = root.elementIterator(); i.hasNext(); ) {
+        	
+        	
+	            Element item = i.next();
+	            
+	            if(item.getNamespacePrefix()=="soapenv"){
+	            	throw new Exception(item.getData().toString());
+	            }else{
+	            	String nodeVal = item.getName();
+		            elementMap.put(nodeVal, item);
+		            log.error(item.asXML());
+	            }
+        	}
+		
+		//return elementMap;        
+	    
+	}	
+	
+    
+    
+    
 }