Search in sources :

Example 1 with CorbaTypeMap

use of org.apache.cxf.binding.corba.CorbaTypeMap 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 2 with CorbaTypeMap

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

the class WSDLToCorbaBindingTest method testMixedArraysMapping.

@Test
public void testMixedArraysMapping() throws Exception {
    try {
        String fileName = getClass().getResource("/wsdl/arrays-mixed.wsdl").toString();
        generator.setWsdlFile(fileName);
        generator.addInterfaceName("X");
        Definition model = generator.generateCORBABinding();
        QName bName = new QName("http://schemas.apache.org/idl/anon.idl", "XCORBABinding", "tns");
        Binding binding = model.getBinding(bName);
        assertNotNull(binding);
        assertEquals("XCORBABinding", binding.getQName().getLocalPart());
        assertEquals("X", binding.getPortType().getQName().getLocalPart());
        assertEquals(1, binding.getExtensibilityElements().size());
        assertEquals(1, binding.getBindingOperations().size());
        for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
            if (extElement.getElementType().getLocalPart().equals("binding")) {
                BindingType bindingType = (BindingType) extElement;
                assertEquals(bindingType.getRepositoryID(), "IDL:X:1.0");
            }
        }
        Iterator<?> tm = model.getExtensibilityElements().iterator();
        assertTrue(tm.hasNext());
        TypeMappingType tmt = (TypeMappingType) tm.next();
        CorbaTypeMap typeMap = CorbaUtils.createCorbaTypeMap(Arrays.asList(tmt));
        assertNull("All nested anonymous types should have \"nested\" names", typeMap.getType("item"));
        // Checkstyle forces me to split the method...
        assertMixedArraysMappingEasyTypes(typeMap);
        // elem types are no longer strings from now.
        assertMixedArraysMappingDifficultSequences(typeMap);
        assertMixedArraysMappingDifficultArrays(typeMap);
        Iterator<?> j = binding.getBindingOperations().iterator();
        while (j.hasNext()) {
            BindingOperation bindingOperation = (BindingOperation) j.next();
            assertEquals(1, bindingOperation.getExtensibilityElements().size());
            assertEquals(bindingOperation.getBindingInput().getName(), "op_a");
            assertEquals(bindingOperation.getBindingOutput().getName(), "op_aResponse");
            for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
                if (extElement.getElementType().getLocalPart().equals("operation")) {
                    OperationType corbaOpType = (OperationType) extElement;
                    assertEquals(corbaOpType.getName(), "op_a");
                    assertEquals(1, corbaOpType.getParam().size());
                    assertNotNull(corbaOpType.getReturn());
                    ParamType paramtype = corbaOpType.getParam().get(0);
                    assertEquals(paramtype.getName(), "part1");
                    QName idltype = new QName("http://schemas.apache.org/idl/anon.idl/corba/typemap/", "MixedArrayType", "ns1");
                    assertEquals(paramtype.getIdltype(), idltype);
                    assertEquals(paramtype.getMode().toString(), "IN");
                } else if (extElement.getElementType().getLocalPart().equals("typeMapping")) {
                    System.out.println("x");
                }
            }
        }
        // See if an IDL is able to produce from this CORBA Binding.
        WSDLToIDLAction idlgen = new WSDLToIDLAction();
        idlgen.setBindingName("XCORBABinding");
        idlgen.setOutputFile("array.idl");
        idlgen.generateIDL(model);
        File f = new File("array.idl");
        assertTrue("array.idl should be generated", f.exists());
    } finally {
        new File("array.idl").deleteOnExit();
    }
}
Also used : WSDLToCorbaBinding(org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaBinding) Binding(javax.wsdl.Binding) WSDLToIDLAction(org.apache.cxf.tools.corba.processors.wsdl.WSDLToIDLAction) CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ParamType(org.apache.cxf.binding.corba.wsdl.ParamType) BindingOperation(javax.wsdl.BindingOperation) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) File(java.io.File) Test(org.junit.Test)

Example 3 with CorbaTypeMap

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

the class CorbaUtils method createCorbaTypeMap.

public static CorbaTypeMap createCorbaTypeMap(List<TypeMappingType> tmTypes) {
    CorbaTypeMap map = null;
    if (tmTypes != null) {
        // Currently, only one type map
        TypeMappingType tmType = tmTypes.get(0);
        map = new CorbaTypeMap(tmType.getTargetNamespace());
        List<CorbaType> types = tmType.getStructOrExceptionOrUnion();
        LOG.fine("Found " + types.size() + " types defined in the typemap");
        for (Iterator<CorbaType> it = types.iterator(); it.hasNext(); ) {
            CorbaType corbaType = it.next();
            String name = corbaType.getName();
            // There can be some instances where a prefix is added to the name by the tool
            // (e.g. Object Reference Names).  Since the name is read as a string, this
            // prefix is added to the types name.  Remove this as it is not needed.
            int pos = name.lastIndexOf(":");
            if (pos != -1) {
                name = name.substring(pos + 1);
                corbaType.setName(name);
            }
            map.addType(name, corbaType);
            LOG.fine("Adding type " + name);
        }
    }
    return map;
}
Also used : CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) TypeMappingType(org.apache.cxf.binding.corba.wsdl.TypeMappingType)

