return null;
}
} else {
try {
inputFetchedData = FetchedData.fromReader(new StringReader(content),
new InputSource(inputUri), expectedInputContentType,
Charsets.UTF_8.displayName());
} catch (IOException e) {
return null;
}
}
}
if (!typeCheck.check(
expectedInputContentType,
inputFetchedData.getContentType())) {
mq.addMessage(
ServiceMessageType.UNEXPECTED_INPUT_MIME_TYPE,
MessagePart.Factory.valueOf(expectedInputContentType),
MessagePart.Factory.valueOf(inputFetchedData.getContentType()));
return null;
}
String transformName = CajaArguments.TRANSFORM.get(args);
Transform transform = null;
if (transformName != null) {
try {
transform = Transform.valueOf(transformName);
} catch (Exception e) {
mq.addMessage(
ServiceMessageType.INVALID_ARGUMENT,
MessagePart.Factory.valueOf(transformName),
MessagePart.Factory.valueOf(CajaArguments.TRANSFORM.toString()));
return null;
}
}
// TODO(jasvir): Change CajaArguments to handle >1 occurrence of arg
String directiveName = CajaArguments.DIRECTIVE.get(args);
List<Directive> directive = Lists.newArrayList();
if (directiveName != null) {
try {
directive.add(Directive.valueOf(directiveName));
} catch (Exception e) {
mq.addMessage(
ServiceMessageType.INVALID_ARGUMENT,
MessagePart.Factory.valueOf(directiveName),
MessagePart.Factory.valueOf(CajaArguments.DIRECTIVE.toString()));
return null;
}
}
ByteArrayOutputStream intermediateResponse = new ByteArrayOutputStream();
Pair<String, String> contentInfo;
try {
contentInfo = applyHandler(
inputUri,
transform,
directive,
args,
inputFetchedData.getContentType(),
inputFetchedData,
intermediateResponse,
mq);
} catch (UnsupportedContentTypeException e) {
mq.addMessage(ServiceMessageType.UNSUPPORTED_CONTENT_TYPES);
return null;
} catch (RuntimeException e) {
mq.addMessage(
ServiceMessageType.EXCEPTION_IN_SERVICE,
MessagePart.Factory.valueOf(e.toString()));
return null;
}
return FetchedData.fromBytes(
intermediateResponse.toByteArray(),
contentInfo.a,
contentInfo.b,
new InputSource(inputUri));
}