Java Code Examples for javax.wsdl.Definition#setExtensionRegistry()

The following examples show how to use javax.wsdl.Definition#setExtensionRegistry() . 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: WSDLSchemaManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Definition createWSDLDefinition(String tns) throws WSDLException, JAXBException {
    WSDLManager wm = BusFactory.getThreadDefaultBus().getExtension(WSDLManager.class);
    WSDLFactory wsdlFactory = wm.getWSDLFactory();
    Definition wsdlDefinition = wsdlFactory.newDefinition();
    wsdlDefinition.setExtensionRegistry(wm.getExtensionRegistry());
    wsdlDefinition.setTargetNamespace(tns);
    wsdlDefinition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    wsdlDefinition.addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
    wsdlDefinition.addNamespace(WSDLConstants.SOAP11_PREFIX, WSDLConstants.NS_SOAP11);
    wsdlDefinition.addNamespace("tns", tns);
    wsdlDefinition.addNamespace(CorbaConstants.NP_WSDL_CORBA, CorbaConstants.NU_WSDL_CORBA);
    defns.put(tns, wsdlDefinition);
    return wsdlDefinition;
}
 
Example 2
Source File: WSDLASTVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Definition getPhysicalDefinition(Definition logicalDef, boolean schemaOnly)
    throws WSDLException, JAXBException {

    Definition def = null;
    if (schemaOnly) {
        def = logicalDef;
    } else {
        def = manager.createWSDLDefinition(targetNamespace);
    }

    Collection<String> namespaces = CastUtils.cast(definition.getNamespaces().values());
    for (String namespace : namespaces) {
        String prefix = definition.getPrefix(namespace);
        def.addNamespace(prefix, namespace);
    }
    Collection<Binding> bindings = CastUtils.cast(definition.getAllBindings().values());
    for (Binding binding : bindings) {
        def.addBinding(binding);
    }
    Collection<Service> services = CastUtils.cast(definition.getAllServices().values());
    for (Service service : services) {
        def.addService(service);
    }
    Collection<ExtensibilityElement> extns = CastUtils.cast(definition.getExtensibilityElements());
    for (ExtensibilityElement ext : extns) {
        def.addExtensibilityElement(ext);
    }

    def.setExtensionRegistry(definition.getExtensionRegistry());

    return def;
}
 
Example 3
Source File: SchemaFactoryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance of a Definition, with an instance of a
 * PopulatedExtensionRegistry as its ExtensionRegistry.
 *
 */
public Definition newDefinition() {
    Definition def = factory.newDefinition();
    ExtensionRegistry extReg = newPopulatedExtensionRegistry();

    def.setExtensionRegistry(extReg);

    return def;
}
 
Example 4
Source File: WSDLCorbaFactoryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance of a Definition, with an instance of a
 * PopulatedExtensionRegistry as its ExtensionRegistry.
 */
public Definition newDefinition() {
    Definition def = factory.newDefinition();
    ExtensionRegistry extReg = newPopulatedExtensionRegistry();
    def.setExtensionRegistry(extReg);
    return def;
}
 
Example 5
Source File: JaxWsServerFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleServiceClass() throws Exception {
    ServerFactoryBean factory = new ServerFactoryBean();
    factory.setServiceClass(Hello.class);
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    Server server = factory.create();
    Endpoint endpoint = server.getEndpoint();
    ServiceInfo service = endpoint.getEndpointInfo().getService();
    assertNotNull(service);

    Bus bus = factory.getBus();
    Definition def = new ServiceWSDLBuilder(bus, service).build();

    WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    Document doc = wsdlWriter.getDocument(def);

    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils xpather = new XPathUtils(ns);
    xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
                    + address + "']",
                    doc,
                    XPathConstants.NODE);
}
 
Example 6
Source File: JaxWsServerFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJaxwsServiceClass() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(CalculatorPortType.class);
    factory.setServiceBean(new CalculatorImpl());
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    Server server = factory.create();
    Endpoint endpoint = server.getEndpoint();
    ServiceInfo service = endpoint.getEndpointInfo().getService();
    assertNotNull(service);

    Bus bus = factory.getBus();
    Definition def = new ServiceWSDLBuilder(bus, service).build();

    WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    Document doc = wsdlWriter.getDocument(def);

    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils xpather = new XPathUtils(ns);
    xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
                    + address + "']",
                    doc,
                    XPathConstants.NODE);
}
 
