Java Code Examples for org.apache.cxf.service.model.BindingOperationInfo#getExtensor()

The following examples show how to use org.apache.cxf.service.model.BindingOperationInfo#getExtensor() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: cxf   File: CorbaStreamOutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private void handleOutBoundMessage(CorbaMessage message, BindingOperationInfo boi) {
    boolean wrap = false;
    if (boi.isUnwrappedCapable()) {
        wrap = true;
    }
    OperationType opType = boi.getExtensor(OperationType.class);
    List<ParamType> paramTypes = opType.getParam();
    List<ArgType> params = new ArrayList<>();
    for (Iterator<ParamType> iter = paramTypes.iterator(); iter.hasNext();) {
        ParamType param = iter.next();
        if (!param.getMode().equals(ModeType.OUT)) {
            params.add(param);
        }
    }
    CorbaStreamWriter writer = new CorbaStreamWriter(orb, params, typeMap, service, wrap);
    message.setContent(XMLStreamWriter.class, writer);
}
 
Example 2
Source Project: cxf   File: CorbaStreamOutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private void handleInBoundMessage(CorbaMessage message, BindingOperationInfo boi) {
    boolean wrap = false;
    if (boi.isUnwrappedCapable()) {
        wrap = true;
    }
    OperationType opType = boi.getExtensor(OperationType.class);

    ArgType returnParam = opType.getReturn();
    List<ParamType> paramTypes = opType.getParam();
    List<ArgType> params = new ArrayList<>();
    if (returnParam != null) {
        params.add(returnParam);
    }
    for (Iterator<ParamType> iter = paramTypes.iterator(); iter.hasNext();) {
        ParamType param = iter.next();
        if (!param.getMode().equals(ModeType.IN)) {
            params.add(param);
        }
    }
    CorbaStreamWriter writer = new CorbaStreamWriter(orb, params, typeMap, service, wrap);
    message.setContent(XMLStreamWriter.class, writer);
}
 
Example 3
private String getSoapAction(SoapMessage message, BindingOperationInfo boi) {
    // allow an interceptor to override the SOAPAction if need be
    String action = (String) message.get(SoapBindingConstants.SOAP_ACTION);

    // Fall back on the SOAPAction in the operation info
    if (action == null) {
        if (boi == null) {
            action = "\"\"";
        } else {
            SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
            action = soi == null ? "\"\"" : soi.getAction() == null ? "\"\"" : soi.getAction();
        }
    }

    if (!action.startsWith("\"")) {
        action = new StringBuilder().append("\"").append(action).append("\"").toString();
    }

    return action;
}
 
Example 4
Source Project: cxf   File: ClientFactoryBeanTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClientFactoryBean() throws Exception {

    ClientFactoryBean cfBean = new ClientFactoryBean();
    cfBean.setAddress("http://localhost/Hello");
    cfBean.setBus(getBus());
    cfBean.setServiceClass(HelloService.class);

    Client client = cfBean.create();
    assertNotNull(client);

    Service service = client.getEndpoint().getService();
    Map<QName, Endpoint> eps = service.getEndpoints();
    assertEquals(1, eps.size());

    Endpoint ep = eps.values().iterator().next();
    EndpointInfo endpointInfo = ep.getEndpointInfo();

    BindingInfo b = endpointInfo.getService().getBindings().iterator().next();

    assertTrue(b instanceof SoapBindingInfo);

    SoapBindingInfo sb = (SoapBindingInfo) b;
    assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
    assertEquals("document", sb.getStyle());

    assertEquals(4, b.getOperations().size());

    BindingOperationInfo bop = b.getOperations().iterator().next();
    SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);
    assertNotNull(sop);
    assertEquals("", sop.getAction());
    assertEquals("document", sop.getStyle());
}
 
Example 5
Source Project: cxf   File: InternalContextUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static SoapOperationInfo getSoapOperationInfo(BindingOperationInfo bindingOpInfo) {
    SoapOperationInfo soi = bindingOpInfo.getExtensor(SoapOperationInfo.class);
    if (soi == null && bindingOpInfo.isUnwrapped()) {
        soi = bindingOpInfo.getWrappedOperation()
            .getExtensor(SoapOperationInfo.class);
    }
    return soi;
}
 
