Search in sources :

Example 16 with EndpointImpl

use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.

the class AbstractWSDLBasedEndpointFactory method createEndpoint.

protected Endpoint createEndpoint() throws BusException, EndpointException {
    serviceFactory.setFeatures(getFeatures());
    if (serviceName != null) {
        serviceFactory.setServiceName(serviceName);
    }
    if (endpointName != null) {
        serviceFactory.setEndpointName(endpointName);
    }
    Service service = serviceFactory.getService();
    if (service == null) {
        initializeServiceFactory();
        service = serviceFactory.create();
    }
    if (endpointName == null) {
        endpointName = serviceFactory.getEndpointName();
    }
    EndpointInfo ei = service.getEndpointInfo(endpointName);
    if (ei != null) {
        if ((transportId != null && !ei.getTransportId().equals(transportId)) || (bindingId != null && !ei.getBinding().getBindingId().equals(bindingId))) {
            ei = null;
        } else {
            BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
            bindingFactory = bfm.getBindingFactory(ei.getBinding().getBindingId());
        }
    }
    if (ei == null) {
        if (getAddress() == null) {
            ei = ServiceModelUtil.findBestEndpointInfo(serviceFactory.getInterfaceName(), service.getServiceInfos());
        }
        if (ei == null && !serviceFactory.isPopulateFromClass()) {
            ei = ServiceModelUtil.findBestEndpointInfo(serviceFactory.getInterfaceName(), service.getServiceInfos());
            if (ei != null) {
                BindingFactoryManager bfm = getBus().getExtension(BindingFactoryManager.class);
                bindingFactory = bfm.getBindingFactory(ei.getBinding().getBindingId());
            }
            if (ei == null) {
                LOG.warning("Could not find endpoint/port for " + endpointName + " in wsdl. Creating default.");
            } else if (!ei.getName().equals(endpointName)) {
                LOG.warning("Could not find endpoint/port for " + endpointName + " in wsdl. Using " + ei.getName() + ".");
            }
        }
        if (ei == null) {
            ei = createEndpointInfo(null);
        } else if (transportId != null && !ei.getTransportId().equals(transportId)) {
            LOG.warning("Transport for endpoint/port " + endpointName + " in wsdl doesn't match " + transportId + ".");
            BindingInfo bi = ei.getBinding();
            ei = createEndpointInfo(bi);
        } else if (bindingId != null && !ei.getBinding().getBindingId().equals(bindingId) && // consider SoapBinding has multiple default namespace
        !(SoapBindingFactory.DEFAULT_NAMESPACES.contains(bindingId) && SoapBindingFactory.DEFAULT_NAMESPACES.contains(ei.getBinding().getBindingId()))) {
            LOG.warning("Binding for endpoint/port " + endpointName + " in wsdl doesn't match " + bindingId + ".");
            ei = createEndpointInfo(null);
        } else if (getAddress() != null) {
            ei.setAddress(getAddress());
            if (ei.getAddress().startsWith("camel") || ei.getAddress().startsWith("local")) {
                modifyTransportIdPerAddress(ei);
            }
        }
    } else if (getAddress() != null) {
        ei.setAddress(getAddress());
    }
    if (publishedEndpointUrl != null && !"".equals(publishedEndpointUrl)) {
        ei.setProperty("publishedEndpointUrl", publishedEndpointUrl);
    }
    if (endpointReference != null) {
        ei.setAddress(endpointReference);
    }
    Endpoint ep = service.getEndpoints().get(ei.getName());
    if (ep == null) {
        ep = serviceFactory.createEndpoint(ei);
        ((EndpointImpl) ep).initializeActiveFeatures(getFeatures());
    } else {
        serviceFactory.setEndpointName(ei.getName());
        if (ep.getActiveFeatures() == null) {
            ((EndpointImpl) ep).initializeActiveFeatures(getFeatures());
        }
    }
    if (properties != null) {
        ep.putAll(properties);
    }
    service.getEndpoints().put(ep.getEndpointInfo().getName(), ep);
    if (getInInterceptors() != null) {
        ep.getInInterceptors().addAll(getInInterceptors());
        ep.getInInterceptors().add(WSDLGetInterceptor.INSTANCE);
    }
    if (getOutInterceptors() != null) {
        ep.getOutInterceptors().addAll(getOutInterceptors());
    }
    if (getInFaultInterceptors() != null) {
        ep.getInFaultInterceptors().addAll(getInFaultInterceptors());
    }
    if (getOutFaultInterceptors() != null) {
        ep.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
    }
    serviceFactory.sendEvent(FactoryBeanListener.Event.ENDPOINT_SELECTED, ei, ep, serviceFactory.getServiceClass(), getServiceClass());
    return ep;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager)

