Search in sources :

Example 1 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project metro-jax-ws by eclipse-ee4j.

the class AbstractReferenceFinderImpl method startElement.

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    super.startElement(namespaceURI, localName, qName, atts);
    String relativeRef = findExternalResource(namespaceURI, localName, atts);
    // non found
    if (relativeRef == null)
        return;
    try {
        // absolutize URL.
        assert locator != null;
        String lsi = locator.getSystemId();
        String ref;
        if (lsi.startsWith("jar:")) {
            int bangIdx = lsi.indexOf('!');
            if (bangIdx > 0) {
                ref = new URL(new URL(lsi), relativeRef).toString();
            } else
                ref = relativeRef;
        } else
            ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
        // then parse this schema as well,
        // but don't mark this document as a root.
        parent.parse(ref, false);
    } catch (URISyntaxException e) {
        SAXParseException spe = new SAXParseException2(WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef, e.getMessage()), locator, e);
        fatalError(spe);
        throw spe;
    } catch (IOException e) {
        SAXParseException spe = new SAXParseException2(WsdlMessages.ABSTRACT_REFERENCE_FINDER_IMPL_UNABLE_TO_PARSE(relativeRef, e.getMessage()), locator, e);
        fatalError(spe);
        throw spe;
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) SAXParseException(org.xml.sax.SAXParseException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL)

Example 2 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project aai-graphadmin by onap.

the class ExceptionHandler method toResponse.

/**
 * @{inheritDoc}
 */
