[teiid-commits] teiid SVN: r4372 - in trunk: jboss-integration/src/main/resources/rest-war and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Aug 27 18:38:00 EDT 2012


Author: rareddy
Date: 2012-08-27 18:38:00 -0400 (Mon, 27 Aug 2012)
New Revision: 4372

Added:
   trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
Modified:
   trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
   trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
   trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml
   trunk/jboss-integration/src/main/resources/rest-war/web.xml
   trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java
   trunk/test-integration/common/src/test/resources/sample-vdb.xml
Log:
TEIID-2158: Adding the HTTPBasic security, with option to use pass-through-authentication and ad-hoc query based rest service

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/RestASMBasedWebArchiveBuilder.java	2012-08-27 22:38:00 UTC (rev 4372)
@@ -56,8 +56,8 @@
 import org.teiid.metadata.MetadataStore;
 import org.teiid.metadata.Procedure;
 import org.teiid.metadata.ProcedureParameter;
+import org.teiid.metadata.ProcedureParameter.Type;
 import org.teiid.metadata.Schema;
-import org.teiid.metadata.ProcedureParameter.Type;
 import org.teiid.query.metadata.TransformationMetadata;
 
 
@@ -74,6 +74,29 @@
 		props.setProperty("${vdb-name}", vdb.getName());
 		props.setProperty("${vdb-version}", String.valueOf(vdb.getVersion()));
 		
+		boolean passthroughAuth = false;
+		String securityType = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-type");
+		String securityDomain = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-domain");
+		String securityRole = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-role");
+		String passthoughAuthStr = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"passthrough-auth");
+		if (passthoughAuthStr != null) {
+			passthroughAuth = Boolean.parseBoolean(passthoughAuthStr);
+		}
+		
+		props.setProperty("${security-role}", ((securityRole == null)?"rest":securityRole));
+		props.setProperty("${security-domain}", ((securityDomain == null)?"teiid-security":securityDomain));
+		
+		if (securityType == null) {
+			securityType = "httpbasic";
+		}
+
+		if (securityType.equalsIgnoreCase("none")) {
+			props.setProperty("${security-content}", "");
+		}
+		else if (securityType.equalsIgnoreCase("httpbasic")) {
+			props.setProperty("${security-content}", replaceTemplates(getFileContents("rest-war/httpbasic.xml"), props));
+		}
+		
 		ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
 		ZipOutputStream out = new ZipOutputStream(byteStream); 
 		writeEntry("WEB-INF/web.xml", out, replaceTemplates(getFileContents("rest-war/web.xml"), props).getBytes());
@@ -82,7 +105,7 @@
 		ArrayList<String> applicationViews = new ArrayList<String>();
 		for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
 			Schema schema = metadataStore.getSchema(model.getName());
-			byte[] viewContents = getViewClass(vdb.getName(), vdb.getVersion(), model.getName(), schema);
+			byte[] viewContents = getViewClass(vdb.getName(), vdb.getVersion(), model.getName(), schema, passthroughAuth);
 			if (viewContents != null) {
 				writeEntry("WEB-INF/classes/org/teiid/jboss/rest/"+model.getName()+".class", out, viewContents);
 				applicationViews.add(schema.getName());
@@ -205,7 +228,7 @@
     	return cw.toByteArray();
     }
     
-    private byte[] getViewClass(String vdbName, int vdbVersion, String modelName, Schema schema) {
+    private byte[] getViewClass(String vdbName, int vdbVersion, String modelName, Schema schema, boolean passthroughAuth) {
     	ClassWriter cw = new ClassWriter(0);
     	FieldVisitor fv;
     	MethodVisitor mv;
@@ -237,11 +260,13 @@
 			String method = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"METHOD", false);
 			String contentType = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"PRODUCES", false);
 			String charSet = procedure.getProperty(ResteasyEnabler.REST_NAMESPACE+"CHARSET", false);
-			if (getPathParameters(uri).size() != procedure.getParameters().size()) {
-				LogManager.logWarning(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50091, procedure.getFullName()));
-				continue;
-			}
+			
 			if (uri != null && method != null) {
+				if (method.equalsIgnoreCase("GET")	&& getPathParameters(uri).size() != procedure.getParameters().size()) {
+					LogManager.logWarning(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50091, procedure.getFullName()));
+					continue;
+				}				
+				
 				if (contentType == null) {
 					contentType = findContentType(procedure);
 				}
