org.apache.cxf.databinding.DataBinding Java Examples

The following examples show how to use org.apache.cxf.databinding.DataBinding. 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: WrapperClassOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private synchronized WrapperHelper getWrapperHelper(Message message,
                                       MessageInfo messageInfo,
                                       MessageInfo wrappedMessageInfo,
                                       Class<?> wrapClass,
                                       MessagePartInfo messagePartInfo) {
    WrapperHelper helper = messagePartInfo.getProperty("WRAPPER_CLASS", WrapperHelper.class);
    if (helper == null) {
        Service service = ServiceModelUtil.getService(message.getExchange());
        DataBinding dataBinding = service.getDataBinding();
        if (dataBinding instanceof WrapperCapableDatabinding) {
            helper = createWrapperHelper((WrapperCapableDatabinding)dataBinding,
                                         messageInfo, wrappedMessageInfo, wrapClass);
            messagePartInfo.setProperty("WRAPPER_CLASS", helper);
        }
    }
    return helper;
}
 
Example #2
Source File: AbstractJAXRSFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setDataBindingProvider(ProviderFactory factory, Service s) {

        List<ClassResourceInfo> cris = serviceFactory.getRealClassResourceInfo();
        if (getDataBinding() == null && !cris.isEmpty()) {
            org.apache.cxf.annotations.DataBinding ann =
                cris.get(0).getServiceClass().getAnnotation(org.apache.cxf.annotations.DataBinding.class);
            if (ann != null) {
                try {
                    setDataBinding(ann.value().newInstance());
                } catch (Exception ex) {
                    LOG.warning("DataBinding " + ann.value() + " can not be loaded");
                }
            }
        }
        DataBinding db = getDataBinding();
        if (db == null) {
            return;
        }
        if (s instanceof JAXRSServiceImpl) {
            ((JAXRSServiceImpl)s).setCreateServiceModel(true);
        }
        db.initialize(s);
        factory.setUserProviders(Collections.singletonList(new DataBindingProvider<Object>(db)));
    }
 
Example #3
Source File: SerializationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeserialization() throws Exception {
    setupClientAndRhino("simple-dlwu-proxy-factory");
    testUtilities.readResourceIntoRhino("/deserializationTests.js");
    DataBinding dataBinding = new JAXBDataBinding(TestBean1.class, TestBean2.class);
    assertNotNull(dataBinding);
    TestBean1 bean = new TestBean1();
    bean.stringItem = "bean1>stringItem";
    bean.doubleItem = -1.0;
    String serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_1", serialized);

    bean = new TestBean1();
    bean.stringItem = null;
    bean.intItem = 21;
    bean.longItem = 200000001;
    bean.optionalIntItem = 456123;
    bean.optionalIntArrayItem = new int[4];
    bean.optionalIntArrayItem[0] = 3;
    bean.optionalIntArrayItem[1] = 1;
    bean.optionalIntArrayItem[2] = 4;
    bean.optionalIntArrayItem[3] = 1;
    bean.doubleItem = -1.0;
    serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_2", serialized);
}
 
Example #4
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Set<Class<?>> generatedWrapperBeanClass() {
    DataBinding b = getDataBinding();
    if (b.getClass().getName().endsWith("JAXBDataBinding")
        && schemaLocations == null) {
        ServiceInfo serviceInfo = getService().getServiceInfos().get(0);
        WrapperClassGenerator wrapperGen = new WrapperClassGenerator(this,
                                                                     serviceInfo.getInterface(),
                                                                     getQualifyWrapperSchema());
        return wrapperGen.generate();
    }
    return Collections.emptySet();
}
 
Example #5
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setMTOMFeatures(DataBinding databinding) {
    if (this.wsFeatures != null) {
        for (WebServiceFeature wsf : this.wsFeatures) {
            if (wsf instanceof MTOMFeature) {
                databinding.setMtomEnabled(true);
                MTOMFeature f = (MTOMFeature) wsf;
                if (f.getThreshold() > 0) {
                    databinding.setMtomThreshold(((MTOMFeature)wsf).getThreshold());
                }
            }
        }
    }
}
 
