protected Operation findOperation()

in shared-libraries/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java [266:332]


    protected Operation findOperation(Context context) throws Exception {
        QName interfaceName = (QName) context.getProperty(Context.INTERFACE);
        QName serviceName = (QName) context.getProperty(Context.SERVICE);
        String endpointName = (String) context.getProperty(Context.ENDPOINT);
        ComponentContext componentContext = endpoint.getServiceUnit().getComponent().getComponentContext();
        QName bodyName = context.getInMessage().getBodyName();
        
        // Find target endpoint
        ServiceEndpoint se = null;
        if (serviceName != null && endpointName != null) {
            se = componentContext.getEndpoint(serviceName, endpointName);
        }
        if (se == null && interfaceName != null) {
            ServiceEndpoint[] ses = componentContext.getEndpoints(interfaceName);
            if (ses != null && ses.length > 0) {
                se = ses[0];
            }
        }
        
        // Find WSDL description
        Definition definition = null;
        if (se != null) {
            // Find endpoint description from the component context
            definition = getDefinition(se);
        }
        if (definition == null) {
            // Get this endpoint definition
            definition = endpoint.getDefinition();
        }

        // Find operation matching 
        if (definition != null) {
            if (interfaceName != null) {
                PortType portType = definition.getPortType(interfaceName);
                if (portType != null) {
                    return findOperationFor(portType, bodyName);
                }
            } else if (definition.getService(serviceName) != null) {
                Service service = definition.getService(serviceName);
                if (endpointName != null) {
                    Port port = service.getPort(endpointName);
                    if (port != null) {
                        Binding binding = port.getBinding();
                        if (binding != null) {
                            PortType portType = binding.getPortType();
                            if (portType != null) {
                                return findOperationFor(portType, bodyName);
                            }
                        }
                    }
                } else if (service.getPorts().size() == 1) {
                    Port port = (Port) service.getPorts().values().iterator().next();
                    Binding binding = port.getBinding();
                    if (binding != null) {
                        PortType portType = binding.getPortType();
                        if (portType != null) {
                            return findOperationFor(portType, bodyName);
                        }
                    }
                }
            } else if (definition.getPortTypes().size() == 1) {
                PortType portType = (PortType) definition.getPortTypes().values().iterator().next();
                return findOperationFor(portType, bodyName);
            }
        }
        return null;
    }