// TEIID-3914 - test the olingo-patch work public void testCompositeKeyTimestamp() throws Exception { String vdb = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<vdb name=\"northwind\" version=\"1\">\n" + " <model name=\"m\">\n" + " <source name=\"x1\" translator-name=\"loopback\" />\n" + " <metadata type=\"DDL\"><![CDATA[\n" + " CREATE FOREIGN TABLE x (a string, b timestamp, c integer, primary key (a, b)) options (updatable true);\n" + " ]]> </metadata>\n" + " </model>\n" + "</vdb>"; 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)"); 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.header( "Authorization", "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$ response = client.post("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}"); assertEquals(204, response.getStatus()); admin.undeploy("loopy-vdb.xml"); }
@Test public void testOdata() throws Exception { String vdb = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<vdb name=\"Loopy\" version=\"1\">\n" + " <model name=\"MarketData\">\n" + " <source name=\"text-connector2\" translator-name=\"loopback\" />\n" + " <metadata type=\"DDL\"><![CDATA[\n" + " CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n" + " CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n" + " ]]> </metadata>\n" + " </model>\n" + "</vdb>"; 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://*****:*****@mm://localhost:31000;user=user;password=user", null); PreparedStatement ps = conn.prepareCall( "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t"); ps.setAsciiStream(1, (InputStream) response.getEntity()); ResultSet rs = ps.executeQuery(); rs.next(); assertEquals( ObjectConverterUtil.convertFileToString( UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")), rs.getString(1)); conn.close(); // try an invalid url client = WebClient.create("http://localhost:8080/odata/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()); admin.undeploy("loopy-vdb.xml"); }
@Override public DataSource invoke(DataSource msg) { try { final URL url = new URL(this.endpoint); final String httpMethod = (String) this.requestContext.get(MessageContext.HTTP_REQUEST_METHOD); Map<String, List<String>> header = (Map<String, List<String>>) this.requestContext.get(MessageContext.HTTP_REQUEST_HEADERS); for (Map.Entry<String, List<String>> entry : header.entrySet()) { this.client.header(entry.getKey(), entry.getValue().toArray()); } String username = (String) this.requestContext.get(Dispatch.USERNAME_PROPERTY); String password = (String) this.requestContext.get(Dispatch.PASSWORD_PROPERTY); if (username != null) { this.client.header( AUTHORIZATION, "Basic " + Base64.encodeBytes((username + ':' + password).getBytes())); // $NON-NLS-1$ } else if (this.requestContext.get(GSSCredential.class.getName()) != null) { WebClient.getConfig(this.client) .getRequestContext() .put( GSSCredential.class.getName(), this.requestContext.get(GSSCredential.class.getName())); WebClient.getConfig(this.client) .getRequestContext() .put("auth.spnego.requireCredDelegation", true); // $NON-NLS-1$ } else if (this.requestContext.get(OAuthCredential.class.getName()) != null) { OAuthCredential credential = (OAuthCredential) this.requestContext.get(OAuthCredential.class.getName()); this.client.header( AUTHORIZATION, credential.getAuthorizationHeader(this.endpoint, httpMethod)); } InputStream payload = null; if (msg != null) { payload = msg.getInputStream(); } HTTPClientPolicy clientPolicy = WebClient.getConfig(this.client).getHttpConduit().getClient(); Long timeout = (Long) this.requestContext.get(RECEIVE_TIMEOUT); if (timeout != null) { clientPolicy.setReceiveTimeout(timeout); } timeout = (Long) this.requestContext.get(CONNECTION_TIMEOUT); if (timeout != null) { clientPolicy.setConnectionTimeout(timeout); } javax.ws.rs.core.Response response = this.client.invoke(httpMethod, payload); this.responseContext.put(WSConnection.STATUS_CODE, response.getStatus()); this.responseContext.putAll(response.getMetadata()); ArrayList contentTypes = (ArrayList) this.responseContext.get("content-type"); // $NON-NLS-1$ String contentType = contentTypes != null ? (String) contentTypes.get(0) : "application/octet-stream"; //$NON-NLS-1$ return new HttpDataSource(url, (InputStream) response.getEntity(), contentType); } catch (IOException e) { throw new WebServiceException(e); } }