use of io.javalin.http.InternalServerErrorResponse in project cwms-radar-api by USACE.
the class XMLv1 method format.
@Override
public String format(CwmsDTO dto) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (dto instanceof Office) {
mar.marshal(new XMLv1Office(Arrays.asList((Office) dto)), pw);
return sw.toString();
} else {
mar.marshal(dto, pw);
return sw.toString();
}
} catch (JAXBException jaxb) {
String msg = dto != null ? "Error rendering '" + dto.toString() + "' to XML" : "Null element passed to formatter";
logger.log(Level.WARNING, msg, jaxb);
throw new InternalServerErrorResponse("Invalid Parameters");
}
}
use of io.javalin.http.InternalServerErrorResponse in project cwms-radar-api by USACE.
the class XMLv2 method format.
@Override
public String format(CwmsDTO dto) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
mar.marshal(dto, pw);
return sw.toString();
} catch (JAXBException jaxb) {
String msg = dto != null ? "Error rendering '" + dto.toString() + "' to XML" : "Null element passed to formatter";
logger.log(Level.WARNING, msg, jaxb);
throw new InternalServerErrorResponse("Invalid Parameters");
}
}
use of io.javalin.http.InternalServerErrorResponse in project cwms-radar-api by USACE.
the class XMLv1 method format.
@Override
// we're ALWAYS checking before conversion in this function
@SuppressWarnings("unchecked")
public String format(List<? extends CwmsDTO> dtoList) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (!dtoList.isEmpty() && dtoList.get(0) instanceof Office) {
mar.marshal(new XMLv1Office((List<Office>) dtoList), pw);
return sw.toString();
}
} catch (Exception err) {
logger.log(Level.WARNING, "Error doing XML format of office list", err);
throw new InternalServerErrorResponse("Invalid Parameters");
}
throw new UnsupportedOperationException("Unable to process your request");
}
Aggregations