Author: veithen
Date: Wed Nov 14 14:46:04 2012
New Revision: 1409218
URL: http://svn.apache.org/viewvc?rev=1409218&view=rev
Log:
Merged a couple of fixes to the 1.6 branch to avoid 100% CPU usage triggered by
certain JSON payloads:
* AXIS2-5044 (r1127327; prerequisite for the other fixes)
* AXIS2-5125 (r1243469, r1290999)
* AXIS2-5300 (r1332362, r1332402; requires Axiom 1.2.14)
Modified:
axis/axis2/java/core/branches/1_6/ (props changed)
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONDataSource.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONOMBuilder.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishDataSource.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishMessageFormatter.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishOMBuilder.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONDataSource.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONMessageFormatter.java
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONOMBuilder.java
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONOMBuilderTest.java
axis/axis2/java/core/branches/1_6/modules/parent/pom.xml
axis/axis2/java/core/branches/1_6/modules/saaj/ (props changed)
Propchange: axis/axis2/java/core/branches/1_6/
------------------------------------------------------------------------------
Merged /axis/axis2/java/core/trunk:r1127327,1243469,1290999,1332362,1332402
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONDataSource.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONDataSource.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONDataSource.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONDataSource.java
Wed Nov 14 14:46:04 2012
@@ -19,18 +19,13 @@
package org.apache.axis2.json;
-import org.apache.axiom.om.OMDataSource;
import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.ds.AbstractPullOMDataSource;
-import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
import java.io.IOException;
-import java.io.OutputStream;
import java.io.Reader;
-import java.io.Writer;
import java.io.BufferedReader;
/**
@@ -39,119 +34,14 @@ import java.io.BufferedReader;
* directly without expanding. This uses the "Mapped" JSON convention.
*/
-public abstract class AbstractJSONDataSource implements OMDataSource {
+public abstract class AbstractJSONDataSource extends AbstractPullOMDataSource {
private Reader jsonReader;
private String jsonString;
private boolean isRead = false;
- protected String localName;
- public AbstractJSONDataSource(Reader jsonReader, String localName) {
+ public AbstractJSONDataSource(Reader jsonReader) {
this.jsonReader = jsonReader;
- this.localName = localName;
- }
-
- /**
- * Writes JSON into the output stream. As this should write JSON, it
directly gets the JSON
- * string and writes it without expanding the tree.
- *
- * @param outputStream the stream to be written into
- * @param omOutputFormat format of the message, this is ignored.
- * @throws javax.xml.stream.XMLStreamException
- * if there is an error while writing the message in to the
output stream.
- */
- public void serialize(OutputStream outputStream, OMOutputFormat
omOutputFormat)
- throws XMLStreamException {
- try {
- outputStream.write(getCompleteJOSNString().getBytes());
- } catch (IOException e) {
- throw new OMException();
- }
- }
-
- /**
- * Writes JSON through the writer. As this should write JSON, it directly
gets the JSON string
- * and writes it without expanding the tree.
- *
- * @param writer Writer to be written into
- * @param omOutputFormat format of the message, this is ignored.
- * @throws javax.xml.stream.XMLStreamException
- * if there is an error while writing the message through the
writer.
- */
- public void serialize(Writer writer, OMOutputFormat omOutputFormat)
- throws XMLStreamException {
- try {
- writer.write(getCompleteJOSNString());
- } catch (IOException e) {
- throw new OMException();
- }
- }
-
- /**
- * Writes XML through the XMLStreamWriter. As the input data source is
JSON, this method needs
- * to get a StAX reader from that JSON String. Therefore this uses the
getReader() method to get
- * the StAX reader writes the events into the XMLStreamWriter.
- *
- * @param xmlStreamWriter StAX writer to be written into
- * @throws javax.xml.stream.XMLStreamException
- * if there is an error while writing the message through the
StAX writer.
- */
- public void serialize(XMLStreamWriter xmlStreamWriter) throws
XMLStreamException {
- XMLStreamReader reader = getReader();
- xmlStreamWriter.writeStartDocument();
- while (reader.hasNext()) {
- int x = reader.next();
- switch (x) {
- case XMLStreamConstants.START_ELEMENT:
- xmlStreamWriter.writeStartElement(reader.getPrefix(),
reader.getLocalName(),
-
reader.getNamespaceURI());
- int namespaceCount = reader.getNamespaceCount();
- for (int i = namespaceCount - 1; i >= 0; i--) {
-
xmlStreamWriter.writeNamespace(reader.getNamespacePrefix(i),
-
reader.getNamespaceURI(i));
- }
- int attributeCount = reader.getAttributeCount();
- for (int i = 0; i < attributeCount; i++) {
-
xmlStreamWriter.writeAttribute(reader.getAttributePrefix(i),
-
reader.getAttributeNamespace(i),
-
reader.getAttributeLocalName(i),
-
reader.getAttributeValue(i));
- }
- break;
- case XMLStreamConstants.START_DOCUMENT:
- break;
- case XMLStreamConstants.CHARACTERS:
- xmlStreamWriter.writeCharacters(reader.getText());
- break;
- case XMLStreamConstants.CDATA:
- xmlStreamWriter.writeCData(reader.getText());
- break;
- case XMLStreamConstants.END_ELEMENT:
- xmlStreamWriter.writeEndElement();
- break;
- case XMLStreamConstants.END_DOCUMENT:
- xmlStreamWriter.writeEndDocument();
- break;
- case XMLStreamConstants.SPACE:
- break;
- case XMLStreamConstants.COMMENT:
- xmlStreamWriter.writeComment(reader.getText());
- break;
- case XMLStreamConstants.DTD:
- xmlStreamWriter.writeDTD(reader.getText());
- break;
- case XMLStreamConstants.PROCESSING_INSTRUCTION:
- xmlStreamWriter
- .writeProcessingInstruction(reader.getPITarget(),
reader.getPIData());
- break;
- case XMLStreamConstants.ENTITY_REFERENCE:
- xmlStreamWriter.writeEntityRef(reader.getLocalName());
- break;
- default :
- throw new OMException();
- }
- }
- xmlStreamWriter.writeEndDocument();
}
/**
@@ -164,6 +54,11 @@ public abstract class AbstractJSONDataSo
public abstract XMLStreamReader getReader() throws XMLStreamException;
+ public boolean isDestructiveRead() {
+ // TODO: for the moment the data source in not destructive (because it
reads the entire message into memory before processing it), but this will
change...
+ return false;
+ }
+
//returns the json string by consuming the JSON input stream.
protected String getJSONString() {
if (isRead) {
@@ -186,8 +81,4 @@ public abstract class AbstractJSONDataSo
return jsonString;
}
}
-
- public String getCompleteJOSNString() {
- return "{" + localName + ":" + getJSONString();
- }
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONMessageFormatter.java
Wed Nov 14 14:46:04 2012
@@ -170,6 +170,8 @@ public abstract class AbstractJSONMessag
out.write(jsonToWrite.getBytes());
} else {
XMLStreamWriter jsonWriter = getJSONWriter(out, format);
+ // Jettison v1.2+ relies on writeStartDocument being called
(AXIS2-5044)
+ jsonWriter.writeStartDocument();
element.serializeAndConsume(jsonWriter);
jsonWriter.writeEndDocument();
}
@@ -204,6 +206,8 @@ public abstract class AbstractJSONMessag
} else {
StringWriter out = new StringWriter();
XMLStreamWriter jsonWriter = getJSONWriter(out);
+ // Jettison v1.2+ relies on writeStartDocument being
called (AXIS2-5044)
+ jsonWriter.writeStartDocument();
dataOut.serializeAndConsume(jsonWriter);
jsonWriter.writeEndDocument();
jsonString = out.toString();
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONOMBuilder.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONOMBuilder.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONOMBuilder.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/AbstractJSONOMBuilder.java
Wed Nov 14 14:46:04 2012
@@ -22,7 +22,6 @@ package org.apache.axis2.json;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
@@ -30,7 +29,6 @@ import org.apache.axis2.builder.Builder;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.http.util.URIEncoderDecoder;
-import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -58,9 +56,6 @@ public abstract class AbstractJSONOMBuil
public OMElement processDocument(InputStream inputStream, String
contentType,
MessageContext messageContext) throws
AxisFault {
OMFactory factory = OMAbstractFactory.getOMFactory();
- String localName = "";
- String prefix = "";
- OMNamespace ns = factory.createOMNamespace("", "");
//sets DoingREST to true because, security scenarios needs to handle
in REST way
messageContext.setDoingREST(true);
@@ -108,46 +103,8 @@ public abstract class AbstractJSONOMBuil
}
}
- /*
- Now we have to read the localname and prefix from the input stream
- if there is not prefix, message starts like {"foo":
- if there is a prefix, message starts like {"prefix:foo":
- */
- try {
- //read the stream until we find a : symbol
- char temp = (char)reader.read();
- while (temp != ':') {
- if (temp != ' ' && temp != '{' && temp != '\n' && temp != '\r'
&& temp != '\t') {
- localName += temp;
- }
- temp = (char)reader.read();
- }
-
- //if the part we read ends with ", there is no prefix, otherwise
it has a prefix
- if (localName.charAt(0) == '"') {
- if (localName.charAt(localName.length() - 1) == '"') {
- localName = localName.substring(1, localName.length() - 1);
- } else {
- prefix = localName.substring(1, localName.length()) + ":";
- localName = "";
- //so far we have read only the prefix, now lets read the
localname
- temp = (char)reader.read();
- while (temp != ':') {
- if (temp != ' ') {
- localName += temp;
- }
- temp = (char)reader.read();
- }
- localName = localName.substring(0, localName.length() - 1);
- }
- }
- } catch (IOException e) {
- throw AxisFault.makeFault(e);
- }
- AbstractJSONDataSource jsonDataSource = getDataSource(reader, prefix,
localName);
- return factory.createOMElement(jsonDataSource, localName, ns);
+ return factory.createOMElement(getDataSource(reader));
}
- protected abstract AbstractJSONDataSource getDataSource(Reader
- jsonReader, String prefix, String localName);
+ protected abstract AbstractJSONDataSource getDataSource(Reader jsonReader);
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishDataSource.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishDataSource.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishDataSource.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishDataSource.java
Wed Nov 14 14:46:04 2012
@@ -31,8 +31,8 @@ import java.io.Reader;
public class JSONBadgerfishDataSource extends AbstractJSONDataSource {
- public JSONBadgerfishDataSource(Reader jsonReader, String localName) {
- super(jsonReader, localName);
+ public JSONBadgerfishDataSource(Reader jsonReader) {
+ super(jsonReader);
}
/**
@@ -48,7 +48,7 @@ public class JSONBadgerfishDataSource ex
//input factory for "Badgerfish"
BadgerFishXMLInputFactory inputFactory = new
BadgerFishXMLInputFactory();
return inputFactory.createXMLStreamReader(
- new JSONTokener("{" + localName + ":" + this.getJSONString()));
+ new JSONTokener(getJSONString()));
}
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishMessageFormatter.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishMessageFormatter.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishMessageFormatter.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishMessageFormatter.java
Wed Nov 14 14:46:04 2012
@@ -50,7 +50,7 @@ public class JSONBadgerfishMessageFormat
@Override
protected String getStringToWrite(OMDataSource dataSource) {
if (dataSource instanceof JSONBadgerfishDataSource) {
- return
((JSONBadgerfishDataSource)dataSource).getCompleteJOSNString();
+ return ((JSONBadgerfishDataSource)dataSource).getJSONString();
} else {
return null;
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishOMBuilder.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishOMBuilder.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishOMBuilder.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONBadgerfishOMBuilder.java
Wed Nov 14 14:46:04 2012
@@ -28,8 +28,7 @@ import java.io.Reader;
public class JSONBadgerfishOMBuilder extends AbstractJSONOMBuilder {
@Override
- protected AbstractJSONDataSource getDataSource(Reader jsonReader, String
prefix,
- String localName) {
- return new JSONBadgerfishDataSource(jsonReader, "\"" + prefix +
localName + "\"");
+ protected AbstractJSONDataSource getDataSource(Reader jsonReader) {
+ return new JSONBadgerfishDataSource(jsonReader);
}
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONDataSource.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONDataSource.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONDataSource.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONDataSource.java
Wed Nov 14 14:46:04 2012
@@ -33,8 +33,8 @@ import java.util.HashMap;
public class JSONDataSource extends AbstractJSONDataSource {
- public JSONDataSource(Reader jsonReader, String localName) {
- super(jsonReader, localName);
+ public JSONDataSource(Reader jsonReader) {
+ super(jsonReader);
}
/**
@@ -52,7 +52,6 @@ public class JSONDataSource extends Abst
//input factory for "Mapped" convention
MappedXMLInputFactory inputFactory = new
MappedXMLInputFactory(XMLToJSNNamespaceMap);
- String jsonString = "{" + localName + ":" + this.getJSONString();
- return inputFactory.createXMLStreamReader(new JSONTokener(jsonString));
+ return inputFactory.createXMLStreamReader(new
JSONTokener(getJSONString()));
}
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONMessageFormatter.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONMessageFormatter.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONMessageFormatter.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONMessageFormatter.java
Wed Nov 14 14:46:04 2012
@@ -57,7 +57,7 @@ public class JSONMessageFormatter extend
@Override
protected String getStringToWrite(OMDataSource dataSource) {
if (dataSource instanceof JSONDataSource) {
- return ((JSONDataSource)dataSource).getCompleteJOSNString();
+ return ((JSONDataSource)dataSource).getJSONString();
} else {
return null;
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONOMBuilder.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONOMBuilder.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONOMBuilder.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/src/org/apache/axis2/json/JSONOMBuilder.java
Wed Nov 14 14:46:04 2012
@@ -25,8 +25,7 @@ import java.io.Reader;
public class JSONOMBuilder extends AbstractJSONOMBuilder {
@Override
- protected AbstractJSONDataSource getDataSource(Reader
- jsonReader, String prefix, String localName) {
- return new JSONDataSource(jsonReader, "\"" + prefix + localName +
"\"");
+ protected AbstractJSONDataSource getDataSource(Reader jsonReader) {
+ return new JSONDataSource(jsonReader);
}
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONDataSourceTest.java
Wed Nov 14 14:46:04 2012
@@ -19,6 +19,7 @@
package org.apache.axis2.json;
+import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.util.StAXUtils;
import org.codehaus.jettison.json.JSONException;
import org.custommonkey.xmlunit.XMLTestCase;
@@ -30,58 +31,59 @@ import javax.xml.stream.XMLStreamWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.io.Reader;
import java.io.StringReader;
public class JSONDataSourceTest extends XMLTestCase {
- public void testMappedSerialize1() throws XMLStreamException {
+ public void testMappedSerialize1() throws Exception {
String jsonString = getMappedJSONString();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
JSONDataSource source = getMappedDataSource(jsonString);
- source.serialize(outStream, null);
- assertEquals(jsonString, new String(outStream.toByteArray()));
+ source.serialize(outStream, new OMOutputFormat());
+ assertXMLEqual("<mapping><inner><first>test string
one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
+ outStream.toString("utf-8"));
}
- public void testMappedSerialize2() throws XMLStreamException, IOException {
+ public void testMappedSerialize2() throws Exception {
String jsonString = getMappedJSONString();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(outStream);
JSONDataSource source = getMappedDataSource(jsonString);
- source.serialize(writer, null);
+ source.serialize(writer, new OMOutputFormat());
writer.flush();
- assertEquals(jsonString, new String(outStream.toByteArray()));
-
+ assertXMLEqual("<mapping><inner><first>test string
one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
+ outStream.toString("utf-8"));
}
- public void testMappedSerialize3() throws XMLStreamException {
+ public void testMappedSerialize3() throws Exception {
String jsonString = getMappedJSONString();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
XMLStreamWriter writer = StAXUtils.createXMLStreamWriter(outStream);
JSONDataSource source = getMappedDataSource(jsonString);
source.serialize(writer);
writer.flush();
- assertEquals(
- "<?xml version='1.0'
encoding='UTF-8'?><mapping><inner><first>test string
one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
- new String(outStream.toByteArray()));
+ assertXMLEqual("<mapping><inner><first>test string
one</first></inner><inner>test string two</inner><name>foo</name></mapping>",
+ outStream.toString("utf-8"));
}
- public void testBadgerfishSerialize1() throws XMLStreamException {
+ public void testBadgerfishSerialize1() throws Exception {
String jsonString = getBadgerfishJSONString();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
- source.serialize(outStream, null);
- assertEquals(jsonString, new String(outStream.toByteArray()));
+ source.serialize(outStream, new OMOutputFormat());
+ assertXMLEqual("<p xmlns=\"http://def.ns\"
xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam
att=\"lets\">555</sam></p>",
+ outStream.toString("utf-8"));
}
- public void testBadgerfishSerialize2() throws XMLStreamException,
IOException {
+ public void testBadgerfishSerialize2() throws Exception {
String jsonString = getBadgerfishJSONString();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(outStream);
JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
- source.serialize(writer, null);
+ source.serialize(writer, new OMOutputFormat());
writer.flush();
- assertEquals(jsonString, new String(outStream.toByteArray()));
+ assertXMLEqual("<p xmlns=\"http://def.ns\"
xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam
att=\"lets\">555</sam></p>",
+ outStream.toString("utf-8"));
}
public void testBadgerfishSerialize3() throws XMLStreamException,
JSONException, IOException,
@@ -92,14 +94,12 @@ public class JSONDataSourceTest extends
JSONBadgerfishDataSource source = getBadgerfishDataSource(jsonString);
source.serialize(writer);
writer.flush();
- assertXMLEqual(
- "<?xml version='1.0' encoding='UTF-8'?><p
xmlns=\"http://def.ns\" xmlns:bb=\"http://other.nsb\"
xmlns:aa=\"http://other.ns\"><sam att=\"lets\">555</sam></p>",
- new String(outStream.toByteArray()));
+ assertXMLEqual("<p xmlns=\"http://def.ns\"
xmlns:bb=\"http://other.nsb\" xmlns:aa=\"http://other.ns\"><sam
att=\"lets\">555</sam></p>",
+ outStream.toString("utf-8"));
}
private JSONBadgerfishDataSource getBadgerfishDataSource(String
jsonString) {
- Reader jsonReader = new StringReader(jsonString);
- return new JSONBadgerfishDataSource(readLocalName(jsonReader),
"\"p\"");
+ return new JSONBadgerfishDataSource(new StringReader(jsonString));
}
private String getBadgerfishJSONString() {
@@ -107,22 +107,10 @@ public class JSONDataSourceTest extends
}
private JSONDataSource getMappedDataSource(String jsonString) {
- Reader jsonReader = new StringReader(jsonString);
- return new JSONDataSource(readLocalName(jsonReader), "\"mapping\"");
+ return new JSONDataSource(new StringReader(jsonString));
}
private String getMappedJSONString() {
return "{\"mapping\":{\"inner\":[{\"first\":\"test string
one\"},\"test string two\"],\"name\":\"foo\"}}";
}
-
- private Reader readLocalName(Reader in) {
- try {
- while ((char)in.read() != ':') {
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return in;
- }
-
}
Modified:
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONOMBuilderTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONOMBuilderTest.java?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
---
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONOMBuilderTest.java
(original)
+++
axis/axis2/java/core/branches/1_6/modules/json/test/org/apache/axis2/json/JSONOMBuilderTest.java
Wed Nov 14 14:46:04 2012
@@ -18,12 +18,13 @@
*/
-/*package org.apache.axis2.json;
+package org.apache.axis2.json;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamException;
@@ -32,6 +33,8 @@ import junit.framework.TestCase;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.builder.Builder;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.TransportUtils;
import org.apache.axis2.transport.http.SOAPMessageFormatter;
@@ -39,21 +42,35 @@ import org.codehaus.jettison.json.JSONEx
import org.xml.sax.SAXException;
public class JSONOMBuilderTest extends TestCase {
+ public void testBadgerfishQName() throws Exception {
+ String jsonString = getBadgerfishJSONString();
+ ByteArrayInputStream inStream = new
ByteArrayInputStream(jsonString.getBytes("utf-8"));
+
+ MessageContext msgCtx = new MessageContext();
+ Builder builder = new JSONBadgerfishOMBuilder();
+ OMElement elem = builder.processDocument(inStream,
+ JSONTestConstants.CONTENT_TYPE_BADGERFISH, msgCtx);
+
+ QName qname = elem.getQName();
+ assertEquals("http://def.ns", qname.getNamespaceURI());
+ assertEquals("p", qname.getLocalPart());
+ assertEquals("", qname.getPrefix());
+ }
public void testBadgerfishOMSerialization1() throws IOException {
String jsonString = getBadgerfishJSONString();
ByteArrayInputStream inStream = new
ByteArrayInputStream(jsonString.getBytes());
- JSONOMBuilder omBuilder = new JSONBadgerfishOMBuilder();
+ MessageContext msgCtx = new MessageContext();
+ JSONOMBuilder omBuilder = new JSONOMBuilder();
OMElement elem = omBuilder.processDocument(inStream,
- JSONTestConstants.CONTENT_TYPE_BADGERFISH, null);
+ JSONTestConstants.CONTENT_TYPE_BADGERFISH, msgCtx);
elem.toString();
SOAPEnvelope envelope = TransportUtils.createSOAPEnvelope(elem);
- MessageContext msgCtx = new MessageContext();
msgCtx.setEnvelope(envelope);
OMOutputFormat outputFormat = new OMOutputFormat();
@@ -72,10 +89,11 @@ public class JSONOMBuilderTest extends T
IOException, ParserConfigurationException, SAXException {
String jsonString = getBadgerfishJSONString();
ByteArrayInputStream inStream = new
ByteArrayInputStream(jsonString.getBytes());
+ MessageContext msgCtx = new MessageContext();
- JSONOMBuilder omBuilder = new JSONBadgerfishOMBuilder();
+ JSONOMBuilder omBuilder = new JSONOMBuilder();
OMElement elem = omBuilder.processDocument(inStream,
- JSONTestConstants.CONTENT_TYPE_BADGERFISH, null);
+ JSONTestConstants.CONTENT_TYPE_BADGERFISH, msgCtx);
elem.toString();
@@ -86,9 +104,20 @@ public class JSONOMBuilderTest extends T
}
+ public void testEmptyJsonString() throws AxisFault {
+ String emptyJson = "{}";
+ ByteArrayInputStream inStream = new
ByteArrayInputStream(emptyJson.getBytes());
+ MessageContext messageContext = new MessageContext();
+
+ JSONOMBuilder omBuilder = new JSONOMBuilder();
+ OMElement elem = omBuilder.processDocument(inStream,
+ JSONTestConstants.CONTENT_TYPE_BADGERFISH, messageContext);
+ // TODO: not sure why we would want to send an empty list...
+// assertEquals(null ,elem);
+ }
+
private String getBadgerfishJSONString() {
return
"{\"p\":{\"@xmlns\":{\"bb\":\"http://other.nsb\",\"aa\":\"http://other.ns\",\"$\":\"http://def.ns\"},\"sam\":{\"$\":\"555\",
\"@att\":\"lets\"}}}";
}
}
-*/
\ No newline at end of file
Modified: axis/axis2/java/core/branches/1_6/modules/parent/pom.xml
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/parent/pom.xml?rev=1409218&r1=1409217&r2=1409218&view=diff
==============================================================================
--- axis/axis2/java/core/branches/1_6/modules/parent/pom.xml (original)
+++ axis/axis2/java/core/branches/1_6/modules/parent/pom.xml Wed Nov 14
14:46:04 2012
@@ -92,7 +92,7 @@
<jaxb.api.version>2.1</jaxb.api.version>
<jaxbri.version>2.1.7</jaxbri.version>
<jaxen.version>1.1.1</jaxen.version>
- <jettison.version>1.0-RC2</jettison.version>
+ <jettison.version>1.3</jettison.version>
<jibx.version>1.2</jibx.version>
<junit.version-jdk1.4>3.8.2</junit.version-jdk1.4>
<junit.version>4.4</junit.version>
Propchange: axis/axis2/java/core/branches/1_6/modules/saaj/
------------------------------------------------------------------------------
Merged
/axis/axis2/java/core/trunk/modules/saaj:r1127327,1243469,1290999,1332362,1332402