Search in sources :

Example 61 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class AttachmentUtil method createMtomAttachment.

public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS, byte[] data, int offset, int length, int threshold) {
    if (!isXop || length <= threshold) {
        return null;
    }
    if (mimeType == null) {
        mimeType = "application/octet-stream";
    }
    ByteDataSource source = new ByteDataSource(data, offset, length);
    source.setContentType(mimeType);
    DataHandler handler = new DataHandler(source);
    String id;
    try {
        id = AttachmentUtil.createContentID(elementNS);
    } catch (UnsupportedEncodingException e) {
        throw new Fault(e);
    }
    AttachmentImpl att = new AttachmentImpl(id, handler);
    att.setXOP(isXop);
    return att;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) Fault(org.apache.cxf.interceptor.Fault) DataHandler(javax.activation.DataHandler)

Example 62 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class AbstractInvoker method createFault.

protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean checked) {
    if (checked) {
        return new Fault(ex);
    }
    String message = (ex == null) ? "" : ex.getMessage();
    String method = (m == null) ? "<null>" : m.toString();
    return new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, message, method, params), ex);
}
Also used : Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault)

Example 63 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class AbstractInvoker method invoke.

public Object invoke(Exchange exchange, Object o) {
    final Object serviceObject = getServiceObject(exchange);
    try {
        BindingOperationInfo bop = exchange.getBindingOperationInfo();
        MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
        Method m = bop == null ? null : md.getMethod(bop);
        if (m == null && bop == null) {
            LOG.severe(new Message("MISSING_BINDING_OPERATION", LOG).toString());
            throw new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, "No binding operation info", "unknown method", "unknown"));
        }
        List<Object> params = null;
        if (o instanceof List) {
            params = CastUtils.cast((List<?>) o);
        } else if (o != null) {
            params = new MessageContentsList(o);
        }
        m = adjustMethodAndParams(m, exchange, params, serviceObject.getClass());
        // Method m = (Method)bop.getOperationInfo().getProperty(Method.class.getName());
        m = matchMethod(m, serviceObject);
        return invoke(exchange, serviceObject, m, params);
    } finally {
        releaseServiceObject(exchange, serviceObject);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.common.i18n.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) Fault(org.apache.cxf.interceptor.Fault) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) Method(java.lang.reflect.Method)

Example 64 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class PerRequestFactory method create.

public Object create(Exchange ex) throws Throwable {
    try {
        if (svcClass.isInterface()) {
            throw new Fault(new Message("SVC_CLASS_IS_INTERFACE", BUNDLE, svcClass.getName()));
        }
        if (Modifier.isAbstract(svcClass.getModifiers())) {
            throw new Fault(new Message("SVC_CLASS_IS_ABSTRACT", BUNDLE, svcClass.getName()));
        }
        Object o = svcClass.newInstance();
        Bus b = ex.getBus();
        ResourceManager resourceManager = b.getExtension(ResourceManager.class);
        if (resourceManager != null) {
            ResourceInjector injector = new ResourceInjector(resourceManager);
            injector.inject(o);
            injector.construct(o);
        }
        return o;
    } catch (InstantiationException e) {
        throw new Fault(new Message("COULD_NOT_INSTANTIATE", BUNDLE), e);
    } catch (IllegalAccessException e) {
        throw new Fault(new Message("ILLEGAL_ACCESS", BUNDLE), e);
    }
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) ResourceManager(org.apache.cxf.resource.ResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector)

Example 65 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class JAXRSUtils method readFromMessageBody.

private static Object readFromMessageBody(Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType contentType, OperationResourceInfo ori, Message m) throws IOException, WebApplicationException {
    List<MediaType> types = JAXRSUtils.intersectMimeTypes(ori.getConsumeTypes(), contentType);
    final ProviderFactory pf = ServerProviderFactory.getInstance(m);
    for (MediaType type : types) {
        List<ReaderInterceptor> readers = pf.createMessageBodyReaderInterceptor(targetTypeClass, parameterType, parameterAnnotations, type, m, true, ori.getNameBindings());
        if (readers != null) {
            try {
                return readFromMessageBodyReader(readers, targetTypeClass, parameterType, parameterAnnotations, is, type, m);
            } catch (IOException e) {
                if (e.getClass().getName().equals(NO_CONTENT_EXCEPTION)) {
                    throw ExceptionUtils.toBadRequestException(e, null);
                }
                throw e;
            } catch (WebApplicationException ex) {
                throw ex;
            } catch (Exception ex) {
                throw new Fault(ex);
            }
        }
    }
    logMessageHandlerProblem("NO_MSG_READER", targetTypeClass, contentType);
    throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
}
Also used : ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) WebApplicationException(javax.ws.rs.WebApplicationException) ProviderFactory(org.apache.cxf.jaxrs.provider.ProviderFactory) ServerProviderFactory(org.apache.cxf.jaxrs.provider.ServerProviderFactory) MediaType(javax.ws.rs.core.MediaType) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

Fault (org.apache.cxf.interceptor.Fault)283 IOException (java.io.IOException)74 QName (javax.xml.namespace.QName)56 Message (org.apache.cxf.message.Message)52 XMLStreamException (javax.xml.stream.XMLStreamException)50 Element (org.w3c.dom.Element)42 Message (org.apache.cxf.common.i18n.Message)34 Exchange (org.apache.cxf.message.Exchange)30 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)30 SOAPException (javax.xml.soap.SOAPException)28 InputStream (java.io.InputStream)27 ArrayList (java.util.ArrayList)27 XMLStreamReader (javax.xml.stream.XMLStreamReader)26 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)26 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)25 Test (org.junit.Test)24 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)23 List (java.util.List)21 SOAPMessage (javax.xml.soap.SOAPMessage)21 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)21