Java Code Examples for org.apache.cxf.service.model.BindingInfo#getOperations()

The following examples show how to use org.apache.cxf.service.model.BindingInfo#getOperations() . 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 File: ServiceProcessor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void processBindings(JavaModel model) {
    for (BindingInfo binding : service.getBindings()) {
        bindingType = getBindingType(binding);

        if (bindingType == null) {
            org.apache.cxf.common.i18n.Message msg =
                new org.apache.cxf.common.i18n.Message("BINDING_SPECIFY_ONE_PROTOCOL",
                                                       LOG,
                                                       binding.getName());
            throw new ToolException(msg);
        }

        Collection<BindingOperationInfo> operations = binding.getOperations();
        for (BindingOperationInfo bop : operations) {
            processOperation(model, bop, binding);
        }
    }
}
 
Example 2
Source File: RPCInInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private BindingOperationInfo getOperation(Message message, QName opName) {
    BindingOperationInfo bop = ServiceModelUtil.getOperation(message.getExchange(), opName);
    if (bop == null) {
        Endpoint ep = message.getExchange().getEndpoint();
        if (ep == null) {
            return null;
        }
        BindingInfo service = ep.getEndpointInfo().getBinding();
        boolean output = !isRequestor(message);
        for (BindingOperationInfo info : service.getOperations()) {
            if (info.getName().getLocalPart().equals(opName.getLocalPart())) {
                SoapBody body = null;
                if (output) {
                    body = info.getOutput().getExtensor(SoapBody.class);
                } else {
                    body = info.getInput().getExtensor(SoapBody.class);
                }
                if (body != null
                    && opName.getNamespaceURI().equals(body.getNamespaceURI())) {
                    return info;
                }
            }
        }
    }
    return bop;
}
 
Example 3
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBare() throws Exception {
    setUpWSDL(BARE_WSDL_PATH, 0);
    BindingInfo bindingInfo = null;
    bindingInfo = serviceInfo.getBindings().iterator().next();
    Collection<BindingOperationInfo> bindingOperationInfos = bindingInfo.getOperations();
    assertNotNull(bindingOperationInfos);
    assertEquals(bindingOperationInfos.size(), 1);
    LOG.info("the binding operation is " + bindingOperationInfos.iterator().next().getName());
    QName name = new QName(serviceInfo.getName().getNamespaceURI(), "greetMe");
    BindingOperationInfo greetMe = bindingInfo.getOperation(name);
    assertNotNull(greetMe);
    assertEquals("greetMe OperationInfo name error", greetMe.getName(), name);
    assertFalse("greetMe should be a Unwrapped operation ", greetMe.isUnwrappedCapable());

    assertNotNull(serviceInfo.getXmlSchemaCollection());
    control.verify();
}
 
Example 4
Source File: SimpleMethodDispatcher.java    From cxf with Apache License 2.0 6 votes vote down vote up
public BindingOperationInfo getBindingOperation(Method method, Endpoint endpoint) {
    Map<BindingInfo, BindingOperationInfo> bops = infoMap.get(method);
    if (bops == null) {
        return null;
    }

    BindingOperationInfo bop = bops.get(endpoint.getEndpointInfo().getBinding());
    if (bop == null) {
        OperationInfo o = methodToOp.get(method);
        if (o == null) {
            return null;
        }

        BindingInfo b = endpoint.getEndpointInfo().getBinding();
        for (BindingOperationInfo bop2 : b.getOperations()) {
            if (bop2.getOperationInfo().equals(o)) {
                BindingOperationInfo realBop = getRealOperation(o, bop2);

                bops.put(b, realBop);
                return realBop;
            }
        }
    }
    return bop;
}
 
Example 5
Source File: SoapClient.java    From jea with Apache License 2.0 5 votes vote down vote up
private QName getQName(Endpoint endpoint, String methodName){
       BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
       QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), methodName);
       
       if (bindingInfo.getOperation(opName) == null) {
           for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
               if (methodName.equals(operationInfo.getName().getLocalPart())) {
                   opName = operationInfo.getName();
                   break;
               }
           }
       }
       return opName;
}
 
