Search in sources :

Example 56 with BindingOperationInfo

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();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Server(org.apache.cxf.endpoint.Server) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 57 with BindingOperationInfo

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);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) SystemException(org.omg.CORBA.SystemException) IOException(java.io.IOException) UnknownUserException(org.omg.CORBA.UnknownUserException)

Example 58 with BindingOperationInfo

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);
        }
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) StreamSource(javax.xml.transform.stream.StreamSource) Attachment(org.apache.cxf.message.Attachment) Fault(org.apache.cxf.interceptor.Fault) DataHandler(javax.activation.DataHandler) IOException(java.io.IOException) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) HashSet(java.util.HashSet)

Example 59 with BindingOperationInfo

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);
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) WrapperCapableDatabinding(org.apache.cxf.databinding.WrapperCapableDatabinding) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) Method(java.lang.reflect.Method) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Exchange(org.apache.cxf.message.Exchange) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) DataBinding(org.apache.cxf.databinding.DataBinding) WrapperHelper(org.apache.cxf.databinding.WrapperHelper)

Example 60 with BindingOperationInfo

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());
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) AbstractWrapperHelper(org.apache.cxf.databinding.AbstractWrapperHelper) AbstractWrapperHelper(org.apache.cxf.databinding.AbstractWrapperHelper) WrapperHelper(org.apache.cxf.databinding.WrapperHelper) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16