// if length is not known, use a default value
length = (length > 0 ? length : Tools.DEFAULT_BUFFER_SIZE * 8);
byte[] bytes = IOTools.getBytes(urlConnection.getInputStream(), length);
ResourceContext resourceContext;
MediaType type = MediaType.create(contentType);
// GTNCOMMON-14
if (isInterpretableAsText(type))
{
// determine the charset of the content, if any
String charset = "UTF-8";
if (contentType != null)
{
for (String part : contentType.split(";"))
{
if (part.startsWith("charset="))
{
charset = part.substring("charset=".length());
}
}
}
String markup = new String(bytes, charset);
resourceContext = WSRPTypeFactory.createResourceContext(contentType, markup, null);
// process markup if needed
SubtypeDef subtype = type.getSubtype();
if (SubtypeDef.HTML.equals(subtype) || SubtypeDef.CSS.equals(subtype) || subtype.getName().contains("javascript") || SubtypeDef.XML.equals(subtype))
{
resourceContext.setRequiresRewriting(true);
}
}
else
{
resourceContext = WSRPTypeFactory.createResourceContext(contentType, null, bytes);
resourceContext.setRequiresRewriting(false);
}
return WSRPTypeFactory.createResourceResponse(resourceContext);
}