Example 6
Source File: AbstractJAXRSFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected BindingInfo createBindingInfo() {
    BindingFactoryManager mgr = getBus().getExtension(BindingFactoryManager.class);
    String binding = getBindingId();
    BindingConfiguration bindingConfig = getBindingConfig();

    if (binding == null && bindingConfig != null) {
        binding = bindingConfig.getBindingId();
    }

    if (binding == null) {
        binding = JAXRSBindingFactory.JAXRS_BINDING_ID;
    }

    try {
        BindingFactory bindingFactory = mgr.getBindingFactory(binding);
        setBindingFactory(bindingFactory);
        BindingInfo bi = bindingFactory.createBindingInfo(serviceFactory.getService(),
                                                          binding, bindingConfig);
        for (BindingOperationInfo boi : bi.getOperations()) {
            serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_OPERATION_CREATED, bi, boi, null);
        }

        serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_CREATED, bi);
        return bi;
    } catch (BusException ex) {
        ex.printStackTrace();
        //do nothing
    }
    return null;
}
 
Example 7
Source File: RMEndpoint.java    From cxf with Apache License 2.0 5 votes vote down vote up
void setPolicies(Message message) {
    // use same WS-policies as for application endpoint
    PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
    if (null == engine || !engine.isEnabled()) {
        return;
    }

    for (Endpoint endpoint : endpoints.values()) {
        EndpointInfo ei = endpoint.getEndpointInfo();
        EndpointPolicy epi = null == conduit
            ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message)
                : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message);

        if (conduit != null) {
            engine.setClientEndpointPolicy(ei, epi);
        } else {
            engine.setServerEndpointPolicy(ei, epi);
        }
        EffectivePolicyImpl effectiveOutbound = new EffectivePolicyImpl();
        effectiveOutbound.initialise(epi, engine, false, false, message);
        EffectivePolicyImpl effectiveInbound = new EffectivePolicyImpl();
        effectiveInbound.initialise(epi, engine, true, false, message);

        BindingInfo bi = ei.getBinding();
        Collection<BindingOperationInfo> bois = bi.getOperations();

        for (BindingOperationInfo boi : bois) {
            engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound);
            engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound);

            engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound);
            engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
        }
    }

    // TODO: FaultPolicy (SequenceFault)
}
 
Example 8
Source File: WSDLServiceBuilderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindingOperationInfo() throws Exception {
    setUpBasic();
    BindingInfo bindingInfo = null;
    bindingInfo = serviceInfo.getBindings().iterator().next();
    Collection<BindingOperationInfo> bindingOperationInfos = bindingInfo.getOperations();
    assertNotNull(bindingOperationInfos);
    assertEquals(bindingOperationInfos.size(), 4);
    LOG.info("the binding operation is " + bindingOperationInfos.iterator().next().getName());

    QName name = new QName(serviceInfo.getName().getNamespaceURI(), "sayHi");
    BindingOperationInfo sayHi = bindingInfo.getOperation(name);
    assertNotNull(sayHi);
    assertEquals(sayHi.getName(), name);

    name = new QName(serviceInfo.getName().getNamespaceURI(), "greetMe");
    BindingOperationInfo greetMe = bindingInfo.getOperation(name);
    assertNotNull(greetMe);
    assertEquals(greetMe.getName(), name);

    name = new QName(serviceInfo.getName().getNamespaceURI(), "greetMeOneWay");
    BindingOperationInfo greetMeOneWay = bindingInfo.getOperation(name);
    assertNotNull(greetMeOneWay);
    assertEquals(greetMeOneWay.getName(), name);

    name = new QName(serviceInfo.getName().getNamespaceURI(), "pingMe");
    BindingOperationInfo pingMe = bindingInfo.getOperation(name);
    assertNotNull(pingMe);
    assertEquals(pingMe.getName(), name);
    control.verify();
}
 
