Search in sources :

Example 16 with EndpointImpl

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

the class SpringBeansTest method testEndpoints.

@Test
public void testEndpoints() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/endpoints.xml" });
    EndpointImpl ep = getEndpointImplBean("simple", ctx);
    assertNotNull(ep.getImplementor());
    assertNotNull(ep.getServer());
    ep = getEndpointImplBean("simpleWithAddress", ctx);
    if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
        fail("can't get the right implementor object");
    }
    assertEquals("http://localhost:8080/simpleWithAddress", ep.getServer().getEndpoint().getEndpointInfo().getAddress());
    ep = getEndpointImplBean("inlineImplementor", ctx);
    if (!(ep.getImplementor() instanceof org.apache.hello_world_soap_http.GreeterImpl)) {
        fail("can't get the right implementor object");
    }
    org.apache.hello_world_soap_http.GreeterImpl impl = (org.apache.hello_world_soap_http.GreeterImpl) ep.getImplementor();
    assertEquals("The property was not injected rightly", impl.getPrefix(), "hello");
    assertNotNull(ep.getServer());
    ep = getEndpointImplBean("inlineInvoker", ctx);
    assertTrue(ep.getInvoker() instanceof NullInvoker);
    assertTrue(ep.getService().getInvoker() instanceof NullInvoker);
    ep = getEndpointImplBean("simpleWithBindingUri", ctx);
    assertEquals("get the wrong bindingId", ep.getBindingUri(), "http://cxf.apache.org/bindings/xformat");
    assertEquals("get a wrong transportId", "http://cxf.apache.org/transports/local", ep.getTransportId());
    ep = getEndpointImplBean("simpleWithBinding", ctx);
    BindingConfiguration bc = ep.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
    ep = getEndpointImplBean("implementorClass", ctx);
    assertEquals(Hello.class, ep.getImplementorClass());
    assertTrue(ep.getImplementor().getClass() == Object.class);
    ep = getEndpointImplBean("epWithProps", ctx);
    assertEquals("bar", ep.getProperties().get("foo"));
    ep = getEndpointImplBean("classImpl", ctx);
    assertTrue(ep.getImplementor() instanceof Hello);
    QName name = ep.getServer().getEndpoint().getService().getName();
    assertEquals("http://service.jaxws.cxf.apache.org/service", name.getNamespaceURI());
    assertEquals("HelloServiceCustomized", name.getLocalPart());
    name = ep.getServer().getEndpoint().getEndpointInfo().getName();
    assertEquals("http://service.jaxws.cxf.apache.org/endpoint", name.getNamespaceURI());
    assertEquals("HelloEndpointCustomized", name.getLocalPart());
    Object bean = ctx.getBean("wsdlLocation");
    assertNotNull(bean);
    ep = getEndpointImplBean("publishedEndpointUrl", ctx);
    String expectedEndpointUrl = "http://cxf.apache.org/Greeter";
    assertEquals(expectedEndpointUrl, ep.getPublishedEndpointUrl());
    ep = getEndpointImplBean("epWithDataBinding", ctx);
    DataBinding dataBinding = ep.getDataBinding();
    assertTrue(dataBinding instanceof JAXBDataBinding);
    assertEquals("The namespace map should have an entry", ((JAXBDataBinding) dataBinding).getNamespaceMap().size(), 1);
    // test for existence of Endpoint without an id element
    boolean found = false;
    String[] names = ctx.getBeanNamesForType(EndpointImpl.class);
    for (String n : names) {
        if (n.startsWith(EndpointImpl.class.getPackage().getName())) {
            found = true;
        }
    }
    assertTrue("Could not find server factory with autogenerated id", found);
    ep = getEndpointImplBean("unpublishedEndpoint", ctx);
    assertFalse("Unpublished endpoint is published", ep.isPublished());
    testInterceptors(ctx);
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) Hello(org.apache.cxf.jaxws.service.Hello) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Example 17 with EndpointImpl

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

