Search in sources :

Example 16 with Fault

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;
}
Also used : Fault(org.apache.cxf.interceptor.Fault) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException)

Example 17 with 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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) Fault(org.apache.cxf.interceptor.Fault) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 18 with Fault

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) PrismObject(com.evolveum.midpoint.prism.PrismObject) Fault(org.apache.cxf.interceptor.Fault)

Example 19 with Fault

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);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

Fault (org.apache.cxf.interceptor.Fault)19 QName (javax.xml.namespace.QName)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 Message (org.apache.cxf.message.Message)4 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)4 Element (org.w3c.dom.Element)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 OutputStream (java.io.OutputStream)3 SOAPException (javax.xml.soap.SOAPException)3 Document (org.w3c.dom.Document)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)1