Example #6
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: ClientFaultConverter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isDOMSupported(DataBinding db) {
    boolean supportsDOM = false;
    for (Class<?> c : db.getSupportedReaderFormats()) {
        if (c.equals(Node.class)) {
            supportsDOM = true;
        }
    }
    return supportsDOM;
}
 
Example #8
Source File: FaultOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isDOMSupported(DataBinding db) {
    boolean supportsDOM = false;
    for (Class<?> c : db.getSupportedWriterFormats()) {
        if (c.equals(Node.class)) {
            supportsDOM = true;
        }
    }
    return supportsDOM;
}
 
Example #9
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static synchronized Class<? extends DataBinding> getJAXBClass() throws ClassNotFoundException {
    if (defaultDatabindingClass == null) {
        defaultDatabindingClass = ClassLoaderUtils.loadClass("org.apache.cxf.jaxb.JAXBDataBinding",
                                                             ReflectionServiceFactoryBean.class,
                                                             DataBinding.class);
    }
    return defaultDatabindingClass;
}
 
Example #10
Source File: SerializationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String serializeObject(DataBinding dataBinding, TestBean1 bean) throws XMLStreamException {
    DataWriter<XMLStreamWriter> writer = dataBinding.createWriter(XMLStreamWriter.class);
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write(bean, xmlStreamWriter);
    xmlStreamWriter.flush();
    xmlStreamWriter.close();
    return stringWriter.toString();
}
 
Example #11
Source File: AttributeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String serializeObject(DataBinding dataBinding,
                               AttributeTestBean bean) throws XMLStreamException {
    DataWriter<XMLStreamWriter> writer = dataBinding.createWriter(XMLStreamWriter.class);
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write(bean, xmlStreamWriter);
    xmlStreamWriter.flush();
    xmlStreamWriter.close();
    return stringWriter.toString();
}
 
Example #12
Source File: AttributeTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: AbstractServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    this.dataBinding = dataBinding;
    this.dataBindingSet = dataBinding != null;
}
 
Example #14
Source File: Header.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Header(QName q, Object o, DataBinding b) {
    object = o;
    name = q;
    dataBinding = b;
}
 
Example #15
Source File: AbstractServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected DataBinding createDefaultDataBinding() {
    return null;
}
 
Example #16
Source File: AbstractServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding(boolean create) {
    if (dataBinding == null && create) {
        dataBinding = createDefaultDataBinding();
    }
    return dataBinding;
}
 
Example #17
Source File: AbstractServiceFactoryBean.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding() {
    return getDataBinding(true);
}
 
Example #18
Source File: ServiceImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding() {
    return dataBinding;
}
 
Example #19
Source File: ServiceImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    this.dataBinding = dataBinding;
}
 
Example #20
Source File: ProtobufServiceImpl.java    From fuchsia with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    this.dataBinding = dataBinding;
}
 
Example #21
Source File: Header.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding() {
    return dataBinding;
}
 
Example #22
Source File: Header.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    this.dataBinding = dataBinding;
}
 
Example #23
Source File: AbstractEndpointFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding() {
    return dataBinding;
}
 
Example #24
Source File: AbstractEndpointFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    this.dataBinding = dataBinding;
}
 
Example #25
Source File: CxfEndpoint.java    From tomee with Apache License 2.0 4 votes vote down vote up
protected static JaxWsServiceFactoryBean configureService(final JaxWsServiceFactoryBean serviceFactory, final ServiceConfiguration configuration, final String prefix) {
    final Properties beanConfig = configuration.getProperties();
    if (beanConfig == null || beanConfig.isEmpty()) {
        return serviceFactory;
    }

    final Collection<ServiceInfo> availableServices = configuration.getAvailableServices();

    // databinding
    final String databinding = beanConfig.getProperty(prefix + CxfUtil.DATABINDING);
    if (databinding != null && !databinding.trim().isEmpty()) {
        Object instance = ServiceInfos.resolve(availableServices, databinding);
        if (instance == null) {  // maybe id == classname
            try {
                instance = Thread.currentThread().getContextClassLoader().loadClass(databinding).newInstance();
            } catch (Exception e) {
                // ignore
            }
        }
        if (!DataBinding.class.isInstance(instance)) {
            throw new OpenEJBRuntimeException(instance + " is not a " + DataBinding.class.getName()
                + ", please check configuration of service [id=" + databinding + "]");
        }
        serviceFactory.setDataBinding((DataBinding) instance);
    }

    final String wsFeatures = beanConfig.getProperty(prefix + "wsFeatures");
    if (wsFeatures != null) {
        final Collection<Object> instances = ServiceInfos.resolve(availableServices, wsFeatures.split(" *, *"));
        if (instances != null && !instances.isEmpty()) {
            final List<WebServiceFeature> features = new ArrayList<>(instances.size());
            for (final Object i : instances) {
                if (!WebServiceFeature.class.isInstance(i)) {
                    throw new IllegalArgumentException("Not a WebServiceFeature: " + i);
                }
                features.add(WebServiceFeature.class.cast(i));
            }
            serviceFactory.setWsFeatures(features);
        }
    }

    return serviceFactory;
}
 
