use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class CorbaStreamFaultOutInterceptor method setUserException.
protected void setUserException(CorbaMessage message, Throwable ex, RaisesType exType, OperationInfo opInfo, DataWriter<XMLStreamWriter> writer, ServiceInfo service) throws Exception {
QName exIdlType = exType.getException();
QName elName = new QName("", exIdlType.getLocalPart());
MessagePartInfo faultPart = getFaultMessagePartInfo(opInfo, elName);
if (faultPart == null) {
throw new CorbaBindingException("Coulnd't find the message fault part : " + elName);
}
Method faultMethod = ex.getClass().getMethod("getFaultInfo");
if (faultMethod == null) {
return;
}
Object fault = faultMethod.invoke(ex);
// one has not been created on the servant side which throws the UserException.
if (fault == null) {
Class<?> faultClass = faultMethod.getReturnType();
fault = faultClass.newInstance();
}
CorbaFaultStreamWriter faultWriter = new CorbaFaultStreamWriter(orb, exType, message.getCorbaTypeMap(), service);
writer.write(fault, faultPart, faultWriter);
CorbaObjectHandler[] objs = faultWriter.getCorbaObjects();
CorbaStreamable streamable = message.createStreamableObject(objs[0], elName);
message.setStreamableException(streamable);
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class CorbaStreamFaultOutInterceptor method getFaultMessagePartInfo.
protected MessagePartInfo getFaultMessagePartInfo(OperationInfo opInfo, QName faultName) {
Iterator<FaultInfo> faults = opInfo.getFaults().iterator();
while (faults.hasNext()) {
FaultInfo fault = faults.next();
MessagePartInfo partInfo = fault.getMessageParts().get(0);
if (partInfo.isElement() && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
return partInfo;
} else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
return partInfo;
}
}
return null;
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ColocOutInterceptorTest method verifyIsColocatedWithCompatibleOperation.
private void verifyIsColocatedWithCompatibleOperation() {
colocOut = new TestColocOutInterceptor1();
// Funtion Param
Server s1 = control.createMock(Server.class);
List<Server> list = new ArrayList<>();
list.add(s1);
Endpoint sep = control.createMock(Endpoint.class);
BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
// Local var
Service ses = control.createMock(Service.class);
EndpointInfo sei = control.createMock(EndpointInfo.class);
BindingInfo rbi = control.createMock(BindingInfo.class);
Endpoint rep = control.createMock(Endpoint.class);
Service res = control.createMock(Service.class);
EndpointInfo rei = control.createMock(EndpointInfo.class);
BindingOperationInfo rboi = control.createMock(BindingOperationInfo.class);
QName op = new QName("E", "F");
QName intf = new QName("G", "H");
QName inmi = new QName("M", "in");
QName outmi = new QName("M", "out");
ServiceInfo ssi = new ServiceInfo();
InterfaceInfo sii = new InterfaceInfo(ssi, intf);
sii.addOperation(op);
OperationInfo soi = sii.getOperation(op);
MessageInfo mii = new MessageInfo(soi, MessageInfo.Type.INPUT, inmi);
MessagePartInfo mpi = mii.addMessagePart("parameters");
mpi.setTypeClass(Source.class);
MessageInfo mio = new MessageInfo(soi, MessageInfo.Type.OUTPUT, outmi);
mpi = mio.addMessagePart("parameters");
mpi.setTypeClass(Source.class);
soi.setInput("in", mii);
soi.setOutput("out", mio);
ServiceInfo rsi = new ServiceInfo();
InterfaceInfo rii = new InterfaceInfo(rsi, intf);
rii.addOperation(op);
OperationInfo roi = rii.getOperation(op);
mii = new MessageInfo(roi, MessageInfo.Type.INPUT, inmi);
mpi = mii.addMessagePart("parameters");
mpi.setTypeClass(Object.class);
mio = new MessageInfo(roi, MessageInfo.Type.OUTPUT, outmi);
mpi = mio.addMessagePart("parameters");
mpi.setTypeClass(Object.class);
roi.setInput("in", mii);
roi.setOutput("out", mio);
EasyMock.expect(sep.getService()).andReturn(ses);
EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
EasyMock.expect(s1.getEndpoint()).andReturn(rep);
EasyMock.expect(rep.getService()).andReturn(res);
EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
EasyMock.expect(rei.getBinding()).andReturn(rbi);
EasyMock.expect(sboi.getName()).andReturn(op);
EasyMock.expect(sboi.getOperationInfo()).andReturn(soi);
EasyMock.expect(rboi.getName()).andReturn(op);
EasyMock.expect(rboi.getOperationInfo()).andReturn(roi);
EasyMock.expect(rbi.getOperation(op)).andReturn(rboi);
control.replay();
Server val = colocOut.isColocated(list, sep, sboi);
assertEquals("Expecting a colocated call", s1, val);
control.reset();
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ColocUtil method convertSourceToObject.
public static void convertSourceToObject(Message message) {
List<Object> content = CastUtils.cast(message.getContent(List.class));
if (content == null || content.isEmpty()) {
// nothing to convert
return;
}
// only supporting the wrapped style for now (one pojo <-> one source)
Source source = (Source) content.get(0);
DataReader<XMLStreamReader> reader = message.getExchange().getService().getDataBinding().createReader(XMLStreamReader.class);
MessagePartInfo mpi = getMessageInfo(message).getMessagePart(0);
XMLStreamReader streamReader = null;
Object wrappedObject;
try {
streamReader = StaxUtils.createXMLStreamReader(source);
wrappedObject = reader.read(mpi, streamReader);
} finally {
try {
StaxUtils.close(streamReader);
} catch (XMLStreamException e) {
// Ignore
}
}
MessageContentsList parameters = new MessageContentsList();
parameters.put(mpi, wrappedObject);
message.setContent(List.class, parameters);
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ColocUtil method isSameMessageInfo.
public static boolean isSameMessageInfo(MessageInfo mi1, MessageInfo mi2) {
if ((mi1 == null && mi2 != null) || (mi1 != null && mi2 == null)) {
return false;
}
if (mi1 != null && mi2 != null) {
List<MessagePartInfo> mpil1 = mi1.getMessageParts();
List<MessagePartInfo> mpil2 = mi2.getMessageParts();
if (mpil1.size() != mpil2.size()) {
return false;
}
int idx = 0;
for (MessagePartInfo mpi1 : mpil1) {
MessagePartInfo mpi2 = mpil2.get(idx);
if (!mpi1.getTypeClass().equals(mpi2.getTypeClass())) {
return false;
}
++idx;
}
}
return true;
}
Aggregations