Search in sources :

Example 1 with CorbaDestination

use of org.apache.cxf.binding.corba.CorbaDestination in project cxf by apache.

the class CorbaDSIServantTest method testInvoke.

/*public void testCorbaDSIServant() throws Exception {

        CorbaDestination destination = testUtils.getSimpleTypesTestDestination();
        Service service = new ServiceImpl();
        Endpoint endpoint = new EndpointImpl(bus, service, destination.getEndPointInfo());
        MessageObserver observer = new ChainInitiationObserver(endpoint, bus);
        destination.setMessageObserver(observer);
        POA rootPOA = null;
        CorbaDSIServant dsiServant = new CorbaDSIServant();
        dsiServant.init(orb,
                        rootPOA,
                        destination,
                        observer);

        assertNotNull("DSIServant should not be null", dsiServant != null);
        assertNotNull("POA should not be null", dsiServant._default_POA() != null);
        assertNotNull("Destination should not be null", dsiServant.getDestination() != null);
        assertNotNull("ORB should not be null", dsiServant.getOrb() != null);
        assertNotNull("MessageObserver should not be null", dsiServant.getObserver() != null);

        byte[] objectId = new byte[10];
        String[] interfaces = dsiServant._all_interfaces(rootPOA, objectId);
        assertNotNull("Interfaces should not be null", interfaces != null);
        assertEquals("Interface ID should be equal", interfaces[0], "IDL:Simple:1.0");

    }*/
@Test
public void testInvoke() throws Exception {
    CorbaDestination dest = new TestUtils().getComplexTypesTestDestination();
    CorbaDSIServant dsiServant = new CorbaDSIServant();
    dsiServant.init(orb, null, dest, null);
    ServerRequest request = new ServerRequest() {

        public String operation() {
            return "greetMe";
        }

        public Context ctx() {
            return null;
        }
    };
    MessageObserver incomingObserver = new TestObserver();
    dsiServant.setObserver(incomingObserver);
    Map<String, QName> map = new HashMap<>(2);
    map.put("greetMe", new QName("greetMe"));
    dsiServant.setOperationMapping(map);
    dsiServant.invoke(request);
}
Also used : TestUtils(org.apache.cxf.binding.corba.TestUtils) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) MessageObserver(org.apache.cxf.transport.MessageObserver) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ServerRequest(org.omg.CORBA.ServerRequest) Test(org.junit.Test)

Example 2 with CorbaDestination

use of org.apache.cxf.binding.corba.CorbaDestination in project cxf by apache.

the class CorbaHandlerUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.getDefaultBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    factory = bfm.getBindingFactory("http://cxf.apache.org/bindings/corba");
    bfm.registerBindingFactory(CorbaConstants.NU_WSDL_CORBA, factory);
    java.util.Properties props = System.getProperties();
    props.put("yoko.orb.id", "CXF-CORBA-Server-Binding");
    orb = ORB.init(new String[0], props);
    CorbaDestination destination = getDestination();
    service = destination.getBindingInfo().getService();
    List<TypeMappingType> corbaTypes = service.getDescription().getExtensors(TypeMappingType.class);
    typeMap = CorbaUtils.createCorbaTypeMap(corbaTypes);
}
Also used : CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Before(org.junit.Before)

Example 3 with CorbaDestination

use of org.apache.cxf.binding.corba.CorbaDestination in project cxf by apache.

the class CorbaStreamInInterceptor method handleRequest.