Example 9
Source File: ServiceProcessor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private JavaPort processPort(JavaModel model, ServiceInfo si, EndpointInfo port) throws ToolException {
    BindingInfo binding = port.getBinding();
    String portType = binding.getInterface().getName().getLocalPart();
    JavaInterface intf = PortTypeProcessor.getInterface(context, si, binding.getInterface());
    JavaPort jport = new JavaPort(NameUtil.mangleNameToClassName(port.getName().getLocalPart()));
    jport.setPackageName(intf.getPackageName());

    jport.setPortName(port.getName().getLocalPart());
    jport.setBindingAdress(port.getAddress());
    jport.setBindingName(binding.getName().getLocalPart());


    jport.setPortType(portType);


    jport.setInterfaceClass(intf.getName());
    bindingType = getBindingType(binding);

    if (bindingType == null) {
        org.apache.cxf.common.i18n.Message msg =
            new org.apache.cxf.common.i18n.Message("BINDING_SPECIFY_ONE_PROTOCOL",
                                                   LOG,
                                                   binding.getName());
        throw new ToolException(msg);
    }

    if (isSoapBinding()) {
        SoapBinding spbd = SOAPBindingUtil.getProxy(SoapBinding.class, this.bindingObj);
        jport.setStyle(SOAPBindingUtil.getSoapStyle(spbd.getStyle()));
        jport.setTransURI(spbd.getTransportURI());
    }

    Collection<BindingOperationInfo> operations = binding.getOperations();
    for (BindingOperationInfo bop : operations) {
        processOperation(model, bop, binding);
    }
    jport.setJavaDoc(port.getDocumentation());
    JAXWSBinding bind = port.getExtensor(JAXWSBinding.class);
    if (bind != null) {
        jport.setMethodName(bind.getMethodName());
        jport.setJavaDoc(bind.getMethodJavaDoc());
    }

    return jport;
}
 
Example 10
Source File: JaxWsServerFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
protected BindingInfo createBindingInfo() {
    JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean)getServiceFactory();

    JaxWsImplementorInfo implInfo = sf.getJaxWsImplementorInfo();
    String jaxBid = implInfo.getBindingType();
    String binding = getBindingId();
    if (binding == null) {
        binding = jaxBid;
        setBindingId(binding);
    }

    if (binding.equals(SOAPBinding.SOAP11HTTP_BINDING)
        || binding.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
        binding = "http://schemas.xmlsoap.org/wsdl/soap/";
        setBindingId(binding);
        if (getBindingConfig() == null) {
            setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
        }
    } else if (binding.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
        binding = SOAPBinding.SOAP12HTTP_BINDING;
        setBindingId(binding);
        if (getBindingConfig() == null) {
            setBindingConfig(new JaxWsSoapBindingConfiguration(sf));
        }
    }

    if (getBindingConfig() instanceof JaxWsSoapBindingConfiguration) {
        JaxWsSoapBindingConfiguration conf = (JaxWsSoapBindingConfiguration)getBindingConfig();

        if (jaxBid.equals(SOAPBinding.SOAP12HTTP_BINDING)) {
            conf.setVersion(Soap12.getInstance());
        }

        if (jaxBid.equals(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
            conf.setVersion(Soap12.getInstance());
            conf.setMtomEnabled(true);
        }
        if (jaxBid.equals(SOAPBinding.SOAP11HTTP_MTOM_BINDING)) {
            conf.setMtomEnabled(true);
        }

        if (transportId != null) {
            conf.setTransportURI(transportId);
        }
        conf.setJaxWsServiceFactoryBean(sf);

    }

    BindingInfo bindingInfo = super.createBindingInfo();

    if (implInfo.isWebServiceProvider()) {
        bindingInfo.getService().setProperty("soap.force.doclit.bare", Boolean.TRUE);
        if (this.getServiceFactory().isPopulateFromClass()) {
            for (EndpointInfo ei : bindingInfo.getService().getEndpoints()) {
                ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
            }
            //Provider, but no wsdl.  Synthetic ops
            for (BindingOperationInfo op : bindingInfo.getOperations()) {
                op.setProperty("operation.is.synthetic", Boolean.TRUE);
                op.getOperationInfo().setProperty("operation.is.synthetic", Boolean.TRUE);
            }
        }
    }

    return bindingInfo;
}
 
