Search in sources :

Example 1 with XmlInspectionService

use of io.atlasmap.xml.inspect.XmlInspectionService in project atlasmap by atlasmap.

the class XmlService method inspectClass.

public Response inspectClass(XmlInspectionRequest request) {
    long startTime = System.currentTimeMillis();
    XmlInspectionResponse response = new XmlInspectionResponse();
    XmlDocument d = null;
    try {
        if (request.getType() == null) {
            response.setErrorMessage("Instance or Schema type must be specified in request");
        } else {
            XmlInspectionService s = new XmlInspectionService();
            switch(request.getType()) {
                case INSTANCE:
                    d = s.inspectXmlDocument(request.getXmlData());
                    break;
                case SCHEMA:
                    d = s.inspectSchema(request.getXmlData());
                    break;
                default:
                    response.setErrorMessage("Unsupported inspection type: " + request.getType());
                    break;
            }
        }
    } catch (Exception e) {
        LOG.error("Error inspecting xml: " + e.getMessage(), e);
        response.setErrorMessage(e.getMessage());
    } finally {
        response.setExecutionTime(System.currentTimeMillis() - startTime);
    }
    response.setXmlDocument(d);
    return Response.ok().entity(toJson(response)).build();
}
Also used : XmlInspectionService(io.atlasmap.xml.inspect.XmlInspectionService) XmlDocument(io.atlasmap.xml.v2.XmlDocument) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) XmlInspectionResponse(io.atlasmap.xml.v2.XmlInspectionResponse)

Example 2 with XmlInspectionService

use of io.atlasmap.xml.inspect.XmlInspectionService in project atlasmap by atlasmap.

the class XmlService method getClass.

@GET
@Path("/inspect")
@Produces(MediaType.APPLICATION_JSON)
public Response getClass(@QueryParam("uri") String uri, @QueryParam("type") String type) {
    XmlDocument d = null;
    try {
        if (type == null) {
            throw new Exception("uri and type parameters must be specified");
        }
        InspectionType inspectType = InspectionType.valueOf(type);
        XmlInspectionService s = new XmlInspectionService();
        switch(inspectType) {
            case INSTANCE:
                d = s.inspectXmlDocument(new File(uri));
                break;
            case SCHEMA:
                d = s.inspectSchema(new File(uri));
                break;
            default:
                throw new Exception("Unknown type specified: " + type);
        }
    } catch (Exception e) {
        LOG.error("Error inspecting xml: " + e.getMessage(), e);
    }
    return Response.ok().entity(toJson(d)).build();
}
Also used : InspectionType(io.atlasmap.xml.v2.InspectionType) XmlInspectionService(io.atlasmap.xml.inspect.XmlInspectionService) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) ApplicationPath(javax.ws.rs.ApplicationPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 XmlInspectionService (io.atlasmap.xml.inspect.XmlInspectionService)2 XmlDocument (io.atlasmap.xml.v2.XmlDocument)2 IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 InspectionType (io.atlasmap.xml.v2.InspectionType)1 XmlInspectionResponse (io.atlasmap.xml.v2.XmlInspectionResponse)1 File (java.io.File)1 ApplicationPath (javax.ws.rs.ApplicationPath)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1