Example 7
Source File: WSDLGetUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Write the contents of a wsdl Definition object to a file.
 *
 * @param message
 * @param mp  a map of known wsdl Definition objects
 * @param smp a map of known xsd SchemaReference objects
 * @param wsdl name of the wsdl file to write
 * @param base the request URL
 * @param endpointInfo information for a web service 'port' inside of a service
 * @return Document
 * @throws WSDLException
 */
public Document writeWSDLDocument(Message message,
                                  Map<String, Definition> mp,
                                  Map<String, SchemaReference> smp,
                                  String wsdl,
                                  String base,
                                  EndpointInfo endpointInfo) throws WSDLException {

    Document doc;
    Bus bus = message.getExchange().getBus();
    Definition def = lookupDefinition(bus, mp, wsdl, base);
    String epurl = base;

    synchronized (def) {
        //writing a def is not threadsafe.  Sync on it to make sure
        //we don't get any ConcurrentModificationExceptions
        epurl = getPublishableEndpointUrl(def, epurl, endpointInfo);

        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
            .getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        doc = wsdlWriter.getDocument(def);
    }

    updateDoc(doc, epurl, mp, smp, message, wsdl);
    return doc;
}
 
Example 8
Source File: ServiceWSDLBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Definition newDefinition(final QName name, String targetNamespace) {
    Definition d = bus.getExtension(WSDLManager.class).getWSDLFactory().newDefinition();
    d.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    d.setQName(name);
    d.setTargetNamespace(targetNamespace);
    addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD, d);
    return d;
}
 
Example 9
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotations() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setStart(false);
    List<String> tp = Arrays.asList(
        "http://schemas.xmlsoap.org/soap/http",
        "http://schemas.xmlsoap.org/wsdl/http/",
        "http://schemas.xmlsoap.org/wsdl/soap/http",
        "http://www.w3.org/2003/05/soap/bindings/HTTP/",
        "http://cxf.apache.org/transports/http/configuration",
        "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);

    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus,
                                                            s.getEndpoint().getService()
                                                                .getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
            .getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu",
               "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        //org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input",
              "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output",
              "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestImplServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input",
              "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
              "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");

        assertEquals(1,
                     xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/"
                                          + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl)
                         .getLength());

        EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
            .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
        assertEquals(1, policy.getChosenAlternative().size());
    } finally {
        bus.shutdown(true);
    }
}
 
Example 10
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotationsInterfaceAsClass() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setServiceClass(TestInterface.class);
    factory.setStart(false);
    List<String> tp = Arrays.asList(
        "http://schemas.xmlsoap.org/soap/http",
        "http://schemas.xmlsoap.org/wsdl/http/",
        "http://schemas.xmlsoap.org/wsdl/soap/http",
        "http://www.w3.org/2003/05/soap/bindings/HTTP/",
        "http://cxf.apache.org/transports/http/configuration",
        "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);


    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus,
                                                            s.getEndpoint().getService()
                                                                .getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class)
            .getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu",
               "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        //org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestInterfacePortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input",
              "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output",
              "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/",
              "TestInterfaceServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input",
              "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output",
              "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestInterfaceServiceServicePolicy");

        assertEquals(1,
                     xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/"
                                          + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl)
                         .getLength());

    } finally {
        bus.shutdown(true);
    }
}
 
Example 11
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotationImplNoInterface() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/",
            "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/",
            "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);

    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);

        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1,
                xpu.getValueList("/wsdl:definitions/wsdl:binding/"
                    + "wsp:PolicyReference[@URI='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']", wsdl)
                    .getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
                .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
 
Example 12
Source File: PolicyAnnotationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testAnnotationImplNoInterfacePolicies() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplWithPoliciesNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/",
            "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/",
            "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");

    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);

    Server s = factory.create();

    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();

        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);

        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1,
                xpu.getValueList("/wsdl:definitions/wsdl:binding/"
                + "wsp:PolicyReference[@URI='#TestImplWithPoliciesNoInterfaceServiceSoapBindingBindingPolicy']",
                        wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class)
                .getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}