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