-
1. Re: Does Teiid REST service support a Blob Input?
rareddy Sep 24, 2013 9:13 AM (in response to madhu.garimilla)It does support POST and there is no restriction of the type to use. However it does not handle automatic type conversion, try writing a Blob object to output stream. I have to say I have not tested that scenario. Also not certain for the multi-part stuff will work with Resteasy framework.
Ramesh..
-
2. Re: Does Teiid REST service support a Blob Input?
madhu.garimilla Oct 4, 2013 9:07 AM (in response to rareddy)Ramesh, I created Blob using the below code and tried to write it using ObjectOutputStream to HttpUrlConnection but it failed as it cannot be serialized.
Blob blob = new org.teiid.core.types.BlobImpl(new org.teiid.core.types.InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new FileInputStream("C:\\sample.war");
}
});
Then i tried using SerialBlob but that also resulted in the same error as "java.io.NotSerializableException" . This does work in JDBC but not sure how to make it work with Teiid REST service. Do you have any suggestions? multipart stuff is working with the normal jboss resteasy framework.
-
3. Re: Does Teiid REST service support a Blob Input?
rareddy Oct 4, 2013 10:06 AM (in response to madhu.garimilla)What is client code look like?
Also, try building BlobImpl or SerialBlob with full byte contents of your data.
-
4. Re: Does Teiid REST service support a Blob Input?
madhu.garimilla Oct 4, 2013 1:09 PM (in response to rareddy)Here is my client code.
String userPassword = "user:user";
String encoding = new BASE64Encoder().encode(userPassword.getBytes());
StringBuffer buff = new StringBuffer();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestProperty("Authorization", "Basic " + encoding);
connection.setRequestProperty("Content-Type","multipart/form-data;");
connection.setChunkedStreamingMode(4096);
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestMethod("POST");
connection.setDoOutput(true);
Blob blob = new org.teiid.core.types.BlobImpl(new org.teiid.core.types.InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new FileInputStream("C:\\sample.war");
}
});
SerialBlob slob = new SerialBlob(blob);
ObjectOutputStream outputStream = new ObjectOutputStream(connection.getOutputStream());
try {
outputStream.writeObject(slob);
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
}
BufferedReader serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = serverResponse.readLine()) != null) {
buff.append(line);
}
System.out.println(buff);
-
5. Re: Re: Does Teiid REST service support a Blob Input?
rareddy Oct 4, 2013 3:49 PM (in response to madhu.garimilla)Try
SerialBlob blob = new SerialBlob(readFileAsBytes("c:\\sample.war"); ... static byte[] readFileAsBytes(String name) throws IOException { FileInputStream in = new FileInputStream(name); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { while(true) { byte b = (byte)in.read(); if (b == -1) { break; } out.write(b); } } finally { in.close(); out.close(); } return out.toByteArray(); }
Ramesh..
-
6. Re: Re: Re: Does Teiid REST service support a Blob Input?
madhu.garimilla Oct 6, 2013 7:19 AM (in response to rareddy)Hi Ramesh, I tried using the byte array as suggested. Now the serialization error is gone but my UDF is still getting null input for Blob object. There were no exceptions reported in the jboss/eclipse consoles. Attached the Client and VDB/UDF files i am using.
-
TeiidRESTServiceClient.java 2.2 KB
-
cfar.1-vdb.xml 1.5 KB
-
UploadUDF.java 1.2 KB
-
-
7. Re: Re: Re: Does Teiid REST service support a Blob Input?
shawkins Oct 8, 2013 8:23 AM (in response to madhu.garimilla)From what I can see the code is not setup to handle binary inputs in any direct fashion. If you are handling large blobs then we'll have to look at enhancing the code.
Otherwise if your content is not too large you can set the content as a string - for example using BASE64 or HEX encoding, then use the teiid function to_bytes(string_val, 'BASE64') to convert back to bytes when you want to pass the value to your upload function.
Steve
-
8. Re: Does Teiid REST service support a Blob Input?
madhu.garimilla Oct 9, 2013 9:54 AM (in response to shawkins)Hi Steve, We are trying to upload large files as Blobs. So, we will not be able to use encoding technique. Shall i create a JIRA issue for this enhancement?
-
9. Re: Does Teiid REST service support a Blob Input?
shawkins Oct 9, 2013 10:38 AM (in response to madhu.garimilla)Yes, an issue is needed as all current parameter handling is done through strings. The RestEasy integration looks like my be a bit tricky in this case - http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-resteasy/
Steve
-
10. Re: Does Teiid REST service support a Blob Input?
madhu.garimilla Oct 10, 2013 5:44 AM (in response to shawkins)I have created the JIRA issue: [TEIID-2694] Support for Blob Input in Teiid REST services - JBoss Issue Tracker