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;
}
}
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;
}
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));
}
}
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();
}
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);
}
Aggregations