private void handleRequest(Message msg) {
    ORB orb;
    ServiceInfo service;
    CorbaDestination destination;
    if (msg.getDestination() != null) {
        destination = (CorbaDestination) msg.getDestination();
    } else {
        destination = (CorbaDestination) msg.getExchange().getDestination();
    }
    service = destination.getBindingInfo().getService();
    CorbaMessage message = (CorbaMessage) msg;
    Exchange exchange = message.getExchange();
    CorbaTypeMap typeMap = message.getCorbaTypeMap();
    BindingInfo bInfo = destination.getBindingInfo();
    InterfaceInfo info = bInfo.getInterface();
    String opName = exchange.get(String.class);
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();
    OperationType opType = null;
    BindingOperationInfo bopInfo = null;
    QName opQName = null;
    while (i.hasNext()) {
        bopInfo = i.next();
        if (bopInfo.getName().getLocalPart().equals(opName)) {
            opType = bopInfo.getExtensor(OperationType.class);
            opQName = bopInfo.getName();
            break;
        }
    }
    if (opType == null) {
        throw new RuntimeException("Couldn't find the binding operation for " + opName);
    }
    orb = exchange.get(ORB.class);
    ServerRequest request = exchange.get(ServerRequest.class);
    NVList list = prepareArguments(message, info, opType, opQName, typeMap, destination, service);
    request.arguments(list);
    message.setList(list);
    HandlerIterator paramIterator = new HandlerIterator(message, true);
    CorbaTypeEventProducer eventProducer = null;
    BindingMessageInfo msgInfo = bopInfo.getInput();
    boolean wrap = false;
    if (bopInfo.isUnwrappedCapable()) {
        wrap = true;
    }
    if (wrap) {
        // wrapper element around our args
        QName wrapperElementQName = msgInfo.getMessageInfo().getName();
        eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName, paramIterator, service, orb);
    } else {
        eventProducer = new ParameterEventProducer(paramIterator, service, orb);
    }
    CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
    message.setContent(XMLStreamReader.class, reader);
}
Also used : CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) WrappedParameterSequenceEventProducer(org.apache.cxf.binding.corba.types.WrappedParameterSequenceEventProducer) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) HandlerIterator(org.apache.cxf.binding.corba.types.HandlerIterator) CorbaStreamReader(org.apache.cxf.binding.corba.runtime.CorbaStreamReader) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Exchange(org.apache.cxf.message.Exchange) ParameterEventProducer(org.apache.cxf.binding.corba.types.ParameterEventProducer) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) CorbaTypeEventProducer(org.apache.cxf.binding.corba.types.CorbaTypeEventProducer) ServerRequest(org.omg.CORBA.ServerRequest) NVList(org.omg.CORBA.NVList) ORB(org.omg.CORBA.ORB)

Example 4 with CorbaDestination

use of org.apache.cxf.binding.corba.CorbaDestination in project cxf by apache.

the class CorbaStreamFaultOutInterceptor method handleMessage.