@@ -257,14 +282,14 @@
 					else if (contentType.equals("plain")) {
 						contentType = "text/plain";
 					}
-			    	buildRestService(vdbName, vdbVersion, modelName, procedure, method, uri, cw, contentType, charSet);
+			    	buildRestService(vdbName, vdbVersion, modelName, procedure, method, uri, cw, contentType, charSet, passthroughAuth);
 			    	hasValidProcedures = true;
 				}
 			}
 		}    	
 		
-//		buildQueryProcedure(vdbName, vdbVersion, "xml", cw);
-//		buildQueryProcedure(vdbName, vdbVersion, "json", cw);
+		buildQueryProcedure(vdbName, vdbVersion, "xml", cw, passthroughAuth);
+		buildQueryProcedure(vdbName, vdbVersion, "json", cw, passthroughAuth);
     	
     	cw.visitEnd();
 
@@ -303,7 +328,7 @@
 
 	private void buildRestService(String vdbName, int vdbVersion, String modelName, Procedure procedure,
 			String method, String uri, ClassWriter cw, String contentType,
-			String charSet) {
+			String charSet, boolean passthroughAuth) {
 		
 		List<ProcedureParameter> params = new ArrayList<ProcedureParameter>(procedure.getParameters().size());
 		boolean usingReturn = false;
@@ -350,9 +375,15 @@
     	av0.visitEnd();
     	}
     	
+    	// post only accepts Form inputs, not path params
+    	String paramType = "Ljavax/ws/rs/PathParam;";
+    	if (method.toUpperCase().equals("POST")) {
+    		paramType = "Ljavax/ws/rs/FormParam;";
+    	}
+    	
     	for (int i = 0; i < paramsSize; i++)
     	{
-		av0 = mv.visitParameterAnnotation(i, "Ljavax/ws/rs/PathParam;", true);
+		av0 = mv.visitParameterAnnotation(i, paramType, true);
 		av0.visit("value", params.get(i).getName());
 		av0.visitEnd();
 		}
@@ -402,8 +433,8 @@
     	
     	mv.visitVarInsn(ALOAD, paramsSize+1);
     	mv.visitLdcInsn(charSet==null?"":charSet);
-    	
-    	mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;)Ljava/io/InputStream;");
+    	mv.visitInsn(passthroughAuth?ICONST_1:ICONST_0);
+    	mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/"+modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;Z)Ljava/io/InputStream;");
     	mv.visitLabel(l1);
     	mv.visitInsn(ARETURN);
     	mv.visitLabel(l2);
@@ -415,12 +446,12 @@
     	mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;");
     	mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V");
     	mv.visitInsn(ATHROW);
-    	mv.visitMaxs(6, paramsSize+2);
+    	mv.visitMaxs(7, paramsSize+2);
     	mv.visitEnd();
     	}
 	}
 	
