use of org.geotoolkit.ows.xml.v100.ExceptionReport in project geotoolkit by Geomatys.
the class WPS2Process method checkLegacyResult.
private Result checkLegacyResult(Result r) throws ProcessException, JAXBException, IOException, InterruptedException {
LegacyStatus legacyStatus = r.getStatus();
if (legacyStatus == null) {
return r;
}
// WPS 1 case
ProcessFailed failure = legacyStatus.getProcessFailed();
if (failure != null) {
ExceptionReport error = failure.getExceptionReport();
throw new ProcessException("Exception when executing the process.", this, error != null ? error.toException() : new RuntimeException("No exception report attached"));
}
if (legacyStatus.getProcessSucceeded() != null) {
return r;
}
final Integer currentProgress = legacyStatus.getPercentCompleted();
final String currentMessage = legacyStatus.getMessage();
if (!Objects.equals(lastProgress, currentProgress) || !Objects.equals(lastMessage, currentMessage)) {
lastProgress = currentProgress;
lastMessage = currentMessage;
fireProgressing(lastMessage, lastProgress, false);
}
registry.getClient().getLogger().log(Level.INFO, "WPS 1 Response is neither a succes nor a fail. Start querying statusLocation.");
legacyStatus.getPercentCompleted();
final Unmarshaller unmarshaller = WPSMarshallerPool.getInstance().acquireUnmarshaller();
String brutLocation = r.getStatusLocation();
if (brutLocation == null || (brutLocation = brutLocation.trim()).isEmpty()) {
throw new ProcessException("Received response is neither a success nor a fail, but no status location can be found.", this);
}
final URL statusLocation = security.secure(new URL(brutLocation));
Object tmpResponse;
// TODO: make configurable
int timeLapse = 3000;
// we tolerate a few unmarshalling or IO errors, the servers behave differentely
// and may not offer the result file right from the start
int failCount = 0;
while (true) {
synchronized (this) {
wait(timeLapse);
}
try {
tmpResponse = unmarshaller.unmarshal(security.decrypt(statusLocation.openStream()));
if (tmpResponse instanceof JAXBElement) {
tmpResponse = ((JAXBElement) tmpResponse).getValue();
}
return checkResult(tmpResponse);
} catch (UnmarshalException | IOException ex) {
if (failCount < 5) {
failCount++;
} else {
// happenning so we consider the process failed
throw ex;
}
}
}
}
use of org.geotoolkit.ows.xml.v100.ExceptionReport in project web-feature-service by 3dcitydb.
the class WFSExceptionReportHandler method getExceptionReport.
public ExceptionReport getExceptionReport(WFSException wfsException, String operationName, HttpServletRequest request, boolean writeToLog) {
preprocessWFSException(wfsException, operationName);
ExceptionReport exceptionReport = owsFactory.createExceptionReport();
exceptionReport.setLang(wfsException.getLanguage());
exceptionReport.setVersion(wfsException.getVersion());
for (WFSExceptionMessage message : wfsException.getExceptionMessages()) {
ExceptionType exceptionType = owsFactory.createExceptionType();
exceptionType.setExceptionCode(message.getExceptionCode().getValue());
exceptionType.setLocator(message.getLocator());
for (String text : message.getExceptionTexts()) {
exceptionType.getExceptionText().add(text);
if (writeToLog) {
StringBuilder logMessage = new StringBuilder().append('[').append(message.getExceptionCode().getValue()).append(", ").append(request.getRemoteAddr());
if (message.getLocator() != null)
logMessage.append(", ").append(message.getLocator());
logMessage.append("] ").append(text);
log.error(logMessage.toString());
}
}
exceptionReport.getException().add(exceptionType);
}
return exceptionReport;
}
use of org.geotoolkit.ows.xml.v100.ExceptionReport in project web-feature-service by 3dcitydb.
the class WFSExceptionReportHandler method sendErrorResponse.
public synchronized void sendErrorResponse(WFSException wfsException, String operationName, HttpServletRequest request, HttpServletResponse response) throws IOException {
ExceptionReport exceptionReport = getExceptionReport(wfsException, operationName, request, true);
response.setContentType("text/xml");
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setStatus(wfsException.getFirstExceptionMessage().getExceptionCode().getHttpStatusCode());
// prepare SAXWriter
SAXWriter saxWriter = new SAXWriter();
saxWriter.setWriteEncoding(true);
saxWriter.setIndentString(" ");
saxWriter.setPrefix(Constants.OWS_NAMESPACE_PREFIX, Constants.OWS_NAMESPACE_URI);
saxWriter.setSchemaLocation(Constants.OWS_NAMESPACE_URI, Constants.OWS_SCHEMA_LOCATION);
// marshall JAXB object
try {
saxWriter.setOutput(response.getWriter());
Marshaller marshaller = cityGMLBuilder.getJAXBContext().createMarshaller();
marshaller.marshal(exceptionReport, saxWriter);
} catch (JAXBException | IOException e) {
if (!response.isCommitted())
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.
the class WfsResponseExceptionMapper method fromResponse.
@Override
public WfsException fromResponse(Response response) {
WfsException wfsEx = null;
if (response != null) {
if (response.getEntity() instanceof InputStream) {
String msg = null;
try {
InputStream is = (InputStream) response.getEntity();
is.reset();
msg = IOUtils.toString(is);
} catch (IOException e) {
LOGGER.info("Unable to parse exception report: {}", e.getMessage());
LOGGER.debug("Unable to parse exception report", e);
}
if (msg != null) {
try {
JAXBElementProvider<ExceptionReport> provider = new JAXBElementProvider<>();
Unmarshaller um = provider.getJAXBContext(ExceptionReport.class, ExceptionReport.class).createUnmarshaller();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(msg));
ExceptionReport report = (ExceptionReport) um.unmarshal(xmlStreamReader);
wfsEx = convertToWfsException(report);
} catch (JAXBException | XMLStreamException e) {
wfsEx = new WfsException("Error parsing Response: " + msg, e);
}
} else {
wfsEx = new WfsException("Error reading Response");
}
} else {
wfsEx = new WfsException("Error reading response, entity type not understood: " + response.getEntity().getClass().getName());
}
wfsEx.setHttpStatus(response.getStatus());
} else {
wfsEx = new WfsException("Error handling response, response is null");
}
return wfsEx;
}
use of org.geotoolkit.ows.xml.v100.ExceptionReport in project ddf by codice.
the class CswExceptionMapperTest method testCswExceptionToServiceExceptionReportWithLocatorAndCode.
@Test
public void testCswExceptionToServiceExceptionReportWithLocatorAndCode() {
CswException exception = new CswException(SERVICE_EXCEPTION_MSG, Status.BAD_REQUEST.getStatusCode(), EXCEPTION_CODE, LOCATOR);
ExceptionMapper<Throwable> exceptionMapper = new CswExceptionMapper();
Response response = exceptionMapper.toResponse(exception);
assertThat(response.getEntity(), is(instanceOf(ExceptionReport.class)));
ExceptionReport exceptionReport = (ExceptionReport) response.getEntity();
assertThat(Status.BAD_REQUEST.getStatusCode(), is(response.getStatus()));
assertThat(SERVICE_EXCEPTION_MSG, is(exceptionReport.getException().get(0).getExceptionText().get(0)));
assertThat(EXCEPTION_CODE, is(exceptionReport.getException().get(0).getExceptionCode()));
assertThat(LOCATOR, is(exceptionReport.getException().get(0).getLocator()));
}
Aggregations