Example 17 with EndpointImpl

use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.

the class ManagedRMManagerTest method createTestEndpoint.

private Endpoint createTestEndpoint() throws Exception {
    ServiceInfo svci = new ServiceInfo();
    svci.setName(new QName(TEST_URI, "testService"));
    Service svc = new ServiceImpl(svci);
    SoapBindingInfo binding = new SoapBindingInfo(svci, WSDLConstants.NS_SOAP11);
    binding.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress(TEST_URI);
    ei.setName(new QName(TEST_URI, "testPort"));
    ei.setBinding(binding);
    ei.setService(svci);
    return new EndpointImpl(bus, svc, ei);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) QName(javax.xml.namespace.QName) ServiceImpl(org.apache.cxf.service.ServiceImpl) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) Service(org.apache.cxf.service.Service)

Example 18 with EndpointImpl

use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.

the class ServiceModelUtilsTest method getService.

private Service getService(URL wsdl, Class<?> implClz, QName port) throws EndpointException {
    assertNotNull(wsdl);
    bean.setWsdlURL(wsdl.toString());
    bean.setServiceClass(implClz);
    Service service = bean.create();
    EndpointInfo endpointInfo = service.getServiceInfos().get(0).getEndpoint(port);
    Endpoint endpoint = new EndpointImpl(getBus(), service, endpointInfo);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    return service;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service)

Example 19 with EndpointImpl

use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.

the class AbstractSTSClient method configureViaEPR.

public void configureViaEPR(EndpointReferenceType ref, boolean useEPRWSAAddrAsMEXLocation) {
    if (client != null) {
        return;
    }
    location = EndpointReferenceUtils.getAddress(ref);
    if (location != null) {
        location = location.trim();
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("EPR address: " + location);
    }
    final QName sName = EndpointReferenceUtils.getServiceName(ref, bus);
    if (sName != null) {
        serviceName = sName;
        final QName epName = EndpointReferenceUtils.getPortQName(ref, bus);
        if (epName != null) {
            endpointName = epName;
        }
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("EPR endpoint: " + serviceName + " " + endpointName);
        }
    }
    final String wsdlLoc = EndpointReferenceUtils.getWSDLLocation(ref);
    if (wsdlLoc != null) {
        wsdlLocation = wsdlLoc;
    }
    String mexLoc = findMEXLocation(ref, useEPRWSAAddrAsMEXLocation);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("WS-MEX location: " + mexLoc);
    }
    if (mexLoc != null) {
        try {
            JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
            proxyFac.setBindingId(soapVersion);
            proxyFac.setAddress(mexLoc);
            MetadataExchange exc = proxyFac.create(MetadataExchange.class);
            Metadata metadata = exc.get2004();
            Definition definition = null;
            List<Schema> schemas = new ArrayList<>();
            // Parse the MetadataSections into WSDL definition + associated schemas
            for (MetadataSection s : metadata.getMetadataSection()) {
                if ("http://schemas.xmlsoap.org/wsdl/".equals(s.getDialect())) {
                    definition = bus.getExtension(WSDLManager.class).getDefinition((Element) s.getAny());
                } else if ("http://www.w3.org/2001/XMLSchema".equals(s.getDialect())) {
                    Element schemaElement = (Element) s.getAny();
                    if (schemaElement == null) {
                        String schemaLocation = s.getLocation();
                        LOG.info("XSD schema location: " + schemaLocation);
                        schemaElement = downloadSchema(schemaLocation);
                    }
                    QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
                    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
                    ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
                    ((Schema) exElement).setElement(schemaElement);
                    schemas.add((Schema) exElement);
                }
            }
            if (definition != null) {
                // Add any extra schemas to the WSDL definition
                for (Schema schema : schemas) {
                    definition.getTypes().addExtensibilityElement(schema);
                }
                WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
                SourceDataBinding dataBinding = new SourceDataBinding();
                factory.setDataBinding(dataBinding);
                Service service = factory.create();
                service.setDataBinding(dataBinding);
                // Get the endpoint + service names by matching the 'location' to the
                // address in the WSDL. If the 'location' is 'anonymous' then just fall
                // back to the first service + endpoint name in the WSDL, if the endpoint
                // name is not defined in the Metadata
                List<ServiceInfo> services = service.getServiceInfos();
                String anonymousAddress = "http://www.w3.org/2005/08/addressing/anonymous";
                if (!anonymousAddress.equals(location)) {
                    for (ServiceInfo serv : services) {
                        for (EndpointInfo ei : serv.getEndpoints()) {
                            if (ei.getAddress().equals(location)) {
                                endpointName = ei.getName();
                                serviceName = serv.getName();
                                LOG.fine("Matched endpoint to location");
                            }
                        }
                    }
                }
                EndpointInfo ei = service.getEndpointInfo(endpointName);
                if (ei == null && anonymousAddress.equals(location) && !services.isEmpty() && !services.get(0).getEndpoints().isEmpty()) {
                    LOG.fine("Anonymous location so taking first endpoint");
                    serviceName = services.get(0).getName();
                    endpointName = services.get(0).getEndpoints().iterator().next().getName();
                    ei = service.getEndpointInfo(endpointName);
                }
                if (ei == null) {
                    throw new TrustException(LOG, "ADDRESS_NOT_MATCHED", location);
                }
                if (location != null && !anonymousAddress.equals(location)) {
                    ei.setAddress(location);
                }
                Endpoint endpoint = new EndpointImpl(bus, service, ei);
                client = new ClientImpl(bus, endpoint);
            }
        } catch (Exception ex) {
            throw new TrustException("WS_MEX_ERROR", ex, LOG);
        }
    }
}
Also used : Types(javax.wsdl.Types) MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) Schema(javax.wsdl.extensions.schema.Schema) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) ArrayList(java.util.ArrayList) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) Base64DecodingException(org.apache.xml.security.exceptions.Base64DecodingException) EndpointException(org.apache.cxf.endpoint.EndpointException) BusException(org.apache.cxf.BusException) WSDLManager(org.apache.cxf.wsdl.WSDLManager)