-	private void buildQueryProcedure(String vdbName, int vdbVersion, String context, ClassWriter cw) {
+	private void buildQueryProcedure(String vdbName, int vdbVersion, String context, ClassWriter cw, boolean passthroughAuth) {
 		MethodVisitor mv;
 		{
 			AnnotationVisitor av0;
@@ -459,7 +490,8 @@
 			mv.visitIntInsn(BIPUSH, vdbVersion);
 			mv.visitVarInsn(ALOAD, 1);
 			mv.visitInsn(context.equals("xml")?ICONST_0:ICONST_1);
-			mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/View", "executeQuery", "(Ljava/lang/String;ILjava/lang/String;Z)Ljava/io/InputStream;");
+			mv.visitInsn(passthroughAuth?ICONST_1:ICONST_0);
+			mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/View", "executeQuery", "(Ljava/lang/String;ILjava/lang/String;ZZ)Ljava/io/InputStream;");
 			mv.visitLabel(l1);
 			mv.visitInsn(ARETURN);
 			mv.visitLabel(l2);
@@ -471,7 +503,7 @@
 			mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;");
 			mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V");
 			mv.visitInsn(ATHROW);
-			mv.visitMaxs(5, 3);
+			mv.visitMaxs(6, 3);
 			mv.visitEnd();
 		}		
 	}

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/ResteasyEnabler.java	2012-08-27 22:38:00 UTC (rev 4372)
@@ -61,7 +61,7 @@
 	public void finishedDeployment(String name, int version, CompositeVDB cvdb) {
 		final VDBMetaData vdb = cvdb.getVDB();
 		
-		String generate = vdb.getPropertyValue("auto-generate-rest-war"); //$NON-NLS-1$
+		String generate = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"auto-generate"); //$NON-NLS-1$
 
 		final String warName = buildName(vdb);
 		if (generate != null && Boolean.parseBoolean(generate)
@@ -112,6 +112,11 @@
 	}
 	
 	private boolean hasRestMetadata(VDBMetaData vdb) {
+		String securityType = vdb.getPropertyValue(ResteasyEnabler.REST_NAMESPACE+"security-type"); //$NON-NLS-1$
+		if (securityType != null && !securityType.equalsIgnoreCase("none") && !securityType.equalsIgnoreCase("httpbasic")) { //$NON-NLS-1$ //$NON-NLS-2$
+			return false;
+		}
+		
 		MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
 		for (ModelMetaData model: vdb.getModelMetaDatas().values()) {
 			Schema schema = metadataStore.getSchema(model.getName());

Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/rest/TeiidRSProvider.java	2012-08-27 22:38:00 UTC (rev 4372)
@@ -31,6 +31,7 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.SQLXML;
+import java.sql.Statement;
 import java.util.LinkedHashMap;
 
 import org.teiid.core.types.BlobType;
@@ -45,7 +46,7 @@
 public abstract class TeiidRSProvider {
 
 	public InputStream execute(String vdbName, int version,	String procedureSignature,
-			LinkedHashMap<String, String> parameters, String charSet) throws SQLException {
+			LinkedHashMap<String, String> parameters, String charSet, boolean passthroughAuth) throws SQLException {
         Object result = null;
         
         //the generated code sends a empty string rather than null.
@@ -53,7 +54,7 @@
         	charSet = null;
         }
         
-        Connection conn = getConnection(vdbName, version);
+        Connection conn = getConnection(vdbName, version, passthroughAuth);
         boolean usingReturn = procedureSignature.startsWith("{ ?"); //$NON-NLS-1$
         try {
         	//TODO: an alternative strategy would be to set the parameters based upon name
@@ -84,32 +85,7 @@
             	result = statement.getObject(1);
             }
             statement.close();
-            if (result == null) {
-            	return null; //or should this be an empty result?
-            }
-            
-            if (result instanceof SQLXML) {
-            	if (charSet != null) {
-	            	XMLSerialize serialize = new XMLSerialize();
-	            	serialize.setTypeString("blob"); //$NON-NLS-1$
-	            	serialize.setDeclaration(true);
-	            	serialize.setEncoding(charSet);
-	            	serialize.setDocument(true);
-	            	try {
-						return ((BlobType)XMLSystemFunctions.serialize(serialize, (XMLType)result)).getBinaryStream();
-					} catch (TransformationException e) {
-						throw new SQLException(e);
-					}
-            	}
-            	return ((SQLXML)result).getBinaryStream();
-            }
-            else if (result instanceof Blob) {
-            	return ((Blob)result).getBinaryStream();
-            }
-            else if (result instanceof Clob) {
-            	return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet));
-            }
-            return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet)));
+            return handleResult(charSet, result);
         } finally {
             if (conn != null) {
                 try {
@@ -119,10 +95,65 @@
             }
         }
     }
+
+	private InputStream handleResult(String charSet, Object result) throws SQLException {
+        if (result == null) {
+        	return null; //or should this be an empty result?
+        }
+        
+		if (result instanceof SQLXML) {
+			if (charSet != null) {
+		    	XMLSerialize serialize = new XMLSerialize();
+		    	serialize.setTypeString("blob"); //$NON-NLS-1$
+		    	serialize.setDeclaration(true);
+		    	serialize.setEncoding(charSet);
+		    	serialize.setDocument(true);
+		    	try {
+					return ((BlobType)XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML)result))).getBinaryStream();
+				} catch (TransformationException e) {
+					throw new SQLException(e);
+				}
+			}
+			return ((SQLXML)result).getBinaryStream();
+		}
+		else if (result instanceof Blob) {
+			return ((Blob)result).getBinaryStream();
+		}
+		else if (result instanceof Clob) {
+			return new ReaderInputStream(((Clob)result).getCharacterStream(), charSet==null?Charset.defaultCharset():Charset.forName(charSet));
+		}
+		return new ByteArrayInputStream(result.toString().getBytes(charSet==null?Charset.defaultCharset():Charset.forName(charSet)));
+	}
 	