the class SpringBeansTest method testTwoEndpointsWithTwoBuses.

@Test
public void testTwoEndpointsWithTwoBuses() throws Exception {
    ClassPathXmlApplicationContext ctx = null;
    Bus cxf1 = null;
    Bus cxf2 = null;
    try {
        ctx = new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/endpoints2.xml");
        EndpointImpl ep1 = (EndpointImpl) ctx.getBean("ep1");
        assertNotNull(ep1);
        cxf1 = (Bus) ctx.getBean("cxf1");
        assertNotNull(cxf1);
        assertEquals(cxf1, ep1.getBus());
        assertEquals("barf", ep1.getBus().getProperty("foo"));
        EndpointImpl ep2 = (EndpointImpl) ctx.getBean("ep2");
        assertNotNull(ep2);
        cxf2 = (Bus) ctx.getBean("cxf2");
        assertNotNull(cxf2);
        assertEquals(cxf2, ep2.getBus());
        assertEquals("snarf", ep2.getBus().getProperty("foo"));
    } finally {
        if (cxf1 != null) {
            cxf1.shutdown(true);
        }
        if (cxf2 != null) {
            cxf2.shutdown(true);
        }
        if (ctx != null) {
            ctx.close();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) Test(org.junit.Test)

Example 18 with EndpointImpl

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

the class SpringBeansTest method testInterceptors.

private void testInterceptors(ClassPathXmlApplicationContext ctx) {
    EndpointImpl ep;
    ep = (EndpointImpl) ctx.getBean("epWithInterceptors");
    assertNotNull(ep);
    List<Interceptor<? extends Message>> inInterceptors = ep.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : ep.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Message(org.apache.cxf.message.Message) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor)

Example 19 with EndpointImpl

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

the class AbstractDOMProvider method publish.

public void publish() throws Exception {
    String addr = epAddress;
    String wsdlLoc = null;
    String svcNm = null;
    String portNm = null;
    String tgtNmspc = null;
    String binding = null;
    Object obj = webSvcProviderVar.get("wsdlLocation", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_WSDL_LOCATION);
    }
    if (obj instanceof String) {
        wsdlLoc = (String) obj;
    }
    obj = webSvcProviderVar.get("serviceName", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_SERVICE_NAME);
    }
    if (obj instanceof String) {
        svcNm = (String) obj;
    }
    obj = webSvcProviderVar.get("portName", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_PORT_NAME);
    }
    if (obj instanceof String) {
        portNm = (String) obj;
    }
    obj = webSvcProviderVar.get("targetNamespace", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_TGT_NAMESPACE);
    }
    if (obj instanceof String) {
        tgtNmspc = (String) obj;
    }
    if (addr == null) {
        obj = webSvcProviderVar.get("EndpointAddress", scriptScope);
        if (obj != Scriptable.NOT_FOUND && obj instanceof String) {
            addr = (String) obj;
            isBaseAddr = false;
        }
    }
    if (addr == null) {
        throw new JSDOMProviderException(NO_EP_ADDR);
    }
    if (isBaseAddr) {
        if (addr.endsWith("/")) {
            addr += portNm;
        } else {
            addr = addr + "/" + portNm;
        }
    }
    obj = webSvcProviderVar.get("BindingType", scriptScope);
    if (obj != Scriptable.NOT_FOUND && obj instanceof String) {
        binding = (String) obj;
    }
    obj = webSvcProviderVar.get("invoke", webSvcProviderVar);
    if (obj == Scriptable.NOT_FOUND) {
        throw new JSDOMProviderException(NO_INVOKE);
    }
    if (obj instanceof Function) {
        invokeFunc = (Function) obj;
    } else {
        throw new JSDOMProviderException(ILLEGAL_INVOKE_TYPE);
    }
    Bus bus = BusFactory.getThreadDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setWsdlLocation(wsdlLoc);
    factory.setBindingId(binding);
    factory.setServiceName(new QName(tgtNmspc, svcNm));
    factory.setEndpointName(new QName(tgtNmspc, portNm));
    ep = new EndpointImpl(bus, this, factory);
    ep.publish(addr);
}
Also used : Function(org.mozilla.javascript.Function) Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) XMLObject(org.mozilla.javascript.xml.XMLObject) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 20 with EndpointImpl

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