@Override
public Response toResponse(Exception exception) {
    Response response = null;
    ArrayList<String> templateVars = new ArrayList<String>();
    // with a linked exception
    if (exception instanceof WebApplicationException) {
        WebApplicationException e = (WebApplicationException) exception;
        if (e.getCause() != null) {
            if (e.getCause() instanceof SAXParseException2) {
                templateVars.add("UnmarshalException");
                AAIException ex = new AAIException("AAI_4007", exception);
                response = Response.status(400).entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)).build();
            }
        }
    } else if (exception instanceof JsonParseException) {
        // jackson does it differently so we get the direct JsonParseException
        templateVars.add("JsonParseException");
        AAIException ex = new AAIException("AAI_4007", exception);
        response = Response.status(400).entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)).build();
    } else if (exception instanceof JsonMappingException) {
        // jackson does it differently so we get the direct JsonParseException
        templateVars.add("JsonMappingException");
        AAIException ex = new AAIException("AAI_4007", exception);
        response = Response.status(400).entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)).build();
    }
    // it didn't get set above, we wrap a general fault here
    if (response == null) {
        Exception actual_e = exception;
        if (exception instanceof WebApplicationException) {
            WebApplicationException e = (WebApplicationException) exception;
            response = e.getResponse();
        } else {
            templateVars.add(request.getMethod());
            templateVars.add("unknown");
            AAIException ex = new AAIException("AAI_4000", actual_e);
            List<MediaType> mediaTypes = headers.getAcceptableMediaTypes();
            int setError = 0;
            for (MediaType mediaType : mediaTypes) {
                if (MediaType.APPLICATION_XML_TYPE.isCompatible(mediaType)) {
                    response = Response.status(400).type(MediaType.APPLICATION_XML_TYPE).entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)).build();
                    setError = 1;
                }
            }
            if (setError == 0) {
                response = Response.status(400).type(MediaType.APPLICATION_JSON_TYPE).entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)).build();
            }
        }
    }
    return response;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SAXParseException2(com.sun.istack.SAXParseException2) ArrayList(java.util.ArrayList) JsonParseException(com.fasterxml.jackson.core.JsonParseException) WebApplicationException(javax.ws.rs.WebApplicationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AAIException(org.onap.aai.exceptions.AAIException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Response(javax.ws.rs.core.Response) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AAIException(org.onap.aai.exceptions.AAIException) MediaType(javax.ws.rs.core.MediaType)

Example 3 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class SchemaCompilerImpl method parseSchema.

@Override
public void parseSchema(String systemId, Element element) {
    checkAbsoluteness(systemId);
    try {
        DOMScanner scanner = new DOMScanner();
        // use a locator that sets the system ID correctly
        // so that we can resolve relative URLs in most of the case.
        // it still doesn't handle xml:base and XInclude and all those things
        // correctly. There's just no way to make all those things work with DOM!
        LocatorImpl loc = new LocatorImpl();
        loc.setSystemId(systemId);
        scanner.setLocator(loc);
        scanner.setContentHandler(getParserHandler(systemId));
        scanner.scan(element);
    } catch (SAXException e) {
        // since parsing DOM shouldn't cause a SAX exception
        // and our handler will never throw it, it's not clear
        // if this will ever happen.
        fatalError(new SAXParseException2(e.getMessage(), null, systemId, -1, -1, e));
    }
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) DOMScanner(org.glassfish.jaxb.core.unmarshaller.DOMScanner) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXException(org.xml.sax.SAXException)

Example 4 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class BindInfo method parse.

/**
 * Parses an InputSource into dom4j Document.
 * Returns null in case of an exception.
 */
private static Document parse(Model model, InputSource is, ErrorReceiver receiver) throws AbortException {
    try {
        ValidatorHandler validator = bindingFileSchema.newValidator();
        // set up the pipe line as :
        // /-> extensionChecker -> validator
        // parser-> -<
        // \-> DOM builder
        SAXParserFactory pf = XmlFactory.createParserFactory(model.options.disableXmlSecurity);
        DocumentBuilderFactory domFactory = XmlFactory.createDocumentBuilderFactory(model.options.disableXmlSecurity);
        DOMBuilder builder = new DOMBuilder(domFactory);
        ErrorReceiverFilter controller = new ErrorReceiverFilter(receiver);
        validator.setErrorHandler(controller);
        XMLReader reader = pf.newSAXParser().getXMLReader();
        reader.setErrorHandler(controller);
        DTDExtensionBindingChecker checker = new DTDExtensionBindingChecker("", model.options, controller);
        checker.setContentHandler(validator);
        reader.setContentHandler(new ForkContentHandler(checker, builder));
        reader.parse(is);
        if (controller.hadError())
            throw new AbortException();
        return (Document) builder.getDOM();
    } catch (IOException | SAXException | ParserConfigurationException e) {
        receiver.error(new SAXParseException2(e.getMessage(), null, e));
    }
    throw new AbortException();
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ValidatorHandler(javax.xml.validation.ValidatorHandler) SAXParseException2(com.sun.istack.SAXParseException2) ForkContentHandler(com.sun.tools.xjc.util.ForkContentHandler) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) AbortException(com.sun.tools.xjc.AbortException)

Example 5 with SAXParseException2

use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.

the class Internalizer method reportError.

private void reportError(Element errorSource, String formattedMsg, Exception nestedException) {
    SAXParseException e = new SAXParseException2(formattedMsg, forest.locatorTable.getStartLocation(errorSource), nestedException);
    errorHandler.error(e);
}
Also used : SAXParseException2(com.sun.istack.SAXParseException2) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

SAXParseException2 (com.sun.istack.SAXParseException2)11 SAXParseException (org.xml.sax.SAXParseException)7 IOException (java.io.IOException)4 SAXException (org.xml.sax.SAXException)3 AbortException (com.sun.tools.xjc.AbortException)2 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JCodeModel (com.sun.codemodel.JCodeModel)1 Model (com.sun.tools.xjc.model.Model)1 ModelChecker (com.sun.tools.xjc.reader.ModelChecker)1 Ring (com.sun.tools.xjc.reader.Ring)1 ForkContentHandler (com.sun.tools.xjc.util.ForkContentHandler)1 DTDParser (com.sun.xml.dtdparser.DTDParser)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 WebApplicationException (javax.ws.rs.WebApplicationException)1