You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/05/04 10:26:25 UTC
cxf git commit: [CXF-6893] Removing Aegis and DataBinding JSON
providers
Repository: cxf
Updated Branches:
refs/heads/master 30a0754eb -> 549106959
[CXF-6893] Removing Aegis and DataBinding JSON providers
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/54910695
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/54910695
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/54910695
Branch: refs/heads/master
Commit: 54910695917fb63a11982a8dc96a3b4d088963c5
Parents: 30a0754
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Wed May 4 11:26:08 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Wed May 4 11:26:08 2016 +0100
----------------------------------------------------------------------
.../jaxrs/provider/aegis/AegisJSONProvider.java | 160 ---------
.../provider/json/DataBindingJSONProvider.java | 136 --------
.../provider/aegis/AegisJSONProviderTest.java | 343 -------------------
.../json/DataBindingJSONProviderTest.java | 234 -------------
.../cxf/systest/jaxrs/JAXRSDataBindingTest.java | 28 --
.../jaxrs_databinding/WEB-INF/beans.xml | 11 +-
6 files changed, 1 insertion(+), 911 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
deleted file mode 100644
index 0a2591a..0000000
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider.aegis;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.Provider;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.w3c.dom.Document;
-
-import org.apache.cxf.aegis.AegisContext;
-import org.apache.cxf.aegis.AegisWriter;
-import org.apache.cxf.aegis.type.AegisType;
-import org.apache.cxf.jaxrs.provider.json.utils.JSONUtils;
-import org.apache.cxf.jaxrs.provider.json.utils.PrefixCollectingXMLStreamWriter;
-import org.apache.cxf.jaxrs.utils.ExceptionUtils;
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.staxutils.StaxUtils;
-import org.apache.cxf.staxutils.W3CDOMStreamWriter;
-import org.codehaus.jettison.mapped.Configuration;
-
-@Provider
-@Produces({"application/json" })
-@Consumes({"application/json" })
-public final class AegisJSONProvider<T> extends AegisElementProvider<T> {
-
- private List<String> arrayKeys;
- private boolean serializeAsArray;
- private boolean dropRootElement;
- private boolean ignoreNamespaces;
-
- private ConcurrentHashMap<String, String> namespaceMap = new ConcurrentHashMap<String, String>();
-
- public AegisJSONProvider() {
- }
-
- public void setIgnoreNamespaces(boolean ignoreNamespaces) {
- this.ignoreNamespaces = ignoreNamespaces;
- }
-
- public void setDropRootElement(boolean dropRootElement) {
- this.dropRootElement = dropRootElement;
- }
-
- public void setArrayKeys(List<String> keys) {
- this.arrayKeys = keys;
- }
-
- public void setSerializeAsArray(boolean asArray) {
- this.serializeAsArray = asArray;
- }
-
- @Override
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return true;
- }
-
- public void setNamespaceMap(Map<String, String> nsMap) {
- this.namespaceMap = new ConcurrentHashMap<String, String>(nsMap);
- }
-
- @Override
- public void writeTo(T obj, Class<?> type, Type genericType, Annotation[] anns, MediaType m,
- MultivaluedMap<String, Object> headers, OutputStream os) throws IOException {
- if (type == null) {
- type = obj.getClass();
- }
- if (genericType == null) {
- genericType = type;
- }
- AegisContext context = getAegisContext(type, genericType);
- AegisType aegisType = context.getTypeMapping().getType(genericType);
- AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
- try {
- W3CDOMStreamWriter w3cStreamWriter = new W3CDOMStreamWriter();
- XMLStreamWriter spyingWriter = new PrefixCollectingXMLStreamWriter(w3cStreamWriter,
- namespaceMap);
- spyingWriter.writeStartDocument();
- // use type qname as element qname?
- aegisWriter.write(obj, aegisType.getSchemaType(), false, spyingWriter, aegisType);
- spyingWriter.writeEndDocument();
- spyingWriter.close();
- Document dom = w3cStreamWriter.getDocument();
- // ok, now the namespace map has all the prefixes.
-
- String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name());
-
- XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), enc, os);
- xmlStreamWriter.writeStartDocument();
- StaxUtils.copy(dom, xmlStreamWriter);
- // Jettison needs, and StaxUtils.copy doesn't do it.
- xmlStreamWriter.writeEndDocument();
- xmlStreamWriter.flush();
- xmlStreamWriter.close();
- } catch (Exception e) {
- throw ExceptionUtils.toInternalServerErrorException(e, null);
- }
- }
-
- @Override
- protected XMLStreamWriter createStreamWriter(QName typeQName, String enc, OutputStream os) throws Exception {
-
- Configuration config =
- JSONUtils.createConfiguration(namespaceMap,
- writeXsiType && !ignoreNamespaces, false, null);
- XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName,
- writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys, dropRootElement, enc);
- return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
- }
-
- @Override
- protected XMLStreamReader createStreamReader(AegisType typeToRead, InputStream is) throws Exception {
- // the namespace map. Oh, the namespace map.
- // This is wrong, but might make unit tests pass until we redesign.
- if (typeToRead != null) {
- String pfx = "ns1";
- int count = 1;
- while (namespaceMap.containsValue(pfx)) {
- count++;
- pfx = "ns" + count;
- }
- namespaceMap.putIfAbsent(typeToRead.getSchemaType().getNamespaceURI(), pfx);
- }
- return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
deleted file mode 100644
index a41f577..0000000
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cxf.jaxrs.provider.json;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.Provider;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.cxf.jaxrs.provider.DataBindingProvider;
-import org.apache.cxf.jaxrs.provider.json.utils.JSONUtils;
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.codehaus.jettison.mapped.Configuration;
-
-@Provider
-@Produces("application/json")
-@Consumes("application/json")
-public class DataBindingJSONProvider<T> extends DataBindingProvider<T> {
-
- private List<String> arrayKeys;
- private boolean serializeAsArray;
- private ConcurrentHashMap<String, String> namespaceMap = new ConcurrentHashMap<String, String>();
- private boolean writeXsiType = true;
- private boolean readXsiType = true;
- private boolean dropRootElement;
- private boolean ignoreMixedContent;
- private boolean ignoreNamespaces;
-
- public void setIgnoreNamespaces(boolean ignoreNamespaces) {
- this.ignoreNamespaces = ignoreNamespaces;
- }
-
- public void setDropRootElement(boolean dropRootElement) {
- this.dropRootElement = dropRootElement;
- }
-
- public void setWriteXsiType(boolean write) {
- writeXsiType = write;
- }
-
- public void setReadXsiType(boolean read) {
- readXsiType = read;
- }
-
- public void setArrayKeys(List<String> keys) {
- this.arrayKeys = keys;
- }
-
- public void setSerializeAsArray(boolean asArray) {
- this.serializeAsArray = asArray;
- }
-
- @Override
- public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
- return true;
- }
-
- public void setNamespaceMap(Map<String, String> nsMap) {
- this.namespaceMap = new ConcurrentHashMap<String, String>(nsMap);
- }
-
- @Override
- protected XMLStreamWriter createWriter(Class<?> type, Type genericType, String enc, OutputStream os)
- throws Exception {
- QName qname = null;
- if (!InjectionUtils.isSupportedCollectionOrArray(type)) {
- qname = getQName(type);
- } else {
- qname = getQName(InjectionUtils.getActualType(genericType));
- }
- Configuration config =
- JSONUtils.createConfiguration(namespaceMap, writeXsiType && !ignoreNamespaces,
- false, null);
- XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname,
- writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys, dropRootElement, enc);
- writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
- return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType);
- }
-
- @Override
- protected void writeToWriter(XMLStreamWriter writer, Object o) throws Exception {
- writer.writeStartDocument();
- super.writeToWriter(writer, o);
- writer.writeEndDocument();
- }
-
- @Override
- protected XMLStreamReader createReader(Class<?> type, Type genericType, InputStream is)
- throws Exception {
- if (!InjectionUtils.isSupportedCollectionOrArray(type)) {
- getQName(type);
- } else {
- getQName(InjectionUtils.getActualType(genericType));
- }
- return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
- }
-
- private QName getQName(Class<?> type) {
- QName qname = JAXRSUtils.getClassQName(type);
- namespaceMap.putIfAbsent(qname.getNamespaceURI(), "ns1");
- return qname;
- }
-
- public void setIgnoreMixedContent(boolean ignoreMixedContent) {
- this.ignoreMixedContent = ignoreMixedContent;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProviderTest.java b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProviderTest.java
deleted file mode 100644
index 5fd385b..0000000
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProviderTest.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider.aegis;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.InvalidPropertiesFormatException;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
-
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.resources.AegisTestBean;
-import org.apache.cxf.jaxrs.resources.CollectionsResource;
-import org.apache.cxf.jaxrs.resources.ManyTags;
-import org.apache.cxf.jaxrs.resources.TagVO;
-import org.apache.cxf.jaxrs.resources.Tags;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class AegisJSONProviderTest extends Assert {
-
- private Properties properties;
-
- @Before
- public void before() throws InvalidPropertiesFormatException, IOException {
- properties = new Properties();
- properties.loadFromXML(getClass().getResourceAsStream("jsonCases.xml"));
- }
-
-
- @Test
- public void testIsWriteable() {
- MessageBodyWriter<Object> p = new AegisJSONProvider<Object>();
- assertTrue(p.isWriteable(AegisTestBean.class, null, null, null));
- }
-
- @Test
- public void testIsReadable() {
- MessageBodyReader<Object> p = new AegisJSONProvider<Object>();
- assertTrue(p.isReadable(AegisTestBean.class, null, null, null));
- }
-
-
- @Test
- public void testReadFrom() throws Exception {
- doTestRead(true);
- }
-
- @Test
- public void testReadFromNoMap() throws Exception {
- doTestRead(false);
- }
-
- private void doTestRead(boolean setNsMap) throws Exception {
- AegisJSONProvider<AegisTestBean> p = new AegisJSONProvider<AegisTestBean>();
- AbstractAegisProvider.clearContexts();
- if (setNsMap) {
- Map<String, String> namespaceMap = new HashMap<String, String>();
- namespaceMap.put("http://resources.jaxrs.cxf.apache.org", "ns1");
- namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
- p.setNamespaceMap(namespaceMap);
- }
- String data = "{\"ns1.AegisTestBean\":{\"@xsi.type\":\"ns1:AegisTestBean\","
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}";
-
- byte[] simpleBytes = data.getBytes("utf-8");
- Object beanObject = p.readFrom(AegisTestBean.class, null, null,
- null, null, new ByteArrayInputStream(simpleBytes));
- AegisTestBean bean = (AegisTestBean) beanObject;
- assertEquals("hovercraft", bean.getStrValue());
- assertEquals(Boolean.TRUE, bean.getBoolValue());
- }
-
- @Test
- public void testWriteToWithXsiType() throws Exception {
- String data = "{\"ns1.AegisTestBean\":{\"@xsi.type\":\"ns1:AegisTestBean\","
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}";
- doTestWriteTo(data, true, true);
- }
-
- @Test
- public void testWriteToWithXsiTypeNoNamespaces() throws Exception {
- String data = "{\"ns1.AegisTestBean\":{\"@xsi.type\":\"ns1:AegisTestBean\","
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}";
- doTestWriteTo(data, true, false);
- }
-
- @Test
- public void testWriteToWithoutXsiType() throws Exception {
- String data = "{\"ns1.AegisTestBean\":{"
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}";
- doTestWriteTo(data, false, true);
- }
-
-
- private void doTestWriteTo(String data, boolean writeXsi, boolean setNsMap) throws Exception {
- AegisJSONProvider<Object> p = new AegisJSONProvider<Object>();
- AbstractAegisProvider.clearContexts();
- p.setWriteXsiType(writeXsi);
- if (setNsMap) {
- Map<String, String> namespaceMap = new HashMap<String, String>();
- namespaceMap.put("http://fortest.jaxrs.cxf.apache.org", "ns1");
- namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
- p.setNamespaceMap(namespaceMap);
- }
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- AegisTestBean bean = new AegisTestBean();
- bean.setBoolValue(Boolean.TRUE);
- bean.setStrValue("hovercraft");
- p.writeTo(bean, AegisTestBean.class, AegisTestBean.class,
- AegisTestBean.class.getAnnotations(),
- MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
- byte[] bytes = os.toByteArray();
- String json = new String(bytes, "utf-8");
- assertEquals(data, json);
-
- }
-
- @Test
- public void testWriteCollection() throws Exception {
- String json = writeCollection(true, false, null, true, false);
- assertEquals("{\"ns1.ArrayOfAegisTestBean\":{\"@xsi.type\":\"ns1:ArrayOfAegisTestBean\","
- + "\"ns1.AegisTestBean\":[{\"@xsi.type\":\"ns1:AegisTestBean\",\"ns1.boolValue\":true,"
- + "\"ns1.strValue\":\"hovercraft\"},{\"@xsi.type\":\"ns1:AegisTestBean\","
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
- }
-
- @Test
- public void testWriteCollectionNoXsiType() throws Exception {
- String json = writeCollection(false, false, null, true, false);
- assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
- + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,"
- + "\"ns1.strValue\":\"hovercraft\"},{"
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
- }
-
- @Test
- public void testWriteCollectionNoXsiTypeArrayKey() throws Exception {
- String json = writeCollection(false, false, "ns1.AegisTestBean", true, false);
- assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
- + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"},"
- + "{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}}", json);
- }
-
- @Test
- public void testWriteCollectionIgnoreNs() throws Exception {
- String json = writeCollection(false, false, "ns1.AegisTestBean", true, true);
- assertEquals("{\"ArrayOfAegisTestBean\":{"
- + "\"AegisTestBean\":[{\"boolValue\":true,\"strValue\":\"hovercraft\"},"
- + "{\"boolValue\":true,\"strValue\":\"hovercraft2\"}]}}", json);
- }
-
- @Test
- public void testWriteCollectionNoXsiTypeSingleBeanArrayKey() throws Exception {
- String json = writeCollection(false, false, "AegisTestBean", false, true);
- assertEquals("{\"ArrayOfAegisTestBean\":{"
- + "\"AegisTestBean\":[{\"boolValue\":true,\"strValue\":\"hovercraft\"}"
- + "]}}", json);
- }
-
- @Test
- public void testWriteCollectionNoXsiTypeSingleBean() throws Exception {
- String json = writeCollection(false, false, null, false, false);
- assertEquals("{\"ns1.ArrayOfAegisTestBean\":{"
- + "\"ns1.AegisTestBean\":{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}"
- + "}}", json);
- }
-
- @Test
- public void testWriteCollectionNoXsiTypeDropRootElement() throws Exception {
- String json = writeCollection(false, true, null, true, false);
- assertEquals("{"
- + "\"ns1.AegisTestBean\":[{\"ns1.boolValue\":true,"
- + "\"ns1.strValue\":\"hovercraft\"},{"
- + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft2\"}]}", json);
- }
-
- private String writeCollection(boolean writeXsiType,
- boolean dropRootElement,
- String arrayKey,
- boolean twoBeans,
- boolean ignoreNs)
- throws Exception {
- AegisJSONProvider<List<AegisTestBean>> p = new AegisJSONProvider<List<AegisTestBean>>();
- p.setWriteXsiType(writeXsiType);
- p.setDropRootElement(dropRootElement);
- p.setIgnoreNamespaces(ignoreNs);
- if (arrayKey != null) {
- p.setSerializeAsArray(true);
- p.setArrayKeys(Collections.singletonList(arrayKey));
- }
- AbstractAegisProvider.clearContexts();
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- AegisTestBean bean = new AegisTestBean();
- bean.setBoolValue(Boolean.TRUE);
- bean.setStrValue("hovercraft");
- List<AegisTestBean> beans = new ArrayList<AegisTestBean>();
- beans.add(bean);
- if (twoBeans) {
- AegisTestBean bean2 = new AegisTestBean();
- bean2.setBoolValue(Boolean.TRUE);
- bean2.setStrValue("hovercraft2");
- beans.add(bean2);
- }
- Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
- p.writeTo(beans, m.getReturnType(), m.getGenericReturnType(), AegisTestBean.class
- .getAnnotations(), MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
- byte[] bytes = os.toByteArray();
- return new String(bytes, "utf-8");
- }
-
-
- @Test
- public void testReadCollection() throws Exception {
- String json = writeCollection(true, false, null, true, false);
- byte[] simpleBytes = json.getBytes("utf-8");
- Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
- AegisJSONProvider<List<AegisTestBean>> p = new AegisJSONProvider<List<AegisTestBean>>();
- // the only way to get the right class ref in there is to make a dummy list object.
- // is that reasonable?
- List<AegisTestBean> list = p.readFrom(null, m.getGenericReturnType(), null,
- null, null, new ByteArrayInputStream(simpleBytes));
- assertEquals(2, list.size());
- AegisTestBean bean = list.get(0);
- assertEquals("hovercraft", bean.getStrValue());
- assertEquals(Boolean.TRUE, bean.getBoolValue());
- bean = list.get(1);
- assertEquals("hovercraft2", bean.getStrValue());
- assertEquals(Boolean.TRUE, bean.getBoolValue());
- }
-
- @Test
- public void testManyTags() throws Exception {
- AegisJSONProvider<ManyTags> p = new AegisJSONProvider<ManyTags>();
- p.setWriteXsiType(false);
- AbstractAegisProvider.clearContexts();
- p.setSerializeAsArray(true);
- p.setArrayKeys(Arrays.asList("ns1.tags"));
-
- Tags tags = new Tags();
- tags.addTag(createTag("a", "b"));
- ManyTags many = new ManyTags();
- many.setTags(tags);
-
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- p.writeTo(many, ManyTags.class, ManyTags.class, ManyTags.class.getAnnotations(),
- MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), os);
- String s = os.toString();
- String data1 = "{\"ns1.ManyTags\":{\"ns1.tags\":[{\"ns1.list\""
- + ":{\"ns1.group\":\"b\",\"ns1.name\":\"a\"}}]}}";
- String data2 = "{\"ns1.ManyTags\":{\"ns1.tags\":[{\"ns1.list\""
- + ":{\"ns1.name\":\"a\",\"ns1.group\":\"b\"}}]}}";
- assertTrue(data1.equals(s) || data2.equals(s));
- }
-
- private TagVO createTag(String name, String group) {
- return new TagVO(name, group);
- }
-
- @org.junit.Ignore
- @Test
- public void testReadWriteComplexMap() throws Exception {
- Map<AegisTestBean, AegisSuperBean> testMap =
- new HashMap<AegisTestBean, AegisSuperBean>();
-
- Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
- Method method = iwithMapClass.getMethod("mapFunction");
- Type mapType = method.getGenericReturnType();
-
- AegisTestBean bean = new AegisTestBean();
- bean.setBoolValue(Boolean.TRUE);
- bean.setStrValue("hovercraft");
-
- AegisSuperBean bean2 = new AegisSuperBean();
- bean2.setBoolValue(Boolean.TRUE);
- bean2.setStrValue("hovercraft2");
- testMap.put(bean, bean2);
-
- AegisJSONProvider<Map<AegisTestBean, AegisSuperBean>> writer
- = new AegisJSONProvider<Map<AegisTestBean, AegisSuperBean>>();
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
- byte[] bytes = os.toByteArray();
- String xml = new String(bytes, "utf-8");
- String expected = properties.getProperty("testReadWriteComplexMap.expected");
- assertEquals(expected, xml);
- AegisJSONProvider<Map<AegisTestBean, AegisSuperBean>> reader
- = new AegisJSONProvider<Map<AegisTestBean, AegisSuperBean>>();
- byte[] simpleBytes = xml.getBytes("utf-8");
-
- Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, null,
- null, null, new ByteArrayInputStream(simpleBytes));
- assertEquals(1, map2.size());
- Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
- AegisTestBean bean1 = entry.getKey();
- assertEquals("hovercraft", bean1.getStrValue());
- assertEquals(Boolean.TRUE, bean1.getBoolValue());
- AegisTestBean bean22 = entry.getValue();
- assertEquals("hovercraft2", bean22.getStrValue());
- assertEquals(Boolean.TRUE, bean22.getBoolValue());
-
- }
-
- public static class AegisSuperBean extends AegisTestBean {
- }
-
- private interface InterfaceWithMap {
- Map<AegisTestBean, AegisSuperBean> mapFunction();
- }
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProviderTest.java b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProviderTest.java
deleted file mode 100644
index a9e46c4..0000000
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProviderTest.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.cxf.jaxrs.provider.json;
-
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.cxf.aegis.databinding.AegisDatabinding;
-import org.apache.cxf.databinding.DataBinding;
-import org.apache.cxf.jaxb.JAXBDataBinding;
-import org.apache.cxf.jaxrs.JAXRSServiceImpl;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.resources.Book;
-import org.apache.cxf.jaxrs.resources.sdo.Structure;
-import org.apache.cxf.jaxrs.resources.sdo.impl.StructureImpl;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
-import org.apache.cxf.sdo.SDODataBinding;
-import org.apache.cxf.service.Service;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class DataBindingJSONProviderTest extends Assert {
-
- private ClassResourceInfo c;
- private ClassResourceInfo c2;
-
- @Before
- public void setUp() {
- c = ResourceUtils.createClassResourceInfo(TheBooks.class, TheBooks.class, true, true);
- c2 = ResourceUtils.createClassResourceInfo(TheSDOBooks.class, TheSDOBooks.class, true, true);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testSDOWrite() throws Exception {
- Service s = new JAXRSServiceImpl(Collections.singletonList(c2), true);
- DataBinding binding = new SDODataBinding();
- binding.initialize(s);
- DataBindingJSONProvider<Structure> p = new DataBindingJSONProvider<Structure>();
- p.setDataBinding(binding);
- p.setNamespaceMap(Collections.singletonMap("http://apache.org/structure/types", "p0"));
- Structure struct = new StructureImpl();
- struct.getTexts().add("text1");
- struct.setText("sdo");
- struct.setInt(3);
- struct.setDbl(123.5);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- p.writeTo(struct, Structure.class, Structure.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
- String data = "{\"p0.Structure\":{\"@xsi.type\":\"p0:Structure\",\"p0.text\":\"sdo\",\"p0.int\":3"
- + ",\"p0.dbl\":123.5,\"p0.texts\":\"text1\"}}";
- assertEquals(bos.toString(), data);
- }
-
- @Test
- public void testSDORead() throws Exception {
- String data = "{\"p0.Structure\":{\"@xsi.type\":\"p0:Structure\",\"p0.text\":\"sdo\",\"p0.int\":3"
- + ",\"p0.dbl\":123.5,\"p0.texts\":\"text1\"}}";
- Service s = new JAXRSServiceImpl(Collections.singletonList(c2), true);
- DataBinding binding = new SDODataBinding();
- binding.initialize(s);
- DataBindingJSONProvider<Structure> p = new DataBindingJSONProvider<Structure>();
- p.setDataBinding(binding);
- p.setNamespaceMap(Collections.singletonMap("http://apache.org/structure/types", "p0"));
- ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
- Structure struct = p.readFrom(Structure.class, Structure.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE,
- new MetadataMap<String, String>(), is);
- assertEquals("sdo", struct.getText());
- assertEquals(123.5, struct.getDbl(), 0.01);
- assertEquals(3, struct.getInt());
- }
-
- @Test
- public void testJAXBWrite() throws Exception {
- Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
- DataBinding binding = new JAXBDataBinding();
- binding.initialize(s);
- DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
- p.setDataBinding(binding);
- Book b = new Book("CXF", 127L);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- p.writeTo(b, Book.class, Book.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
- String data = "{\"Book\":{\"id\":127,\"name\":\"CXF\",\"state\":\"\"}}";
- assertEquals(bos.toString(), data);
- }
-
- @Test
- public void testJAXBRead() throws Exception {
- String data = "{\"Book\":{\"id\":127,\"name\":\"CXF\",\"state\":\"\"}}";
- Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
- DataBinding binding = new JAXBDataBinding();
- binding.initialize(s);
- DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
- p.setDataBinding(binding);
- ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
- Book book = (Book)p.readFrom(Book.class, Book.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE,
- new MetadataMap<String, String>(), is);
- assertEquals("CXF", book.getName());
- assertEquals(127L, book.getId());
- }
-
- @Test
- public void testAegisWrite() throws Exception {
- Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
- s.put("writeXsiType", true);
- AegisDatabinding binding = new AegisDatabinding();
- binding.initialize(s);
- DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
- p.setDataBinding(binding);
- Book b = new Book("CXF", 127L);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- p.writeTo(b, Book.class, Book.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
- doTestAegisRead(bos.toString());
- }
-
- @Test
- @Ignore
- public void testAegisCollectionWrite() throws Exception {
- Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
- s.put("writeXsiType", true);
- AegisDatabinding binding = new AegisDatabinding();
- binding.initialize(s);
- DataBindingJSONProvider<List<Book>> p = new DataBindingJSONProvider<List<Book>>();
- p.setDataBinding(binding);
-
- Book b = new Book("CXF", 127L);
- List<Book> books = new ArrayList<Book>();
- books.add(b);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- p.writeTo(books, List.class, Book.class,
- new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
-
- System.out.println(bos.toString());
- }
-
- @Test
- public void testAegisRead() throws Exception {
- String data = "{\"ns1.Book\":{\"@xsi.type\":\"ns1:Book\",\"ns1.id\":127,"
- + "\"ns1.name\":\"CXF\",\"ns1.state\":\"\"}}";
- doTestAegisRead(data);
- }
-
- public void doTestAegisRead(String data) throws Exception {
- Service s = new JAXRSServiceImpl(Collections.singletonList(c), true);
- s.put("readXsiType", true);
- AegisDatabinding binding = new AegisDatabinding();
- binding.initialize(s);
- DataBindingJSONProvider<Book> p = new DataBindingJSONProvider<Book>();
- p.setDataBinding(binding);
- ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
- Book book = (Book)p.readFrom(Book.class, Book.class,
- new Annotation[0], MediaType.APPLICATION_XML_TYPE,
- new MetadataMap<String, String>(), is);
- assertEquals("CXF", book.getName());
- assertEquals(127L, book.getId());
- }
-
- @Path("/")
- @Ignore
- public static class TheBooks {
-
- @Path("/books/{bookId}/{new}")
- public Book getNewBook(Book b) {
- return new Book();
- }
-
- @Path("/books/{bookId}/{new}")
- public Book getNewBook2() {
- return new Book();
- }
-
-// @Path("/books/{bookId}/{new}")
-// public List<Book> getNewBook3() {
-// return null;
-// }
-
- @POST
- public void setNewBook(Book b) {
- }
-
- @Path("/books/{bookId}/{new}")
- @POST
- public void setNewBook2(@PathParam("new") String id, Book b) {
- }
- }
-
- @Path("/")
- @Ignore
- public static class TheSDOBooks {
-
- @GET
- @Path("/books/{bookId}/{new}")
- public Structure getStructure() {
- return null;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
index ec0d449..2f4708f 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSDataBindingTest.java
@@ -19,19 +19,12 @@
package org.apache.cxf.systest.jaxrs;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
-import org.apache.cxf.databinding.DataBinding;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
import org.apache.cxf.jaxrs.provider.aegis.AegisElementProvider;
-import org.apache.cxf.jaxrs.provider.json.DataBindingJSONProvider;
-import org.apache.cxf.message.Message;
import org.apache.cxf.sdo.SDODataBinding;
import org.apache.cxf.systest.jaxrs.sdo.SDOResource;
import org.apache.cxf.systest.jaxrs.sdo.Structure;
@@ -93,26 +86,5 @@ public class JAXRSDataBindingTest extends AbstractBusClientServerTestBase {
assertEquals(3, struct.getInt());
}
- @Test
- public void testSDOStructureJSON() throws Exception {
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
- DataBinding db = new SDODataBinding();
- bean.setDataBinding(db);
- DataBindingJSONProvider<Structure> provider = new DataBindingJSONProvider<Structure>();
- provider.setNamespaceMap(Collections.singletonMap("http://apache.org/structure/types", "p0"));
- provider.setDataBinding(db);
- bean.setProvider(provider);
- bean.setAddress("http://localhost:" + PORT + "/databinding/sdo");
- bean.setResourceClass(SDOResource.class);
- List<Interceptor<? extends Message>> list = new ArrayList<Interceptor<? extends Message>>();
- list.add(new LoggingInInterceptor());
- bean.setInInterceptors(list);
- SDOResource client = bean.create(SDOResource.class);
- WebClient.client(client).accept("application/json");
- Structure struct = client.getStructure();
- assertEquals("sdo", struct.getText());
- assertEquals(123.5, struct.getDbl(), 0.01);
- assertEquals(3, struct.getInt());
- }
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/54910695/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
index 5960555..ff8613d 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_databinding/WEB-INF/beans.xml
@@ -59,9 +59,6 @@
<jaxrs:dataBinding>
<ref bean="sdoDatabinding"/>
</jaxrs:dataBinding>
- <jaxrs:providers>
- <ref bean="jsonSdoBean"/>
- </jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="sdo2" address="/sdo2">
<jaxrs:serviceBeans>
@@ -69,12 +66,6 @@
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="sdoDatabinding" class="org.apache.cxf.sdo.SDODataBinding"/>
- <bean id="jsonSdoBean" class="org.apache.cxf.jaxrs.provider.json.DataBindingJSONProvider">
- <property name="dataBinding" ref="sdoDatabinding"/>
- <property name="namespaceMap" ref="jsonNamespaceMap"/>
- </bean>
- <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
- <entry key="http://apache.org/structure/types" value="p0"/>
- </util:map>
+
</beans>
<!-- END SNIPPET: beans -->