Example 6
Source Project: cxf   File: CorbaConduit.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 7
Source Project: cxf   File: CorbaConduitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testClose() throws Exception {
    Method m = CorbaConduit.class.getDeclaredMethod("buildRequest",
        new Class[] {CorbaMessage.class, OperationType.class});
    CorbaConduit conduit = EasyMock.createMockBuilder(CorbaConduit.class)
        .addMockedMethod(m).createMock();

    org.omg.CORBA.Object obj = control.createMock(org.omg.CORBA.Object.class);
    CorbaMessage msg = control.createMock(CorbaMessage.class);
    EasyMock.expect(msg.get(CorbaConstants.CORBA_ENDPOINT_OBJECT)).andReturn(obj);
    Exchange exg = control.createMock(Exchange.class);
    EasyMock.expect(msg.getExchange()).andReturn(exg);
    BindingOperationInfo bopInfo = control.createMock(BindingOperationInfo.class);
    EasyMock.expect(exg.getBindingOperationInfo()).andReturn(bopInfo);
    OperationType opType = control.createMock(OperationType.class);
    bopInfo.getExtensor(OperationType.class);
    EasyMock.expectLastCall().andReturn(opType);
    conduit.buildRequest(msg, opType);
    EasyMock.expectLastCall();
    OutputStream os = control.createMock(OutputStream.class);
    EasyMock.expect(msg.getContent(OutputStream.class)).andReturn(os);
    os.close();
    EasyMock.expectLastCall();

    control.replay();
    conduit.close(msg);
    control.verify();
}
 
Example 8
Source Project: cxf   File: CorbaConduitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildExceptionListWithExceptions() throws Exception {
    CorbaConduit conduit = setupCorbaConduit(false);
    Message msg = new MessageImpl();
    CorbaMessage message = new CorbaMessage(msg);
    TestUtils testUtils = new TestUtils();
    CorbaDestination destination = testUtils.getExceptionTypesTestDestination();
    EndpointInfo endpointInfo2 = destination.getEndPointInfo();
    QName name = new QName("http://schemas.apache.org/idl/except", "review_data", "");
    BindingOperationInfo bInfo = destination.getBindingInfo().getOperation(name);
    OperationType opType = bInfo.getExtensor(OperationType.class);
    CorbaTypeMap typeMap = null;
    List<TypeMappingType> corbaTypes =
        endpointInfo2.getService().getDescription().getExtensors(TypeMappingType.class);
    if (corbaTypes != null) {
        typeMap = CorbaUtils.createCorbaTypeMap(corbaTypes);
    }

    ExceptionList exList = conduit.getExceptionList(conduit.getOperationExceptions(opType, typeMap),
                                                    message,
                                                    opType);

    assertNotNull("ExceptionList is not null", exList != null);
    assertNotNull("TypeCode is not null", exList.item(0) != null);
    assertEquals("ID should be equal", exList.item(0).id(), "IDL:BadRecord:1.0");
    assertEquals("ID should be equal", exList.item(0).name(), "BadRecord");
    assertEquals("ID should be equal", exList.item(0).member_count(), 2);
    assertEquals("ID should be equal", exList.item(0).member_name(0), "reason");
    assertNotNull("Member type is not null", exList.item(0).member_type(0) != null);
}
 
Example 9
Source Project: cxf   File: SoapActionInInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isActionMatch(SoapMessage message, BindingOperationInfo boi, String action) {
    SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        return false;
    }
    boolean allowNoMatchingToDefault = MessageUtils.getContextualBoolean(message,
                                                                ALLOW_NON_MATCHING_TO_DEFAULT,
                                                                false);
    return action.equals(soi.getAction())
           || (allowNoMatchingToDefault && StringUtils.isEmpty(soi.getAction())
           || (message.getVersion() instanceof Soap12) && StringUtils.isEmpty(soi.getAction()));
}
 
Example 10
Source Project: cxf   File: SoapBindingInfo.java    License: Apache License 2.0 5 votes vote down vote up
public OperationInfo getOperationByAction(String action) {
    for (BindingOperationInfo b : getOperations()) {
        SoapOperationInfo opInfo = b.getExtensor(SoapOperationInfo.class);

        if (opInfo.getAction().equals(action)) {
            return b.getOperationInfo();
        }
    }

    return null;
}
 
Example 11
Source Project: cxf   File: SoapBindingInfo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the soap action for an operation. Will never return null.
 *
 * @param operation
 * @return
 */
public String getSoapAction(OperationInfo operation) {
    BindingOperationInfo b = getOperation(operation.getName());
    SoapOperationInfo opInfo = b.getExtensor(SoapOperationInfo.class);

    if (opInfo != null && opInfo.getAction() != null) {
        return opInfo.getAction();
    }

    return "";
}
 
Example 12
@Test
public void testServerFactoryBean() throws Exception {
    Service service = createService(true);
    assertEquals("test", service.get("test"));

    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceFactory(serviceFactory);
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setBus(getBus());

    Map<String, Object> props = new HashMap<>();
    props.put("test", "test");
    serviceFactory.setProperties(props);
    svrBean.setProperties(props);

    Server server = svrBean.create();
    assertNotNull(server);
    Map<QName, Endpoint> eps = service.getEndpoints();
    assertEquals(1, eps.size());

    Endpoint ep = eps.values().iterator().next();
    EndpointInfo endpointInfo = ep.getEndpointInfo();

    assertEquals("test", ep.get("test"));

    BindingInfo b = endpointInfo.getService().getBindings().iterator().next();

    assertTrue(b instanceof SoapBindingInfo);

    SoapBindingInfo sb = (SoapBindingInfo) b;
    assertEquals("HelloServiceSoapBinding", b.getName().getLocalPart());
    assertEquals("document", sb.getStyle());

    assertEquals(4, b.getOperations().size());

    BindingOperationInfo bop = b.getOperations().iterator().next();
    SoapOperationInfo sop = bop.getExtensor(SoapOperationInfo.class);
    assertNotNull(sop);
    assertEquals("", sop.getAction());
    assertEquals("document", sop.getStyle());
}
 