Example 20 with EndpointImpl

use of org.apache.cxf.endpoint.EndpointImpl in project cxf by apache.

the class STSUtils method createSTSEndpoint.

// CHECKSTYLE:OFF
private static Endpoint createSTSEndpoint(Bus bus, String namespace, String transportId, String location, String soapVersion, Policy policy, QName epName, boolean sc) throws BusException, EndpointException {
    // CHECKSTYLE:ON
    String ns = namespace + "/wsdl";
    ServiceInfo si = new ServiceInfo();
    QName iName = new QName(ns, sc ? "SecureConversationTokenService" : "SecurityTokenService");
    si.setName(iName);
    InterfaceInfo ii = new InterfaceInfo(si, iName);
    OperationInfo ioi = addIssueOperation(ii, namespace, ns);
    OperationInfo coi = addCancelOperation(ii, namespace, ns);
    OperationInfo roi = addRenewOperation(ii, namespace, ns);
    si.setInterface(ii);
    Service service = new ServiceImpl(si);
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    BindingFactory bindingFactory = bfm.getBindingFactory(soapVersion);
    BindingInfo bi = bindingFactory.createBindingInfo(service, soapVersion, null);
    si.addBinding(bi);
    if (transportId == null) {
        ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
        ConduitInitiator ci = cim.getConduitInitiatorForUri(location);
        transportId = ci.getTransportIds().get(0);
    }
    EndpointInfo ei = new EndpointInfo(si, transportId);
    ei.setBinding(bi);
    ei.setName(epName == null ? iName : epName);
    ei.setAddress(location);
    si.addEndpoint(ei);
    if (policy != null) {
        ei.addExtensor(policy);
    }
    BindingOperationInfo boi = bi.getOperation(ioi);
    SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT" : "/RST/Issue"));
    boi = bi.getOperation(coi);
    soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT/Cancel" : "/RST/Cancel"));
    boi = bi.getOperation(roi);
    soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        soi = new SoapOperationInfo();
        boi.addExtensor(soi);
    }
    soi.setAction(namespace + (sc ? "/RST/SCT/Renew" : "/RST/Renew"));
    service.setDataBinding(new SourceDataBinding());
    return new EndpointImpl(bus, service, ei);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) QName(javax.xml.namespace.QName) ServiceImpl(org.apache.cxf.service.ServiceImpl) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) Service(org.apache.cxf.service.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingInfo(org.apache.cxf.service.model.BindingInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) BindingFactory(org.apache.cxf.binding.BindingFactory)

Aggregations

EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)31 Endpoint (org.apache.cxf.endpoint.Endpoint)24 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)18 Service (org.apache.cxf.service.Service)14 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)13 QName (javax.xml.namespace.QName)12 Exchange (org.apache.cxf.message.Exchange)12 MessageImpl (org.apache.cxf.message.MessageImpl)12 WSDLServiceFactory (org.apache.cxf.wsdl11.WSDLServiceFactory)9 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 Feature (org.apache.cxf.feature.Feature)7 ServiceImpl (org.apache.cxf.service.ServiceImpl)7 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 Bus (org.apache.cxf.Bus)6 Message (org.apache.cxf.message.Message)6 ArrayList (java.util.ArrayList)5 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)5 AbstractFeature (org.apache.cxf.feature.AbstractFeature)5 List (java.util.List)4 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)4