the class Server method run.

protected void run() {
    URL url = getClass().getResource("fault-stack-trace.xml");
    if (url != null) {
        System.setProperty("cxf.config.file.url", url.toString());
    }
    Object implementor;
    String address;
    implementor = new AsyncGreeter();
    address = "http://localhost:" + PORT + "/SoapContext/AsyncSoapPort";
    eps.add(Endpoint.publish(address, implementor));
    implementor = new AsyncEchoProvider();
    address = "http://localhost:" + PORT + "/SoapContext/AsyncEchoProvider";
    eps.add(Endpoint.publish(address, implementor));
    implementor = new GreeterImplMultiPort();
    address = "http://localhost:" + PORT + "/MultiPort/GreeterPort";
    eps.add(Endpoint.publish(address, implementor));
    implementor = new DocLitBareGreeterMultiPort();
    address = "http://localhost:" + PORT + "/MultiPort/DocBarePort";
    eps.add(Endpoint.publish(address, implementor));
    implementor = new GreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    Endpoint ep = Endpoint.publish(address, implementor);
    eps.add(ep);
    implementor = new GreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPortWithGzip";
    Endpoint ep2 = Endpoint.publish(address, implementor);
    ((EndpointImpl) ep2).getService().getInInterceptors().add(new GZIPInInterceptor());
    ((EndpointImpl) ep2).getService().getOutInterceptors().add(new GZIPOutInterceptor());
    eps.add(ep2);
    implementor = new RefGreeterImpl();
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort2";
    eps.add(Endpoint.publish(address, implementor));
    // publish port with soap12 binding
    address = "http://localhost:" + PORT + "/SoapContext/SoapPort";
    EndpointImpl e = (EndpointImpl) Endpoint.create(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING, new Greeter12Impl());
    e.publish(address);
    eps.add(e);
    implementor = new DocLitBareGreeterImpl();
    address = "http://localhost:" + BARE_PORT + "/SoapContext/SoapPort";
    eps.add(Endpoint.publish(address, implementor));
    implementor = new GreeterImplBogus();
    address = "http://localhost:" + BOGUS_REAL_PORT + "/SoapContext/SoapPort";
    eps.add(Endpoint.publish(address, implementor));
}
Also used : EndpointImpl(org.apache.cxf.jaxws.EndpointImpl) GZIPInInterceptor(org.apache.cxf.transport.common.gzip.GZIPInInterceptor) URL(java.net.URL) GZIPOutInterceptor(org.apache.cxf.transport.common.gzip.GZIPOutInterceptor) Endpoint(javax.xml.ws.Endpoint) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) BaseGreeterImpl(org.apache.hello_world_soap_http.BaseGreeterImpl) DocLitBareGreeterImpl(org.apache.hello_world_soap_http.DocLitBareGreeterImpl) DocLitBareGreeterImpl(org.apache.hello_world_soap_http.DocLitBareGreeterImpl)

Aggregations

EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)61 QName (javax.xml.namespace.QName)14 Test (org.junit.Test)9 Bus (org.apache.cxf.Bus)8 BeforeClass (org.junit.BeforeClass)7 Bean (org.springframework.context.annotation.Bean)7 Endpoint (javax.xml.ws.Endpoint)5 URL (java.net.URL)4 HashMap (java.util.HashMap)4 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)4 Feature (org.apache.cxf.feature.Feature)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)3 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JAXBException (javax.xml.bind.JAXBException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 WebServiceException (javax.xml.ws.WebServiceException)2