Search in sources :

Example 21 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding 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 22 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class OOBHeaderTest method addOutOfBoundHeader.

private void addOutOfBoundHeader(PutLastTradedPricePortType portType, boolean invalid, boolean mu) {
    InvocationHandler handler = Proxy.getInvocationHandler(portType);
    BindingProvider bp = null;
    try {
        if (handler instanceof BindingProvider) {
            bp = (BindingProvider) handler;
            Map<String, Object> requestContext = bp.getRequestContext();
            OutofBandHeader ob = new OutofBandHeader();
            ob.setName("testOobHeader");
            ob.setValue("testOobHeaderValue");
            ob.setHdrAttribute(invalid ? "dontProcess" : "testHdrAttribute");
            SoapHeader hdr = new SoapHeader(new QName(TEST_HDR_NS, TEST_HDR_REQUEST_ELEM), ob, new JAXBDataBinding(ob.getClass()));
            hdr.setMustUnderstand(mu);
            List<Header> holder = new ArrayList<>();
            holder.add(hdr);
            // Add List of headerHolders to requestContext.
            requestContext.put(Header.HEADER_LIST, holder);
        }
    } catch (JAXBException ex) {
    // System.out.println("failed to insert header into request context :" + ex);
    }
}
Also used : QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 23 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class DefaultServiceBuilderFactory method newBuilder.

@Override
public ServiceBuilder newBuilder(FrontendFactory.Style s) {
    DataBinding dataBinding;
    final String dbn = getDatabindingName();
    if (ToolConstants.JAXB_DATABINDING.equals(dbn)) {
        dataBinding = new JAXBDataBinding();
    } else if (ToolConstants.AEGIS_DATABINDING.equals(dbn)) {
        dataBinding = new AegisDatabinding();
    } else {
        throw new ToolException("Unsupported databinding: " + dbn);
    }
    final AbstractServiceFactory builder;
    if (Style.Jaxws.equals(s)) {
        builder = new JaxwsServiceBuilder();
    } else if (Style.Simple.equals(s)) {
        builder = new SimpleServiceBuilder();
    } else {
        throw new ToolException("Unsupported frontend style: " + s);
    }
    builder.setDataBinding(dataBinding);
    builder.setServiceClass(serviceClass);
    return builder;
}
Also used : AbstractServiceFactory(org.apache.cxf.frontend.AbstractServiceFactory) SimpleServiceBuilder(org.apache.cxf.simple.SimpleServiceBuilder) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) AegisDatabinding(org.apache.cxf.aegis.databinding.AegisDatabinding) ToolException(org.apache.cxf.tools.common.ToolException) JaxwsServiceBuilder(org.apache.cxf.jaxws.JaxwsServiceBuilder)

Example 24 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class ServiceImplTest method testJAXBCachedOnRepeatGetPort.

@Test
public void testJAXBCachedOnRepeatGetPort() {
    System.gc();
    System.gc();
    URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
    assertNotNull(wsdl1);
    ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
    CalculatorPortType cal1 = service.getPort(PORT_1, CalculatorPortType.class);
    assertNotNull(cal1);
    ClientProxy cp = (ClientProxy) Proxy.getInvocationHandler(cal1);
    JAXBDataBinding db1 = (JAXBDataBinding) cp.getClient().getEndpoint().getService().getDataBinding();
    assertNotNull(db1);
    System.gc();
    System.gc();
    System.gc();
    System.gc();
    CalculatorPortType cal2 = service.getPort(PORT_1, CalculatorPortType.class);
    assertNotNull(cal2);
    cp = (ClientProxy) Proxy.getInvocationHandler(cal2);
    JAXBDataBinding db2 = (JAXBDataBinding) cp.getClient().getEndpoint().getService().getDataBinding();
    assertNotNull(db2);
    assertEquals("got cached JAXBContext", db1.getContext(), db2.getContext());
}
Also used : CalculatorPortType(org.apache.cxf.calculator.CalculatorPortType) ClientProxy(org.apache.cxf.frontend.ClientProxy) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) URL(java.net.URL) Test(org.junit.Test)

Example 25 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class ClientFactoryBeanTest method testJaxbExtraClass.

@Test
public void testJaxbExtraClass() throws Exception {
    ClientFactoryBean cfBean = new ClientFactoryBean();
    cfBean.setAddress("http://localhost/Hello");
    cfBean.setBus(getBus());
    cfBean.setServiceClass(HelloService.class);
    Map<String, Object> props = cfBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses", new Class[] { GreetMe.class, GreetMeOneWay.class });
    cfBean.setProperties(props);
    Client client = cfBean.create();
    assertNotNull(client);
    Class<?>[] extraClass = ((JAXBDataBinding) cfBean.getServiceFactory().getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
Also used : ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)51 QName (javax.xml.namespace.QName)24 Test (org.junit.Test)18 JAXBException (javax.xml.bind.JAXBException)15 Header (org.apache.cxf.headers.Header)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)12 ArrayList (java.util.ArrayList)10 DataBinding (org.apache.cxf.databinding.DataBinding)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)7 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)7 Service (org.apache.cxf.service.Service)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 JAXBContext (javax.xml.bind.JAXBContext)5 Bus (org.apache.cxf.Bus)5 URL (java.net.URL)4 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)4 HashMap (java.util.HashMap)3 List (java.util.List)3 MessageContext (javax.xml.ws.handler.MessageContext)3