Example #26
Source File: CxfUtil.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static void configureEndpoint(final AbstractEndpointFactory svrFactory, final ServiceConfiguration configuration, final String prefix) {
    final Properties beanConfig = configuration.getProperties();
    if (beanConfig == null || beanConfig.isEmpty()) {
        return;
    }

    final Collection<ServiceInfo> availableServices = configuration.getAvailableServices();

    // endpoint properties
    final Properties properties = ServiceInfos.serviceProperties(availableServices, beanConfig.getProperty(prefix + ENDPOINT_PROPERTIES));
    if (properties != null) {
        svrFactory.setProperties(PropertiesHelper.map(properties));
    }

    final String debugKey = prefix + DEBUG;
    if ("true".equalsIgnoreCase(beanConfig.getProperty(debugKey, SystemInstance.get().getOptions().get(debugKey, "false")))) {
        svrFactory.getProperties(true).put("faultStackTraceEnabled", "true");
    }

    // endpoint features
    final String featuresIds = beanConfig.getProperty(prefix + FEATURES);
    if (featuresIds != null) {
        final List<? extends Feature> features = createFeatures(availableServices, featuresIds);
        svrFactory.setFeatures(features);
    }

    configureInterceptors(svrFactory, prefix, availableServices, beanConfig);

    // databinding
    final String databinding = beanConfig.getProperty(prefix + DATABINDING);
    if (databinding != null && !databinding.trim().isEmpty()) {
        Object instance = ServiceInfos.resolve(availableServices, databinding);
        if (instance == null) {  // maybe id == classname
            try {
                instance = Thread.currentThread().getContextClassLoader().loadClass(databinding).newInstance();
            } catch (Exception e) {
                // ignore
            }
        }

        if (!DataBinding.class.isInstance(instance)) {
            throw new OpenEJBRuntimeException(instance + " is not a " + DataBinding.class.getName()
                    + ", please check configuration of service [id=" + databinding + "]");
        }
        svrFactory.setDataBinding((DataBinding) instance);
    }

    // address: easier than using openejb-jar.xml
    final String changedAddress = beanConfig.getProperty(prefix + ADDRESS);
    if (changedAddress != null && !changedAddress.trim().isEmpty()) {
        svrFactory.setAddress(changedAddress);
    }

    // published url
    final String publishedUrl = beanConfig.getProperty(prefix + PUBLISHED_URL);
    if (publishedUrl != null && !publishedUrl.trim().isEmpty()) {
        svrFactory.setPublishedEndpointUrl(publishedUrl);
    }
}
 
Example #27
Source File: ProtobufServiceImpl.java    From fuchsia with Apache License 2.0 4 votes vote down vote up
public DataBinding getDataBinding() {
    return dataBinding;
}
 
Example #28
Source File: EndpointImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setDataBinding(DataBinding dataBinding) {
    serverFactory.setDataBinding(dataBinding);
}
 
Example #29
Source File: SoapHeader.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SoapHeader(QName q, Object o, DataBinding b, boolean mustUnderstand) {
    super(q, o, b);
    this.mustUnderstand = mustUnderstand;
}
 
Example #30
Source File: SoapHeader.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SoapHeader(QName q, Object o, DataBinding b, boolean mustUnderstand, String actor) {
    super(q, o, b);
    this.mustUnderstand = mustUnderstand;
    this.actor = actor;
}