Search in sources :

Example 1 with InternalServerErrorResponse

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");
    }
}
Also used : Office(cwms.radar.data.dto.Office) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) InternalServerErrorResponse(io.javalin.http.InternalServerErrorResponse) PrintWriter(java.io.PrintWriter)

Example 2 with InternalServerErrorResponse

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");
    }
}
Also used : StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) InternalServerErrorResponse(io.javalin.http.InternalServerErrorResponse) PrintWriter(java.io.PrintWriter)

Example 3 with InternalServerErrorResponse

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");
}
Also used : Office(cwms.radar.data.dto.Office) StringWriter(java.io.StringWriter) InternalServerErrorResponse(io.javalin.http.InternalServerErrorResponse) List(java.util.List) JAXBException(javax.xml.bind.JAXBException) PrintWriter(java.io.PrintWriter)

Aggregations

InternalServerErrorResponse (io.javalin.http.InternalServerErrorResponse)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 JAXBException (javax.xml.bind.JAXBException)3 Office (cwms.radar.data.dto.Office)2 List (java.util.List)1