public void handleMessage(Message msg) {
    CorbaMessage message = (CorbaMessage) msg;
    Exchange exchange = message.getExchange();
    CorbaDestination destination;
    Fault faultEx = null;
    if (message.getDestination() != null) {
        destination = (CorbaDestination) message.getDestination();
    } else {
        destination = (CorbaDestination) exchange.getDestination();
    }
    orb = (ORB) message.get(CorbaConstants.ORB);
    if (orb == null) {
        orb = exchange.get(ORB.class);
    }
    DataWriter<XMLStreamWriter> writer = getDataWriter(message);
    Throwable ex = message.getContent(Exception.class);
    // is a Fault instance and contains a detail object.
    if (ex.getCause() == null) {
        if ((ex instanceof Fault) && (((Fault) ex).getDetail() != null)) {
            faultEx = (Fault) ex;
        } else {
            throw new CorbaBindingException(ex);
        }
    } else {
        ex = ex.getCause();
    }
    if (ex instanceof InvocationTargetException) {
        ex = ex.getCause();
    }
    if (ex instanceof SystemException) {
        setSystemException(message, ex, destination);
        return;
    }
    String exClassName = null;
    if (faultEx == null) {
        // REVISIT, we should not have to depend on WebFault annotation
        // Try changing the fault name to the proper mangled java exception classname.
        WebFault fault = ex.getClass().getAnnotation(WebFault.class);
        if (fault == null) {
            throw new CorbaBindingException(ex);
        }
        exClassName = fault.name();
    } else {
        // JCGS: exClassName to be set to the exception name
        Element faultElement = (Element) faultEx.getDetail().getFirstChild();
        exClassName = faultElement.getLocalName();
    }
    // Get information about the operation being invoked from the WSDL
    // definition.
    // We need this to marshal data correctly
    BindingInfo bInfo = destination.getBindingInfo();
    String opName = message.getExchange().get(String.class);
    Iterator<BindingOperationInfo> iter = bInfo.getOperations().iterator();
    BindingOperationInfo bopInfo = null;
    OperationType opType = null;
    while (iter.hasNext()) {
        bopInfo = iter.next();
        if (bopInfo.getName().getLocalPart().equals(opName)) {
            opType = bopInfo.getExtensor(OperationType.class);
            break;
        }
    }
    if (opType == null) {
        throw new CorbaBindingException("Unable to find binding operation for " + opName);
    }
    OperationInfo opInfo = bopInfo.getOperationInfo();
    if (faultEx != null) {
        MessagePartInfo partInfo = getFaultMessagePartInfo(opInfo, new QName("", exClassName));
        if (partInfo != null) {
            exClassName = partInfo.getTypeQName().getLocalPart();
        }
    }
    RaisesType exType = getRaisesType(opType, exClassName, ex);
    try {
        if (exType != null) {
            if (faultEx != null) {
                setUserExceptionFromFaultDetail(message, faultEx.getDetail(), exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
            } else {
                setUserException(message, ex, exType, opInfo, writer, exchange.getEndpoint().getEndpointInfo().getService());
            }
        } else {
            throw new CorbaBindingException(ex);
        }
    } catch (Exception exp) {
        throw new CorbaBindingException(exp);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Fault(org.apache.cxf.interceptor.Fault) WebFault(javax.xml.ws.WebFault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.omg.CORBA.SystemException) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Exchange(org.apache.cxf.message.Exchange) WebFault(javax.xml.ws.WebFault) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) RaisesType(org.apache.cxf.binding.corba.wsdl.RaisesType) SystemException(org.omg.CORBA.SystemException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) BindingInfo(org.apache.cxf.service.model.BindingInfo) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) ORB(org.omg.CORBA.ORB)

Example 5 with CorbaDestination

use of org.apache.cxf.binding.corba.CorbaDestination in project cxf by apache.

the class CorbaStreamInInterceptor method handleReply.

private void handleReply(Message msg) {
    ORB orb;
    ServiceInfo service;
    CorbaDestination destination;
    if (msg.getDestination() != null) {
        destination = (CorbaDestination) msg.getDestination();
    } else {
        destination = (CorbaDestination) msg.getExchange().getDestination();
    }
    service = destination.getBindingInfo().getService();
    CorbaMessage message = (CorbaMessage) msg;
    if (message.getStreamableException() != null || message.getSystemException() != null) {
        message.setContent(Exception.class, message.getExchange().getOutMessage().getContent(Exception.class));
        Endpoint ep = message.getExchange().getEndpoint();
        message.getInterceptorChain().abort();
        if (ep.getInFaultObserver() != null) {
            ep.getInFaultObserver().onMessage(message);
            return;
        }
    }
    CorbaMessage outMessage = (CorbaMessage) message.getExchange().getOutMessage();
    orb = message.getExchange().get(ORB.class);
    HandlerIterator paramIterator = new HandlerIterator(outMessage, false);
    CorbaTypeEventProducer eventProducer = null;
    Exchange exchange = message.getExchange();
    BindingOperationInfo bindingOpInfo = exchange.getBindingOperationInfo();
    BindingMessageInfo msgInfo = bindingOpInfo.getOutput();
    boolean wrap = false;
    if (bindingOpInfo.isUnwrappedCapable()) {
        wrap = true;
    }
    if (wrap) {
        // wrapper element around our args
        // REVISIT, bravi, message name same as the element name
        QName wrapperElementQName = msgInfo.getMessageInfo().getName();
        eventProducer = new WrappedParameterSequenceEventProducer(wrapperElementQName, paramIterator, service, orb);
    } else {
        eventProducer = new ParameterEventProducer(paramIterator, service, orb);
    }
    CorbaStreamReader reader = new CorbaStreamReader(eventProducer);
    message.setContent(XMLStreamReader.class, reader);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) WrappedParameterSequenceEventProducer(org.apache.cxf.binding.corba.types.WrappedParameterSequenceEventProducer) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) QName(javax.xml.namespace.QName) HandlerIterator(org.apache.cxf.binding.corba.types.HandlerIterator) CorbaStreamReader(org.apache.cxf.binding.corba.runtime.CorbaStreamReader) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Exchange(org.apache.cxf.message.Exchange) ParameterEventProducer(org.apache.cxf.binding.corba.types.ParameterEventProducer) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) CorbaTypeEventProducer(org.apache.cxf.binding.corba.types.CorbaTypeEventProducer) ORB(org.omg.CORBA.ORB)

Aggregations

CorbaDestination (org.apache.cxf.binding.corba.CorbaDestination)5 QName (javax.xml.namespace.QName)4 CorbaMessage (org.apache.cxf.binding.corba.CorbaMessage)3 Exchange (org.apache.cxf.message.Exchange)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 ORB (org.omg.CORBA.ORB)3 CorbaStreamReader (org.apache.cxf.binding.corba.runtime.CorbaStreamReader)2 CorbaTypeEventProducer (org.apache.cxf.binding.corba.types.CorbaTypeEventProducer)2 HandlerIterator (org.apache.cxf.binding.corba.types.HandlerIterator)2 ParameterEventProducer (org.apache.cxf.binding.corba.types.ParameterEventProducer)2 WrappedParameterSequenceEventProducer (org.apache.cxf.binding.corba.types.WrappedParameterSequenceEventProducer)2 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)2 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)2 ServerRequest (org.omg.CORBA.ServerRequest)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 WebFault (javax.xml.ws.WebFault)1