use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class FaultOutInterceptor method getFaultForClass.
/**
* Find the correct Fault part for a particular exception.
*
* @param op
* @param class1
*/
public FaultInfo getFaultForClass(BindingOperationInfo op, Class<?> class1) {
FaultInfo selectedFaultInfo = null;
Class<?> selectedFaultInfoClass = null;
for (BindingFaultInfo bfi : op.getFaults()) {
FaultInfo faultInfo = bfi.getFaultInfo();
Class<?> c = (Class<?>) faultInfo.getProperty(Class.class.getName());
if (c != null && c.isAssignableFrom(class1) && (selectedFaultInfo == null || (selectedFaultInfoClass != null && selectedFaultInfoClass.isAssignableFrom(c)))) {
selectedFaultInfo = faultInfo;
selectedFaultInfoClass = c;
}
}
return selectedFaultInfo;
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ServiceModelVisitor method visitOperation.
private void visitOperation(OperationInfo o) {
MessageInfo in = o.getInput();
if (in != null) {
begin(in);
for (MessagePartInfo part : in.getMessageParts()) {
begin(part);
end(part);
}
end(in);
}
MessageInfo out = o.getOutput();
if (out != null) {
begin(out);
for (MessagePartInfo part : out.getMessageParts()) {
begin(part);
end(part);
}
end(out);
}
for (FaultInfo f : o.getFaults()) {
begin(f);
for (MessagePartInfo part : f.getMessageParts()) {
begin(part);
end(part);
}
end(f);
}
if (o.isUnwrappedCapable()) {
OperationInfo uop = o.getUnwrappedOperation();
begin(uop);
visitOperation(o.getUnwrappedOperation());
end(uop);
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method setFaultClassInfo.
private void setFaultClassInfo(OperationInfo o, Method selected) {
Class<?>[] types = selected.getExceptionTypes();
Map<FaultInfo, List<MessagePartInfo>> mpiMap = null;
if (types.length > 0) {
// early iterate over FaultInfo before cycling on exception types
// as fi.getMessageParts() is very time-consuming due to elements
// copy in ArrayList constructor
mpiMap = new HashMap<>();
for (FaultInfo fi : o.getFaults()) {
mpiMap.put(fi, fi.getMessageParts());
}
}
for (int i = 0; i < types.length; i++) {
Class<?> exClass = types[i];
Class<?> beanClass = getBeanClass(exClass);
if (beanClass == null) {
continue;
}
QName name = getFaultName(o.getInterface(), o, exClass, beanClass);
for (Entry<FaultInfo, List<MessagePartInfo>> entry : mpiMap.entrySet()) {
FaultInfo fi = entry.getKey();
List<MessagePartInfo> mpis = entry.getValue();
if (mpis.size() != 1) {
Message message = new Message("NO_FAULT_PART", LOG, fi.getFaultName());
LOG.log(Level.WARNING, message.toString());
}
for (MessagePartInfo mpi : mpis) {
String ns = null;
if (mpi.isElement()) {
ns = mpi.getElementQName().getNamespaceURI();
} else {
ns = mpi.getTypeQName().getNamespaceURI();
}
if (mpi.getConcreteName().getLocalPart().equals(name.getLocalPart()) && name.getNamespaceURI().equals(ns)) {
fi.setProperty(Class.class.getName(), exClass);
mpi.setTypeClass(beanClass);
sendEvent(Event.OPERATIONINFO_FAULT, o, exClass, fi);
}
}
}
}
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method addFault.
protected FaultInfo addFault(final InterfaceInfo service, final OperationInfo op, Class<?> exClass) {
Class<?> beanClass = getBeanClass(exClass);
if (beanClass == null) {
return null;
}
String faultMsgName = null;
for (AbstractServiceConfiguration c : serviceConfigurations) {
faultMsgName = c.getFaultMessageName(op, exClass, beanClass);
if (faultMsgName != null) {
break;
}
}
if (faultMsgName == null) {
faultMsgName = exClass.getSimpleName();
}
QName faultName = getFaultName(service, op, exClass, beanClass);
FaultInfo fi = op.addFault(new QName(op.getName().getNamespaceURI(), faultMsgName), new QName(op.getName().getNamespaceURI(), faultMsgName));
fi.setProperty(Class.class.getName(), exClass);
fi.setProperty("elementName", faultName);
MessagePartInfo mpi = fi.addMessagePart(new QName(faultName.getNamespaceURI(), exClass.getSimpleName()));
mpi.setElementQName(faultName);
mpi.setTypeClass(beanClass);
sendEvent(Event.OPERATIONINFO_FAULT, op, exClass, fi);
return fi;
}
use of org.apache.cxf.service.model.FaultInfo in project cxf by apache.
the class ColocUtil method isSameFaultInfo.
public static boolean isSameFaultInfo(Collection<FaultInfo> fil1, Collection<FaultInfo> fil2) {
if ((fil1 == null && fil2 != null) || (fil1 != null && fil2 == null)) {
return false;
}
if (fil1 != null && fil2 != null) {
if (fil1.size() != fil2.size()) {
return false;
}
for (FaultInfo fi1 : fil1) {
Iterator<FaultInfo> iter = fil2.iterator();
Class<?> fiClass1 = fi1.getProperty(Class.class.getName(), Class.class);
boolean match = false;
while (iter.hasNext()) {
FaultInfo fi2 = iter.next();
Class<?> fiClass2 = fi2.getProperty(Class.class.getName(), Class.class);
// So Compare Exception Class Instance.
if (fiClass1.equals(fiClass2)) {
match = true;
break;
}
}
if (!match) {
return false;
}
}
}
return true;
}
Aggregations