Example 11
Source File: AbstractWSDLBasedEndpointFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected BindingInfo createBindingInfo() {
    BindingFactoryManager mgr = bus.getExtension(BindingFactoryManager.class);
    String binding = bindingId;

    if (binding == null && bindingConfig != null) {
        binding = bindingConfig.getBindingId();
    }

    if (binding == null) {
        // default to soap binding
        binding = "http://schemas.xmlsoap.org/soap/";
    }

    try {
        if (binding.contains("/soap")) {
            if (bindingConfig == null) {
                bindingConfig = createSoapBindingConfig();
            }
            if (bindingConfig instanceof SoapBindingConfiguration
                && !((SoapBindingConfiguration)bindingConfig).isSetStyle()) {
                ((SoapBindingConfiguration)bindingConfig).setStyle(serviceFactory.getStyle());
            }
        }

        bindingFactory = mgr.getBindingFactory(binding);

        BindingInfo inf = bindingFactory.createBindingInfo(serviceFactory.getService(),
                                                binding, bindingConfig);

        for (BindingOperationInfo boi : inf.getOperations()) {
            serviceFactory.updateBindingOperation(boi);
            Method m = serviceFactory.getMethodDispatcher().getMethod(boi);
            serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_OPERATION_CREATED, inf, boi, m);
        }
        serviceFactory.sendEvent(FactoryBeanListener.Event.BINDING_CREATED, inf);
        return inf;
    } catch (BusException ex) {
        throw new ServiceConstructionException(
               new Message("COULD.NOT.RESOLVE.BINDING", LOG, bindingId), ex);
    }
}
 
Example 12
Source File: XMLFormatValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private boolean checkXMLFormat(BindingInfo binding) {
    Collection<BindingOperationInfo> bos = binding.getOperations();
    boolean result = true;
    boolean needRootNode = false;
    for (BindingOperationInfo bo : bos) {
        OperationInfo op = binding.getInterface().getOperation(bo.getName());
        needRootNode = false;
        final int inputPartsNum = op.getInput().getMessagePartsNumber();
        if (inputPartsNum == 0 || inputPartsNum > 1) {
            needRootNode = true;
        }
        if (needRootNode) {
            String path = "Binding(" + binding.getName().getLocalPart()
                + "):BindingOperation(" + bo.getName() + ")";
            List<XMLBindingMessageFormat> inExtensors =
                bo.getInput().getExtensors(XMLBindingMessageFormat.class);
            Iterator<XMLBindingMessageFormat> itIn = null;
            if (inExtensors != null) {
                itIn = inExtensors.iterator();
            }
            if (!findXMLFormatRootNode(itIn, bo, path + "-input")) {
                return false;
            }
            // Input check correct, continue to check output binding
            if (op.getOutput() != null) {
                needRootNode = false;
                final int outputPartsNum = op.getOutput().getMessagePartsNumber();
                if (outputPartsNum == 0 || outputPartsNum > 1) {
                    needRootNode = true;
                }
                if (needRootNode) {
                    List<XMLBindingMessageFormat> outExtensors =
                        bo.getOutput().getExtensors(XMLBindingMessageFormat.class);
                    Iterator<XMLBindingMessageFormat> itOut = null;
                    if (outExtensors != null) {
                        itOut = outExtensors.iterator();
                    }
                    result = result
                        && findXMLFormatRootNode(itOut, bo, path + "-Output");
                    if (!result) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}