Search in sources :

Example 41 with JAXBDataBinding

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

the class AttributeTest method testDeserialization.

@Test
public void testDeserialization() throws Exception {
    setupClientAndRhino("attribute-test-proxy-factory");
    testUtilities.readResourceIntoRhino("/attributeTests.js");
    DataBinding dataBinding = new JAXBDataBinding(AttributeTestBean.class);
    assertNotNull(dataBinding);
    AttributeTestBean bean = new AttributeTestBean();
    bean.element1 = "e1";
    bean.element2 = "e2";
    bean.attribute1 = "a1";
    bean.attribute2 = "a2";
    String serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeAttributeTestBean", serialized);
}
Also used : AttributeTestBean(org.apache.cxf.javascript.fortest.AttributeTestBean) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) AbstractCXFSpringTest(org.apache.cxf.test.AbstractCXFSpringTest) Test(org.junit.Test)

Example 42 with JAXBDataBinding

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

the class TestBase method common.

protected void common(String wsdl, QName portName, Class<?>... jaxbClasses) throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    WSDLManagerImpl manager = new WSDLManagerImpl();
    XMLWSDLExtensionLoader loader = new XMLWSDLExtensionLoader(bus);
    loader.registerExtensors(manager);
    assertNotNull(bus.getExtension(WSDLManager.class));
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource(wsdl).toString(), new QName(portName.getNamespaceURI(), "XMLService"));
    org.apache.cxf.service.Service service = factory.create();
    EndpointInfo epi = service.getEndpointInfo(portName);
    assertNotNull(epi);
    serviceInfo = epi.getService();
    JAXBDataBinding db = new JAXBDataBinding();
    db.initialize(service);
    db.setContext(JAXBContext.newInstance(jaxbClasses));
    service.setDataBinding(db);
    Endpoint endpoint = new EndpointImpl(bus, service, epi);
    xmlMessage.getExchange().put(Endpoint.class, endpoint);
    xmlMessage.getExchange().put(org.apache.cxf.service.Service.class, service);
}
Also used : Bus(org.apache.cxf.Bus) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) XMLWSDLExtensionLoader(org.apache.cxf.binding.xml.wsdl11.XMLWSDLExtensionLoader) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) WSDLManager(org.apache.cxf.wsdl.WSDLManager) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 43 with JAXBDataBinding

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

the class SwAOutInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    if (bop == null) {
        return;
    }
    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();
    if (bmi == null) {
        return;
    }
    SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);
    if (sbi == null || sbi.getAttachments() == null || sbi.getAttachments().isEmpty()) {
        Service s = ex.getService();
        DataBinding db = s.getDataBinding();
        if (db instanceof JAXBDataBinding && hasSwaRef((JAXBDataBinding) db)) {
            setupAttachmentOutput(message);
        }
        return;
    }
    processAttachments(message, sbi);
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) SoapBodyInfo(org.apache.cxf.binding.soap.model.SoapBodyInfo) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Service(org.apache.cxf.service.Service) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 44 with JAXBDataBinding

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

the class JaxWsServerFactoryBeanTest method testJaxbExtraClass.

@Test
public void testJaxbExtraClass() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setBus(getBus());
    sf.setAddress("http://localhost:9000/test");
    sf.setServiceClass(Hello.class);
    sf.setStart(false);
    Map<String, Object> props = sf.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses", new Class[] { DescriptionType.class, DisplayNameType.class });
    sf.setProperties(props);
    Server server = sf.create();
    assertNotNull(server);
    Class<?>[] extraClass = ((JAXBDataBinding) sf.getServiceFactory().getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], DescriptionType.class);
    assertEquals(extraClass[1], DisplayNameType.class);
}
Also used : Server(org.apache.cxf.endpoint.Server) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Test(org.junit.Test)

Example 45 with JAXBDataBinding

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

the class RMEndpoint method createService.

void createService(ProtocolVariation protocol) {
    ServiceInfo si = new ServiceInfo();
    si.setProperty(Schema.class.getName(), getSchema());
    QName serviceQName = new QName(protocol.getWSRMNamespace(), SERVICE_NAME);
    si.setName(serviceQName);
    buildInterfaceInfo(si, protocol);
    WrappedService service = new WrappedService(applicationEndpoint.getService(), serviceQName, si);
    Class<?> create = protocol.getCodec().getCreateSequenceType();
    try {
        JAXBContext ctx = JAXBContext.newInstance(PackageUtils.getPackageName(create), create.getClassLoader());
        service.setDataBinding(new JAXBDataBinding(ctx));
    } catch (JAXBException e) {
        throw new ServiceConstructionException(e);
    }
    service.setInvoker(servant);
    services.put(protocol, service);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) QName(javax.xml.namespace.QName) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException)

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