Example 4 with CorbaTypeMap

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

the class CorbaAnyHandlerTest method testCorbaAnyHandler.

@Test
public void testCorbaAnyHandler() {
    Any a = orb.create_any();
    a.insert_string("TestMessage");
    QName anyName = new QName("AnyHandlerName");
    QName anyIdlType = CorbaConstants.NT_CORBA_ANY;
    TypeCode anyTC = orb.get_primitive_tc(TCKind.from_int(TCKind._tk_any));
    CorbaTypeMap tm = new CorbaTypeMap(CorbaConstants.NU_WSDL_CORBA);
    CorbaAnyHandler anyHandler = new CorbaAnyHandler(anyName, anyIdlType, anyTC, null);
    anyHandler.setTypeMap(tm);
    // Test the get/set value methods
    anyHandler.setValue(a);
    Any resultAny = anyHandler.getValue();
    assertNotNull(resultAny);
    String value = resultAny.extract_string();
    assertEquals("TestMessage", value);
    // Test get/set CorbaTypeMap methods
    CorbaTypeMap resultTM = anyHandler.getTypeMap();
    assertTrue(resultTM.getTargetNamespace().equals(CorbaConstants.NU_WSDL_CORBA));
}
Also used : CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) TypeCode(org.omg.CORBA.TypeCode) QName(javax.xml.namespace.QName) Any(org.omg.CORBA.Any) Test(org.junit.Test)

Example 5 with CorbaTypeMap

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

the class CorbaUtilsTest method testErrorConditionNullTypeQName.

@Test
public void testErrorConditionNullTypeQName() {
    try {
        CorbaUtils.getTypeCode(orb, null, new CorbaTypeMap("dud:namespace"));
        fail("expect exception on null type");
    } catch (CorbaBindingException expected) {
    // ignore
    }
    CorbaTypeMap typeMap = new CorbaTypeMap("dud:namespace");
    QName seen = new QName("bla", "Bla");
    Stack<QName> seenTypes = new Stack<QName>();
    seenTypes.add(seen);
    try {
        CorbaUtils.getTypeCode(orb, null, typeMap, seenTypes);
        fail("expect exception on null type");
    } catch (CorbaBindingException expected) {
        assertTrue("enclosed type is present", expected.getMessage().indexOf(seen.toString()) != -1);
    }
    CorbaType ctype = new CorbaType();
    try {
        CorbaUtils.getTypeCode(orb, null, ctype, typeMap);
        fail("expect exception on null type");
    } catch (CorbaBindingException expected) {
        assertTrue("enclosed corba type is present", expected.getMessage().indexOf(ctype.toString()) != -1);
    }
}
Also used : CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) CorbaTypeMap(org.apache.cxf.binding.corba.CorbaTypeMap) CorbaType(org.apache.cxf.binding.corba.wsdl.CorbaType) QName(javax.xml.namespace.QName) Stack(java.util.Stack) Test(org.junit.Test)

Aggregations

CorbaTypeMap (org.apache.cxf.binding.corba.CorbaTypeMap)5 QName (javax.xml.namespace.QName)4 Test (org.junit.Test)3 CorbaType (org.apache.cxf.binding.corba.wsdl.CorbaType)2 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)2 TypeMappingType (org.apache.cxf.binding.corba.wsdl.TypeMappingType)2 File (java.io.File)1 Stack (java.util.Stack)1 Binding (javax.wsdl.Binding)1 BindingOperation (javax.wsdl.BindingOperation)1 Definition (javax.wsdl.Definition)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 CorbaBindingException (org.apache.cxf.binding.corba.CorbaBindingException)1 CorbaDestination (org.apache.cxf.binding.corba.CorbaDestination)1 CorbaMessage (org.apache.cxf.binding.corba.CorbaMessage)1 CorbaStreamReader (org.apache.cxf.binding.corba.runtime.CorbaStreamReader)1 CorbaTypeEventProducer (org.apache.cxf.binding.corba.types.CorbaTypeEventProducer)1 HandlerIterator (org.apache.cxf.binding.corba.types.HandlerIterator)1 ParameterEventProducer (org.apache.cxf.binding.corba.types.ParameterEventProducer)1 WrappedParameterSequenceEventProducer (org.apache.cxf.binding.corba.types.WrappedParameterSequenceEventProducer)1