diff --git a/plugins/org.teiid.designer.webservice.lib/rest_war_resources/webapps/WEB-INF/classes/org/teiid/rest/services/ResourceTemplate.java b/plugins/org.teiid.designer.webservice.lib/rest_war_resources/webapps/WEB-INF/classes/org/teiid/rest/services/ResourceTemplate.java index d2ad5e9857..de67b9503c 100644 --- a/plugins/org.teiid.designer.webservice.lib/rest_war_resources/webapps/WEB-INF/classes/org/teiid/rest/services/ResourceTemplate.java +++ b/plugins/org.teiid.designer.webservice.lib/rest_war_resources/webapps/WEB-INF/classes/org/teiid/rest/services/ResourceTemplate.java @@ -115,11 +115,11 @@ private Element findElement( Node node ) { return (Element)node; } - protected Map getJSONInputs( StreamingOutput is, String charset ) { + protected Map getJSONInputs( InputStream is, String charset ) { Map 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); @@ -129,6 +129,37 @@ protected Map 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) { /* @@ -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);