-	private Connection getConnection(String vdbName, int version) throws SQLException {
+	public InputStream executeQuery(String vdbName, int vdbVersion, String sql, boolean json, boolean passthroughAuth) throws SQLException {
+		Connection conn = getConnection(vdbName, vdbVersion, passthroughAuth);
+		Object result = null;
+		try {
+			Statement statement = conn.createStatement();
+            final boolean hasResultSet = statement.execute(sql);
+            if (hasResultSet) {
+                ResultSet rs = statement.getResultSet();
+                if (rs.next()) {
+                    result = rs.getObject(1);
+                } else {
+                	throw new SQLException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50092)); 
+                }
+                rs.close();
+            }			
+			statement.close();
+			return handleResult(Charset.defaultCharset().name(), result);
+		} finally {
+            if (conn != null) {
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                }
+            }
+		}
+	}
+	
+	private Connection getConnection(String vdbName, int version, boolean passthough) throws SQLException {
 		TeiidDriver driver = new TeiidDriver();
-		return driver.connect("jdbc:teiid:"+vdbName+"."+version, null);
+		return driver.connect("jdbc:teiid:"+vdbName+"."+version+(passthough?"PassthroughAuthentication=true":""), null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
 	}
-	
 }

Added: trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml	                        (rev 0)
+++ trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml	2012-08-27 22:38:00 UTC (rev 4372)
@@ -0,0 +1,20 @@
+     <security-role>
+        <description>security role</description>
+        <role-name>${security-role}</role-name>
+    </security-role>
+      
+    <security-constraint>
+        <display-name>require valid user</display-name>
+        <web-resource-collection>
+            <web-resource-name>Teiid Rest Application</web-resource-name>
+            <url-pattern>/*</url-pattern>
+        </web-resource-collection>
+        <auth-constraint>
+            <role-name>${security-role}</role-name>
+        </auth-constraint>
+    </security-constraint>
+
+    <login-config>
+        <auth-method>BASIC</auth-method>
+        <realm-name>yourdomain.com</realm-name>
+    </login-config>
\ No newline at end of file


Property changes on: trunk/jboss-integration/src/main/resources/rest-war/httpbasic.xml
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/resources/rest-war/jboss-web.xml	2012-08-27 22:38:00 UTC (rev 4372)
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <jboss-web>
-    <security-domain>java:/jaas/teiid-security</security-domain>
+    <security-domain>java:/jaas/${security-domain}</security-domain>
 </jboss-web>
\ No newline at end of file

Modified: trunk/jboss-integration/src/main/resources/rest-war/web.xml
===================================================================
--- trunk/jboss-integration/src/main/resources/rest-war/web.xml	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/jboss-integration/src/main/resources/rest-war/web.xml	2012-08-27 22:38:00 UTC (rev 4372)
@@ -16,26 +16,7 @@
         <servlet-name>RestDataservice</servlet-name>
         <url-pattern>/*</url-pattern>
     </servlet-mapping>
-  <!-- 
-     <security-role>
-        <description>security role</description>
-        <role-name>example-role</role-name>
-    </security-role>
-      
-    <security-constraint>
-        <display-name>require valid user</display-name>
-        <web-resource-collection>
-            <web-resource-name>Teiid rest application</web-resource-name>
-            <url-pattern>/*</url-pattern>
-        </web-resource-collection>
-        <auth-constraint>
-            <role-name>example-role</role-name>
-        </auth-constraint>
-    </security-constraint>
 
-    <login-config>
-        <auth-method>BASIC</auth-method>
-        <realm-name>yourdomain.com</realm-name>
-    </login-config>
-     -->      
+${security-content}
+      
 </web-app>
\ No newline at end of file

Modified: trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestRestWebserviceGeneration.java	2012-08-27 22:38:00 UTC (rev 4372)
@@ -22,13 +22,16 @@
 
 package org.teiid.arquillian;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.BufferedReader;
 import java.io.FileInputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLEncoder;
 
 import org.jboss.arquillian.junit.Arquillian;
 import org.junit.After;
@@ -61,7 +64,7 @@
 	}
 	
 	@Test
-    public void testReuse() throws Exception {
+    public void testGetOperation() throws Exception {
 		admin.deploy("sample-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
 		
 		assertTrue(AdminUtil.waitForVDBLoad(admin, "sample", 1, 3));
@@ -73,15 +76,49 @@
 		
 		assertTrue(((AdminImpl)admin).getDeployments().contains("sample_1.war"));
 		
-		String response = httpCall("http://localhost:8080/sample_1/view/g1/123", "GET");
-		assertEquals("<sample.g1Table.p1 p1=\"123\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></sample.g1Table.p1>", response);
+		// get based call
+		String response = httpCall("http://localhost:8080/sample_1/view/g1/123", "GET", null);
+		assertEquals("<rows p1=\"123\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
     }
 	
-	private String httpCall(String url, String method) throws Exception {
+	@Test
+    public void testPostOperation() throws Exception {
+		admin.deploy("sample-vdb.xml",new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
+		
+		assertTrue(AdminUtil.waitForVDBLoad(admin, "sample", 1, 3));
+		
+		this.internalConnection =  TeiidDriver.getInstance().connect("jdbc:teiid:sample at mm://localhost:31000;user=user;password=user", null);
+		
+		execute("SELECT * FROM Txns.G1"); //$NON-NLS-1$
+		this.internalResultSet.next();
+		
+		assertTrue(((AdminImpl)admin).getDeployments().contains("sample_1.war"));
+		
+		String params = URLEncoder.encode("p1", "UTF-8") + "=" + URLEncoder.encode("456", "UTF-8");
+		
+		// post based call
+		String response = httpCall("http://localhost:8080/sample_1/view/g1post", "POST", params);
+		assertEquals("<rows p1=\"456\"><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
+		
+		// ad-hoc procedure
+		params = URLEncoder.encode("sql", "UTF-8") + "=" + URLEncoder.encode("SELECT XMLELEMENT(NAME \"rows\", XMLAGG(XMLELEMENT(NAME \"row\", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1", "UTF-8");
+		response = httpCall("http://localhost:8080/sample_1/view/query", "POST", params);
+		assertEquals("<rows><row><e1>ABCDEFGHIJ</e1><e2>0</e2></row></rows>", response);
+    }	
+	
+	
+	private String httpCall(String url, String method, String params) throws Exception {
 		StringBuffer buff = new StringBuffer();
 		HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
 		connection.setRequestMethod(method);
 		connection.setDoOutput(true);
+		
+		if (method.equalsIgnoreCase("post")) {
+			OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
+		    wr.write(params);
+		    wr.flush();
+		}
+		
 		BufferedReader serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
 		String line;
 		while ((line = serverResponse.readLine()) != null) {

Modified: trunk/test-integration/common/src/test/resources/sample-vdb.xml
===================================================================
--- trunk/test-integration/common/src/test/resources/sample-vdb.xml	2012-08-27 20:43:50 UTC (rev 4371)
+++ trunk/test-integration/common/src/test/resources/sample-vdb.xml	2012-08-27 22:38:00 UTC (rev 4372)
@@ -1,7 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <vdb name="sample" version="1">
     <property name="UseConnectorMetadata" value="true" />
-    <property name="auto-generate-rest-war" value="true"/>
+    <property name="{http://teiid.org/rest}auto-generate" value="true"/>
+    <property name="{http://teiid.org/rest}security-type" value="none"/>
+    <property name="{http://teiid.org/rest}security-domain" value="teiid-security"/>
+    <property name="{http://teiid.org/rest}security-role" value="example-role"/>
     
     <model name="Txns">
         <source name="text-connector" translator-name="loopback" />
@@ -16,13 +19,18 @@
             CREATE VIRTUAL PROCEDURE g1Table(IN p1 integer) RETURNS TABLE (xml_out xml) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'g1/{p1}')
             AS
             BEGIN
-                SELECT XMLELEMENT(NAME sample.g1Table.p1, XMLATTRIBUTES (g1Table.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
+                SELECT XMLELEMENT(NAME "rows", XMLATTRIBUTES (g1Table.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
             END        
             CREATE VIRTUAL PROCEDURE g2Table() RETURNS TABLE (xml_out string) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'g2')
             AS
             BEGIN
                 SELECT '{ "age":100, "name":test,messages:["msg1","msg2","msg3"]}' as xml_out;
-            END                    
+            END     
+            CREATE VIRTUAL PROCEDURE g1TablePost(IN p1 integer) RETURNS TABLE (xml_out xml) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'POST', "REST:URI" 'g1post')
+            AS
+            BEGIN
+                SELECT XMLELEMENT(NAME "rows", XMLATTRIBUTES (g1TablePost.p1 as p1), XMLAGG(XMLELEMENT(NAME "row", XMLFOREST(e1, e2)))) AS xml_out FROM Txns.G1;
+            END                            
             ]]> </metadata>
     </model>
 



More information about the teiid-commits mailing list