use of org.apache.cxf.interceptor.Fault in project midpoint by Evolveum.
the class ModelWebService method throwFault.
public void throwFault(Throwable ex, OperationResult result) throws FaultMessage {
if (result != null) {
result.recordFatalError(ex.getMessage(), ex);
}
FaultType faultType;
if (ex instanceof ObjectNotFoundException) {
faultType = new ObjectNotFoundFaultType();
} else if (ex instanceof IllegalArgumentException) {
faultType = new IllegalArgumentFaultType();
} else if (ex instanceof ObjectAlreadyExistsException) {
faultType = new ObjectAlreadyExistsFaultType();
} else if (ex instanceof CommunicationException) {
faultType = new CommunicationFaultType();
} else if (ex instanceof ConfigurationException) {
faultType = new ConfigurationFaultType();
} else if (ex instanceof ExpressionEvaluationException) {
faultType = new SystemFaultType();
} else if (ex instanceof SchemaException) {
faultType = new SchemaViolationFaultType();
} else if (ex instanceof PolicyViolationException) {
faultType = new PolicyViolationFaultType();
} else if (ex instanceof AuthorizationException) {
throw new Fault(new WSSecurityException(WSSecurityException.ErrorCode.FAILED_AUTHENTICATION), WSSecurityException.ErrorCode.FAILED_AUTHENTICATION.getQName());
} else if (ex instanceof SecurityViolationException) {
throw new Fault(new WSSecurityException(WSSecurityException.ErrorCode.FAILURE), WSSecurityException.ErrorCode.FAILURE.getQName());
} else {
faultType = new SystemFaultType();
}
faultType.setMessage(ex.getMessage());
if (result != null) {
faultType.setOperationResult(result.createOperationResultType());
}
FaultMessage fault = new FaultMessage(ex.getMessage(), faultType, ex);
LOGGER.trace("Throwing fault message type: {}", faultType.getClass(), fault);
throw fault;
}
use of org.apache.cxf.interceptor.Fault in project midpoint by Evolveum.
the class ReportWebService method processReport.
@Override
public ObjectListType processReport(String query, RemoteReportParametersType parameters, SelectorQualifiedGetOptionsType options) {
try {
Map<QName, Object> parametersMap = getParamsMap(parameters);
ObjectQuery q = reportService.parseQuery(query, parametersMap);
Collection<PrismObject<? extends ObjectType>> resultList = reportService.searchObjects(q, MiscSchemaUtil.optionsTypeToOptions(options));
return createObjectListType(resultList);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO Auto-generated catch block
throw new Fault(e);
}
}
use of org.apache.cxf.interceptor.Fault in project midpoint by Evolveum.
the class ReportWebService method evaluateScript.
@Override
public ObjectListType evaluateScript(String script, RemoteReportParametersType parameters) {
try {
Map<QName, Object> params = getParamsMap(parameters);
Collection resultList = reportService.evaluateScript(script, params);
return createObjectListType(resultList);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
// TODO Auto-generated catch block
throw new Fault(e);
}
}
use of org.apache.cxf.interceptor.Fault in project midpoint by Evolveum.
the class CustomWrappedOutInterceptor method writeParts.
@Override
protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
// TODO Auto-generated method stub
OutputStream out = message.getContent(OutputStream.class);
XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
Service service = exchange.getService();
XMLStreamWriter xmlWriter = origXmlWriter;
CachingXmlEventWriter cache = null;
Object en = message.getContextualProperty(OUT_BUFFERING);
boolean allowBuffer = true;
boolean buffer = false;
if (en != null) {
buffer = Boolean.TRUE.equals(en) || "true".equals(en);
allowBuffer = !(Boolean.FALSE.equals(en) || "false".equals(en));
}
// need to cache the events in case validation fails or buffering is enabled
if (buffer || (allowBuffer && shouldValidate(message) && !isRequestor(message))) {
cache = new CachingXmlEventWriter();
try {
cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
} catch (XMLStreamException e) {
//ignorable, will just get extra namespace decls
}
xmlWriter = cache;
out = null;
}
if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.isTrue(message.getContextualProperty(DISABLE_OUTPUTSTREAM_OPTIMIZATION))) {
if (xmlWriter != null) {
try {
xmlWriter.writeCharacters("");
xmlWriter.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
osWriter.write(o, part, out);
}
}
} else {
DataWriter<XMLStreamWriter> dataWriter = new CustomDataWriter(prismContext);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
dataWriter.write(o, part, xmlWriter);
}
}
}
if (cache != null) {
try {
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origXmlWriter);
}
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
}
Aggregations