Search in sources :

Example 1 with MetadataExchange

use of org.apache.cxf.ws.mex.MetadataExchange in project cxf by apache.

the class IssueUnitTest method testRetrieveWSMEX.

@org.junit.Test
public void testRetrieveWSMEX() throws Exception {
    createBus(getClass().getResource("cxf-client.xml").toString());
    // Get Metadata
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setBindingId(SoapBindingConstants.SOAP11_BINDING_ID);
    proxyFac.setAddress("https://localhost:" + STSPORT + "/SecurityTokenService/Transport/mex");
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    // Parse response (as per the STSClient)
    Definition definition = null;
    // 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());
        }
    }
    assertNotNull(definition);
}
Also used : MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) Element(org.w3c.dom.Element) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) Definition(javax.wsdl.Definition) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange)

Example 2 with MetadataExchange

use of org.apache.cxf.ws.mex.MetadataExchange in project jbossws-cxf by jbossws.

the class WSMexTestCase method testEndpoint.

@Test
@RunAsClient
public void testEndpoint() throws Exception {
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress(baseURL + "/jaxws-cxf-wsmex/EndpointService");
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    assertNotNull(metadata);
    assertEquals(1, metadata.getMetadataSection().size());
    MetadataSection ms = metadata.getMetadataSection().get(0);
    assertEquals("http://schemas.xmlsoap.org/wsdl/", ms.getDialect());
    assertEquals("http://org.jboss.ws/cxf/wsmex", ms.getIdentifier());
    String wsdl = DOMWriter.printNode((Node) ms.getAny(), true);
    assertTrue(wsdl.contains("EndpointBeanServiceSoapBinding"));
}
Also used : MetadataSection(org.apache.cxf.ws.mex.model._2004_09.MetadataSection) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 3 with MetadataExchange

use of org.apache.cxf.ws.mex.MetadataExchange in project cxf by apache.

the class MEXTest method testGet.

@Test
public void testGet() {
    // Create the client
    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setBus(getStaticBus());
    proxyFac.setAddress("http://localhost:" + PORT + "/jaxws/addmex");
    proxyFac.getFeatures().add(new LoggingFeature());
    MetadataExchange exc = proxyFac.create(MetadataExchange.class);
    Metadata metadata = exc.get2004();
    assertNotNull(metadata);
    assertEquals(2, metadata.getMetadataSection().size());
    assertEquals("http://schemas.xmlsoap.org/wsdl/", metadata.getMetadataSection().get(0).getDialect());
    assertEquals("http://apache.org/cxf/systest/ws/addr_feature/", metadata.getMetadataSection().get(0).getIdentifier());
    assertEquals("http://www.w3.org/2001/XMLSchema", metadata.getMetadataSection().get(1).getDialect());
    GetMetadata body = new GetMetadata();
    body.setDialect("http://www.w3.org/2001/XMLSchema");
    metadata = exc.getMetadata(body);
    assertEquals(1, metadata.getMetadataSection().size());
    assertEquals("http://www.w3.org/2001/XMLSchema", metadata.getMetadataSection().get(0).getDialect());
}
Also used : GetMetadata(org.apache.cxf.ws.mex.model._2004_09.GetMetadata) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Metadata(org.apache.cxf.ws.mex.model._2004_09.Metadata) GetMetadata(org.apache.cxf.ws.mex.model._2004_09.GetMetadata) MetadataExchange(org.apache.cxf.ws.mex.MetadataExchange) Test(org.junit.Test)

Example 4 with MetadataExchange

use of org.apache.cxf.ws.mex.MetadataExchange 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)

Aggregations

JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)4 MetadataExchange (org.apache.cxf.ws.mex.MetadataExchange)4 Metadata (org.apache.cxf.ws.mex.model._2004_09.Metadata)4 MetadataSection (org.apache.cxf.ws.mex.model._2004_09.MetadataSection)3 Definition (javax.wsdl.Definition)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Types (javax.wsdl.Types)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 Schema (javax.wsdl.extensions.schema.Schema)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 BusException (org.apache.cxf.BusException)1 ModCountCopyOnWriteArrayList (org.apache.cxf.common.util.ModCountCopyOnWriteArrayList)1 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)1 ClientImpl (org.apache.cxf.endpoint.ClientImpl)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 EndpointException (org.apache.cxf.endpoint.EndpointException)1