use of org.apache.cxf.service.model.BindingOperationInfo 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.BindingOperationInfo in project cxf by apache.
the class CorbaConduit method close.
public void close(Message message) throws IOException {
if (message.get(CorbaConstants.CORBA_ENDPOINT_OBJECT) != null) {
BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
OperationType opType = boi.getExtensor(OperationType.class);
try {
if (message instanceof CorbaMessage) {
buildRequest((CorbaMessage) message, opType);
}
message.getContent(OutputStream.class).close();
} catch (Exception ex) {
LOG.log(Level.SEVERE, "Could not build the corba request");
throw new CorbaBindingException(ex);
}
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class SwAInInterceptor method handleMessage.
public void handleMessage(SoapMessage message) throws Fault {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop == null) {
return;
}
if (bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
if (bmi == null) {
return;
}
SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);
if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
return;
}
Set<Integer> foundAtts = new HashSet<>();
MessageContentsList inObjects = MessageContentsList.getContentsList(message);
for (MessagePartInfo mpi : sbi.getAttachments()) {
String partName = mpi.getConcreteName().getLocalPart();
String start = partName + "=";
boolean found = false;
if (foundAtts.contains(mpi.getIndex())) {
continue;
}
foundAtts.add(mpi.getIndex());
for (Attachment a : message.getAttachments()) {
if (a.getId().startsWith(start)) {
DataHandler dh = a.getDataHandler();
String ct = dh.getContentType();
Object o = null;
Class<?> typeClass = mpi.getTypeClass();
if (DataHandler.class.isAssignableFrom(typeClass)) {
o = dh;
} else if (String.class.isAssignableFrom(typeClass)) {
try {
// o = IOUtils.readBytesFromStream(dh.getInputStream());
o = dh.getContent();
} catch (IOException e) {
throw new Fault(e);
}
} else if (byte[].class.isAssignableFrom(typeClass)) {
try {
o = IOUtils.readBytesFromStream(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else if (ct.startsWith("image/")) {
try {
o = ImageIO.read(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else if (ct.startsWith("text/xml") || ct.startsWith("application/xml")) {
try {
o = new StreamSource(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
}
} else {
o = dh;
}
inObjects.put(mpi, o);
found = true;
break;
}
}
if (!found) {
inObjects.put(mpi, null);
}
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class WrapperClassInInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Exchange ex = message.getExchange();
BindingOperationInfo boi = ex.getBindingOperationInfo();
if (Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE)) || boi == null) {
return;
}
Method method = ex.get(Method.class);
if (method != null && method.getName().endsWith("Async")) {
Class<?> retType = method.getReturnType();
if (retType.getName().equals("java.util.concurrent.Future") || retType.getName().equals("javax.xml.ws.Response")) {
return;
}
}
if (boi.isUnwrappedCapable()) {
BindingOperationInfo boi2 = boi.getUnwrappedOperation();
OperationInfo op = boi2.getOperationInfo();
BindingMessageInfo bmi;
MessageInfo wrappedMessageInfo = message.get(MessageInfo.class);
MessageInfo messageInfo;
if (wrappedMessageInfo == boi.getOperationInfo().getInput()) {
messageInfo = op.getInput();
bmi = boi2.getInput();
} else {
messageInfo = op.getOutput();
bmi = boi2.getOutput();
}
// Sometimes, an operation can be unwrapped according to WSDLServiceFactory,
// but not according to JAX-WS. We should unify these at some point, but
// for now check for the wrapper class.
MessageContentsList lst = MessageContentsList.getContentsList(message);
if (lst == null) {
return;
}
message.put(MessageInfo.class, messageInfo);
message.put(BindingMessageInfo.class, bmi);
ex.put(BindingOperationInfo.class, boi2);
if (isGET(message)) {
LOG.fine("WrapperClassInInterceptor skipped in HTTP GET method");
return;
}
MessagePartInfo wrapperPart = wrappedMessageInfo.getFirstMessagePart();
Class<?> wrapperClass = wrapperPart.getTypeClass();
Object wrappedObject = lst.get(wrapperPart.getIndex());
if (wrapperClass == null || wrappedObject == null || (wrapperClass != null && !wrapperClass.isInstance(wrappedObject))) {
return;
}
WrapperHelper helper = wrapperPart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
if (helper == null) {
Service service = ServiceModelUtil.getService(message.getExchange());
DataBinding dataBinding = service.getDataBinding();
if (dataBinding instanceof WrapperCapableDatabinding) {
helper = createWrapperHelper((WrapperCapableDatabinding) dataBinding, messageInfo, wrappedMessageInfo, wrapperClass);
wrapperPart.setProperty("WRAPPER_CLASS", helper);
} else {
return;
}
}
MessageContentsList newParams;
try {
newParams = new MessageContentsList(helper.getWrapperParts(wrappedObject));
List<Integer> removes = null;
int count = 0;
for (MessagePartInfo part : messageInfo.getMessageParts()) {
if (Boolean.TRUE.equals(part.getProperty(ReflectionServiceFactoryBean.HEADER))) {
MessagePartInfo mpi = null;
for (MessagePartInfo mpi2 : wrappedMessageInfo.getMessageParts()) {
if (mpi2.getConcreteName().equals(part.getConcreteName())) {
mpi = mpi2;
}
}
if (mpi != null && lst.hasValue(mpi)) {
count++;
newParams.put(part, lst.get(mpi));
} else if (mpi == null || mpi.getTypeClass() == null) {
// header, but not mapped to a param on the method
if (removes == null) {
removes = new ArrayList<>();
}
removes.add(part.getIndex());
}
} else {
++count;
}
}
if (count == 0) {
newParams.clear();
} else if (removes != null) {
Collections.sort(removes, Collections.reverseOrder());
for (Integer i : removes) {
if (i < newParams.size()) {
newParams.remove(i.intValue());
}
}
}
} catch (Exception e) {
throw new Fault(e);
}
message.setContent(List.class, newParams);
}
}
use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.
the class WrapperClassOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Exchange ex = message.getExchange();
BindingOperationInfo bop = ex.getBindingOperationInfo();
MessageInfo messageInfo = message.get(MessageInfo.class);
if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
return;
}
BindingOperationInfo newbop = bop.getWrappedOperation();
MessageInfo wrappedMsgInfo;
if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
wrappedMsgInfo = newbop.getInput().getMessageInfo();
} else {
wrappedMsgInfo = newbop.getOutput().getMessageInfo();
}
Class<?> wrapped = null;
if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
}
if (wrapped != null) {
MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
MessageContentsList objs = MessageContentsList.getContentsList(message);
WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
if (helper == null) {
helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
}
if (helper == null) {
return;
}
try {
MessageContentsList newObjs = new MessageContentsList();
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message) && helper instanceof AbstractWrapperHelper) {
((AbstractWrapperHelper) helper).setValidate(true);
}
Object o2 = helper.createWrapperObject(objs);
newObjs.put(firstMessagePart, o2);
for (MessagePartInfo p : messageInfo.getMessageParts()) {
if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
if (objs.hasValue(p)) {
newObjs.put(mpi, objs.get(p));
}
}
}
message.setContent(List.class, newObjs);
} catch (Fault f) {
throw f;
} catch (Exception e) {
throw new Fault(e);
}
// we've now wrapped the object, so use the wrapped binding op
ex.put(BindingOperationInfo.class, newbop);
if (messageInfo == bop.getOperationInfo().getInput()) {
message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
message.put(BindingMessageInfo.class, newbop.getInput());
} else if (messageInfo == bop.getOperationInfo().getOutput()) {
message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
message.put(BindingMessageInfo.class, newbop.getOutput());
}
}
}
Aggregations