Skip to content

Commit

Permalink
Merge pull request #588 from Teiid-Designer/teiid-3178
Browse files Browse the repository at this point in the history
Corrected logic for handling inserts
  • Loading branch information
blafond committed Jan 15, 2018
2 parents 33030d2 + c2cd6c1 commit 55c734f
Showing 1 changed file with 34 additions and 3 deletions.
Expand Up @@ -115,11 +115,11 @@ private Element findElement( Node node ) {
return (Element)node;
}

protected Map<String, String> getJSONInputs( StreamingOutput is, String charset ) {
protected Map<String, String> getJSONInputs( InputStream is, String charset ) {
Map<String, String> parameters = getParameterMap();

try {
String jsonString = convertStreamToString(is, charset);
String jsonString = convertInputStreamToString(is, charset);

// Do this to validate the JSON string. If we don't blow up, then we are good.
new JSONObject(jsonString);
Expand All @@ -129,6 +129,37 @@ protected Map<String, String> getJSONInputs( StreamingOutput is, String charset
}
return parameters;
}

public String convertInputStreamToString( InputStream is, String charset) {
/*
* To convert the InputStream to String we use the
* Reader.read(char[] buffer) method.
*/

if (is != null) {

ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try {
int nRead;
byte[] data = new byte[1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}

buffer.flush();
byte[] byteArray = buffer.toByteArray();

return new String(byteArray, charset);

}catch(Exception ioe){
throw new WebApplicationException(ioe, Response.Status.INTERNAL_SERVER_ERROR);
}

}

return ""; //$NON-NLS-1$

}

public String convertStreamToString( StreamingOutput is, String charset) {
/*
Expand All @@ -141,7 +172,7 @@ public String convertStreamToString( StreamingOutput is, String charset) {
try {

is.write(output);
String string = new String(output.toByteArray(), charset);
//String string = new String(output.toByteArray(), charset);

}catch(Exception ioe){
throw new WebApplicationException(ioe, Response.Status.INTERNAL_SERVER_ERROR);
Expand Down

0 comments on commit 55c734f

Please sign in to comment.