Example 13
Source Project: cxf   File: ServiceModelPolicyProvider.java    License: Apache License 2.0 4 votes vote down vote up
public Policy getEffectivePolicy(BindingOperationInfo bi, Message m) {
    return bi.getExtensor(Policy.class);
}
 
Example 14
Source Project: cxf   File: CorbaDSIServant.java    License: Apache License 2.0 4 votes vote down vote up
public void init(ORB theOrb,
                 POA poa,
                 CorbaDestination dest,
                 MessageObserver observer,
                 CorbaTypeMap map) {
    orb = theOrb;
    servantPOA = poa;
    destination = dest;
    incomingObserver = observer;
    typeMap = map;

    // Get the list of interfaces that this servant will support
    try {
        BindingType bindType = destination.getBindingInfo().getExtensor(BindingType.class);
        if (bindType == null) {
            throw new CorbaBindingException("Unable to determine corba binding information");
        }

        List<String> bases = bindType.getBases();
        interfaces = new ArrayList<>();
        interfaces.add(bindType.getRepositoryID());
        for (Iterator<String> iter = bases.iterator(); iter.hasNext();) {
            interfaces.add(iter.next());
        }
    } catch (java.lang.Exception ex) {
        LOG.log(Level.SEVERE, "Couldn't initialize the corba DSI servant");
        throw new CorbaBindingException(ex);
    }

    // Build the list of CORBA operations and the WSDL operations they map to.  Note that
    // the WSDL operation name may not always match the CORBA operation name.
    BindingInfo bInfo = destination.getBindingInfo();
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();

    operationMap = new HashMap<>(bInfo.getOperations().size());

    while (i.hasNext()) {
        BindingOperationInfo bopInfo = i.next();
        OperationType opType = bopInfo.getExtensor(OperationType.class);
        if (opType != null) {
            operationMap.put(opType.getName(), bopInfo.getName());
        }
    }
}
 
Example 15
Source Project: cxf   File: CorbaStreamInInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 16
Source Project: cxf   File: SoapBindingFactoryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testNoBodyParts() throws Exception {
    Definition d = createDefinition("/wsdl_soap/no_body_parts.wsdl");
    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                    "NoBodyParts"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("urn:org:apache:cxf:no_body_parts/wsdl",
                                                          "operation1"));

    assertNotNull(boi);
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertNull(sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertNull(bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(0, parts.size());
}
 
Example 17
Source Project: cxf   File: SoapBindingFactoryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testFactory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);

    bus.getExtension(BindingFactoryManager.class);
    expectLastCall().andReturn(bfm).anyTimes();

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
    assertTrue(sbi.getSoapVersion() instanceof Soap11);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());
}
 
Example 18
Source Project: cxf   File: SoapBindingFactoryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testSoap12Factory() throws Exception {
    Definition d = createDefinition("/wsdl_soap/hello_world_soap12.wsdl");

    Bus bus = getMockBus();

    BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP12, bus);

    expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm);

    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);

    control.replay();

    WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
    ServiceInfo serviceInfo = builder
        .buildServices(d, new QName("http://apache.org/hello_world_soap12_http", "SOAPService"))
        .get(0);

    BindingInfo bi = serviceInfo.getBindings().iterator().next();

    assertTrue(bi instanceof SoapBindingInfo);

    SoapBindingInfo sbi = (SoapBindingInfo)bi;
    assertEquals("document", sbi.getStyle());
    assertEquals(WSDLConstants.NS_SOAP_HTTP_TRANSPORT, sbi.getTransportURI());
    assertTrue(sbi.getSoapVersion() instanceof Soap12);

    BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http",
                                                          "sayHi"));
    SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("sayHiAction", sboi.getAction());

    BindingMessageInfo input = boi.getInput();
    SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
    assertEquals("literal", bodyInfo.getUse());

    List<MessagePartInfo> parts = bodyInfo.getParts();
    assertNotNull(parts);
    assertEquals(1, parts.size());

    boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap12_http", "pingMe"));
    sboi = boi.getExtensor(SoapOperationInfo.class);
    assertNotNull(sboi);
    assertEquals("document", sboi.getStyle());
    assertEquals("", sboi.getAction());
    Collection<BindingFaultInfo> faults = boi.getFaults();
    assertEquals(1, faults.size());
    BindingFaultInfo faultInfo = boi.getFault(new QName("http://apache.org/hello_world_soap12_http",
                                                        "pingMeFault"));
    assertNotNull(faultInfo);
}