Skip to content

Commit

Permalink
TEIID-3914 TEIID-3911 updating test and refining error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Feb 8, 2016
1 parent 00bb7c4 commit be855d4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/main/java/org/teiid/jdbc/TeiidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ConnectionImpl connect(String url, Properties info) throws SQLException {
myConnection = socketProfile.connect(url, info);
}
} catch (TeiidSQLException e) {
logger.log(Level.SEVERE, "Could not create connection", e); //$NON-NLS-1$
logger.log(Level.FINE, "Could not create connection", e); //$NON-NLS-1$
throw TeiidSQLException.create(e, e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<module name="org.jboss.teiid.admin"/>
<module name="org.jboss.teiid.api"/>
<module name="org.jboss.teiid"/>
<module name="org.apache.commons.lang" slot="3.3.2"/>
</dependencies>

</module>
3 changes: 2 additions & 1 deletion olingo/src/main/java/org/teiid/olingo/ODataPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static enum Event implements BundleUtil.Event {
TEIID16043,
TEIID16044,
TEIID16045,
TEIID16046
TEIID16046,
TEIID16047
}
}
20 changes: 20 additions & 0 deletions olingo/src/main/java/org/teiid/olingo/web/ODataFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.teiid.olingo.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.ref.SoftReference;
import java.sql.Connection;
import java.sql.SQLException;
Expand All @@ -38,7 +39,10 @@
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.server.api.ODataHttpHandler;
import org.teiid.core.util.LRUCache;
import org.teiid.deployers.CompositeVDB;
Expand Down Expand Up @@ -85,6 +89,22 @@ public void init(FilterConfig config) throws ServletException {

@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
internalDoFilter(request, response, chain);
} catch (UnavailableException e) {
LogManager.logWarning(LogConstants.CTX_ODATA, e, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16047, e.getMessage()));
HttpServletResponse httpResponse = (HttpServletResponse)response;
httpResponse.setStatus(404);
//TODO: json error as well
httpResponse.setHeader(HttpHeader.CONTENT_TYPE, "application/xml"); //$NON-NLS-1$
PrintWriter writer = httpResponse.getWriter();
writer.write("<m:error xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:code/><m:message>"+StringEscapeUtils.escapeXml10(e.getMessage())+"</m:message></m:error>"); //$NON-NLS-1$ //$NON-NLS-2$
writer.close();
}
}

public void internalDoFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;
Expand Down
1 change: 1 addition & 0 deletions olingo/src/main/resources/org/teiid/olingo/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ TEIID16043=Wrong query expecting $root
TEIID16044={0} is invalid - the semantic version must contain all parts vX.X.X, not have a trailing . and the old version property must be unspecified or 1.
TEIID16045=Expected Edm.String, but value is {0}
TEIID16046=Invalid query, "auth" and "token" end points apply only for oauth based security. Typically the authentication URL will look like http://<host>:8080/odata4/auth, note there is no VDB name after the "odata4" in the URL. The OData URL looks like http://<host>:8080/odata4/<vdbname>.<version>/schema/entityName
TEIID16047=Could not process OData 4 request: {0}
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public void testOdata() throws Exception {
conn.close();

//try an invalid url
client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
client = WebClient.create("http://localhost:8080/odata4/x/y$metadata");
client.header("Authorization", "Basic " + Base64.encodeBytes(("user:user").getBytes())); //$NON-NLS-1$ //$NON-NLS-2$
response = client.invoke("GET", null);
assertEquals(500, response.getStatus());
assertEquals(404, response.getStatus());

admin.undeploy("loopy-vdb.xml");
}
Expand Down Expand Up @@ -161,10 +161,9 @@ public void testReadOdataMetadata() throws Exception {
}

// TEIID-3914 - test the olingo-patch work
public void testCompositeKeyTimestamp() throws Exception {

@Test public void testCompositeKeyTimestamp() throws Exception {
String vdb = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<vdb name=\"northwind\" version=\"1\">\n" +
"<vdb name=\"Loopy\" version=\"1\">\n" +
" <model name=\"m\">\n" +
" <source name=\"x1\" translator-name=\"loopback\" />\n" +
" <metadata type=\"DDL\"><![CDATA[\n" +
Expand All @@ -176,15 +175,16 @@ public void testCompositeKeyTimestamp() throws Exception {
admin.deploy("loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));
assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

WebClient client = WebClient.create("http://localhost:8080/odata4/m/x(a='a',b=2011-09-11T00:00:00Z)");
WebClient client = WebClient.create("http://localhost:8080/odata4/Loopy/m/x(a='a',b=2011-09-11T00:00:00Z)");
client.header("Authorization", "Basic " + Base64.encodeBytes(("user:user").getBytes())); //$NON-NLS-1$ //$NON-NLS-2$
Response response = client.invoke("GET", null);
assertEquals(200, response.getStatus());

client = WebClient.create("http://localhost:8080/odata4/m/x");
client = WebClient.create("http://localhost:8080/odata4/Loopy/m/x");
client.header("Authorization", "Basic " + Base64.encodeBytes(("user:user").getBytes())); //$NON-NLS-1$ //$NON-NLS-2$
client.header("Content-Type", "application/json");
response = client.post("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}");
assertEquals(204, response.getStatus());
assertEquals(304, response.getStatus());

admin.undeploy("loopy-vdb.xml");
}
Expand Down

0 comments on commit be855d4

Please sign in to comment.