Author: thomas.diesler(a)jboss.com
Date: 2008-03-14 23:42:44 -0400 (Fri, 14 Mar 2008)
New Revision: 5983
Added:
stack/native/trunk/src/main/java/org/jboss/ws/annotation/JsonEncoding.java
stack/native/trunk/src/main/java/org/jboss/ws/core/client/JsonConnectionHTTP.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageMarshaller.java
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageUnMarshaller.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/BadgerFishXMLEventWriter.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentParser.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentSerializer.java
stack/native/trunk/src/main/java/org/jboss/ws/feature/JsonEncodingFeature.java
stack/native/trunk/src/main/resources/jbossws-core.jar/META-INF/services/org.jboss.ws.core.client.RemoteConnection.http.json
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonEndpoint.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonPort.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonTestCase.java
stack/native/trunk/src/test/resources/jaxws/json/
stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/
stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/web.xml
Removed:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/BadgerFishXMLEventWriter.java
Modified:
stack/native/trunk/ant-import-tests/build-jars-jaxws.xml
stack/native/trunk/ant-import/jbossws-deploy-macros.xml
stack/native/trunk/src/main/java/javax/xml/ws/http/HTTPBinding.java
stack/native/trunk/src/main/java/org/jboss/ws/core/CommonClient.java
stack/native/trunk/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java
stack/native/trunk/src/main/java/org/jboss/ws/core/client/RemoteConnectionFactory.java
stack/native/trunk/src/main/java/org/jboss/ws/feature/FastInfosetFeature.java
stack/native/trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/EndpointFeatureProcessor.java
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/fastinfoset/FastInfosetAPITestCase.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonAPITestCase.java
Log:
[JBWS-1165] Add initial JSON support
Modified: stack/native/trunk/ant-import/jbossws-deploy-macros.xml
===================================================================
--- stack/native/trunk/ant-import/jbossws-deploy-macros.xml 2008-03-14 15:12:14 UTC (rev
5982)
+++ stack/native/trunk/ant-import/jbossws-deploy-macros.xml 2008-03-15 03:42:44 UTC (rev
5983)
@@ -44,6 +44,7 @@
<include name="**/jboss-jaxws.jar"/>
<include name="**/jboss-jaxws-ext.jar"/>
<include name="**/jboss-saaj.jar"/>
+ <include name="**/jettison.jar"/>
<include name="**/policy.jar"/>
<include name="**/stax-api.jar"/>
<include name="**/stax-ex.jar"/>
@@ -79,6 +80,7 @@
<include name="**/FastInfoset.jar"/>
<include name="**/jboss-jaxb-intros.jar"/>
<include name="**/jbossws-core.jar"/>
+ <include name="**/jettison.jar"/>
<include name="**/policy.jar"/>
<include name="**/wsdl4j.jar"/>
<include name="**/xmlsec.jar"/>
Modified: stack/native/trunk/ant-import-tests/build-jars-jaxws.xml
===================================================================
--- stack/native/trunk/ant-import-tests/build-jars-jaxws.xml 2008-03-14 15:12:14 UTC (rev
5982)
+++ stack/native/trunk/ant-import-tests/build-jars-jaxws.xml 2008-03-15 03:42:44 UTC (rev
5983)
@@ -146,6 +146,13 @@
</classes>
</war>
+ <!-- jaxws-json -->
+ <war warfile="${tests.output.dir}/libs/jaxws-json.war"
webxml="${tests.output.dir}/resources/jaxws/json/WEB-INF/web.xml">
+ <classes dir="${tests.output.dir}/classes">
+ <include
name="org/jboss/test/ws/jaxws/json/JsonEndpoint.class"/>
+ </classes>
+ </war>
+
<!-- jaxws-jaxbintros -->
<war warfile="${tests.output.dir}/libs/jaxws-jaxbintros.war"
webxml="${tests.output.dir}/resources/jaxws/jaxbintros/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/classes">
Modified: stack/native/trunk/src/main/java/javax/xml/ws/http/HTTPBinding.java
===================================================================
--- stack/native/trunk/src/main/java/javax/xml/ws/http/HTTPBinding.java 2008-03-14
15:12:14 UTC (rev 5982)
+++ stack/native/trunk/src/main/java/javax/xml/ws/http/HTTPBinding.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -24,7 +24,6 @@
// $Id$
import javax.xml.ws.Binding;
-import javax.xml.ws.Binding21;
/** The <code>HTTPBinding</code> interface is an
* abstraction for the XML/HTTP binding.
@@ -33,7 +32,6 @@
**/
public interface HTTPBinding extends Binding
{
-
/**
* A constant representing the identity of the XML/HTTP binding.
*/
Added: stack/native/trunk/src/main/java/org/jboss/ws/annotation/JsonEncoding.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/annotation/JsonEncoding.java
(rev 0)
+++ stack/native/trunk/src/main/java/org/jboss/ws/annotation/JsonEncoding.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.annotation;
+
+// $Id$
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.ws.feature.JsonEncodingFeature;
+
+/**
+ * This feature represents the use of JSON encoding
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 29-Feb-2008
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.TYPE })
+@EndpointFeature(id = JsonEncodingFeature.ID)
+public @interface JsonEncoding {
+
+ /**
+ * Specifies if the feature is enabled or disabled
+ */
+ boolean enabled() default true;
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/annotation/JsonEncoding.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/CommonClient.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/CommonClient.java 2008-03-14
15:12:14 UTC (rev 5982)
+++ stack/native/trunk/src/main/java/org/jboss/ws/core/CommonClient.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -49,7 +49,6 @@
import org.jboss.ws.core.client.EndpointInfo;
import org.jboss.ws.core.client.RemoteConnection;
import org.jboss.ws.core.client.RemoteConnectionFactory;
-import org.jboss.ws.core.client.SOAPProtocolConnectionHTTP;
import org.jboss.ws.core.jaxrpc.ParameterWrapping;
import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.core.soap.Style;
@@ -107,7 +106,7 @@
{
this.epMetaData = serviceMetaData.getEndpoints().get(0);
}
-
+
// Initialize the binding provider
this.bindingProvider = getCommonBindingProvider();
}
@@ -117,7 +116,7 @@
protected CommonClient(EndpointMetaData epMetaData)
{
this.epMetaData = epMetaData;
-
+
// Initialize the binding provider
this.bindingProvider = getCommonBindingProvider();
}
@@ -146,7 +145,7 @@
{
setOperationName(opName);
}
-
+
// Initialize the binding provider
this.bindingProvider = getCommonBindingProvider();
}
@@ -657,7 +656,7 @@
EndpointMetaData epMetaData = getEndpointMetaData();
return epMetaData.getConfigFile();
}
-
+
public String getSecurityConfig()
{
return securityConfig;
@@ -666,7 +665,7 @@
public void setSecurityConfig(String securityConfig)
{
this.securityConfig = securityConfig;
-
+
if (securityConfig != null)
{
EndpointMetaData epMetaData = getEndpointMetaData();
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/client/HTTPRemotingConnection.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -52,14 +52,13 @@
import org.jboss.ws.core.StubExt;
import org.jboss.ws.core.WSTimeoutException;
import org.jboss.ws.core.soap.MessageContextAssociation;
-import org.jboss.ws.metadata.config.EndpointProperty;
-import org.jboss.ws.metadata.config.CommonConfig;
-import org.jboss.ws.metadata.umdm.EndpointMetaData;
-
import org.jboss.ws.extensions.wsrm.transport.RMChannel;
-import org.jboss.ws.extensions.wsrm.transport.RMTransportHelper;
import org.jboss.ws.extensions.wsrm.transport.RMMetadata;
+import org.jboss.ws.extensions.wsrm.transport.RMTransportHelper;
import org.jboss.ws.feature.FastInfosetFeature;
+import org.jboss.ws.metadata.config.CommonConfig;
+import org.jboss.ws.metadata.config.EndpointProperty;
+import org.jboss.ws.metadata.umdm.EndpointMetaData;
/**
* SOAPConnection implementation.
Added: stack/native/trunk/src/main/java/org/jboss/ws/core/client/JsonConnectionHTTP.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/client/JsonConnectionHTTP.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/client/JsonConnectionHTTP.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.client;
+
+// $Id$
+
+import java.util.Map;
+
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPConstants;
+
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.ws.core.MessageAbstraction;
+import org.jboss.ws.core.jaxws.binding.JsonMessageMarshaller;
+import org.jboss.ws.core.jaxws.binding.JsonMessageUnMarshaller;
+import org.jboss.ws.core.soap.attachment.MimeConstants;
+
+/**
+ * JSON remoting connection
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 12-Mar-2008
+ */
+public class JsonConnectionHTTP extends HTTPRemotingConnection
+{
+ public UnMarshaller getUnmarshaller()
+ {
+ return new JsonMessageUnMarshaller();
+ }
+
+ public Marshaller getMarshaller()
+ {
+ return new JsonMessageMarshaller();
+ }
+
+ @Override
+ protected void populateHeaders(MessageAbstraction reqMessage, Map<String,
Object> metadata)
+ {
+ // TODO: fix the content-type
+ MimeHeaders mimeHeaders = reqMessage.getMimeHeaders();
+ mimeHeaders.setHeader(MimeConstants.CONTENT_TYPE,
SOAPConstants.SOAP_1_1_CONTENT_TYPE);
+
+ super.populateHeaders(reqMessage, metadata);
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/core/client/JsonConnectionHTTP.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/client/RemoteConnectionFactory.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/client/RemoteConnectionFactory.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/client/RemoteConnectionFactory.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -22,6 +22,7 @@
package org.jboss.ws.core.client;
import org.jboss.ws.feature.FastInfosetFeature;
+import org.jboss.ws.feature.JsonEncodingFeature;
import org.jboss.wsf.spi.util.ServiceLoader;
// $Id$
@@ -50,7 +51,13 @@
throw new IllegalArgumentException("Cannot obtain remote connetion for:
" + targetAddress);
if (epInfo.isFeatureEnabled(FastInfosetFeature.class))
+ {
key += ".fastinfoset";
+ }
+ else if (epInfo.isFeatureEnabled(JsonEncodingFeature.class))
+ {
+ key += ".json";
+ }
RemoteConnection con = (RemoteConnection)ServiceLoader.loadService(key, null);
if (con == null)
Added:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageMarshaller.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageMarshaller.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageMarshaller.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.jaxws.binding;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.invocation.OnewayInvocation;
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
+import org.jboss.ws.core.soap.SOAPMessageImpl;
+import org.jboss.ws.extensions.json.DOMDocumentSerializer;
+
+/**
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 25-Nov-2004
+ */
+public class JsonMessageMarshaller implements Marshaller
+{
+ // Provide logging
+ private static Logger log = Logger.getLogger(JsonMessageMarshaller.class);
+
+ /**
+ * Marshaller will need to take the dataObject and convert
+ * into primitive java data types and write to the
+ * given output.
+ *
+ * @param dataObject Object to be writen to output
+ * @param output The data output to write the object
+ * data to.
+ */
+ public void write(Object dataObject, OutputStream output) throws IOException
+ {
+ if (dataObject instanceof InvocationRequest)
+ dataObject = ((InvocationRequest)dataObject).getParameter();
+
+ if (dataObject instanceof OnewayInvocation)
+ dataObject = ((OnewayInvocation)dataObject).getParameters()[0];
+
+ // TODO: this should not be a SOAP message
+ if ((dataObject instanceof SOAPMessageImpl) == false)
+ throw new IllegalArgumentException("Not a SOAPMessageImpl: " +
dataObject);
+
+ try
+ {
+ SOAPMessage soapMessage = (SOAPMessage)dataObject;
+ SOAPBodyImpl soapBody = (SOAPBodyImpl)soapMessage.getSOAPBody();
+ SOAPBodyElement payload = soapBody.getBodyElement();
+ new DOMDocumentSerializer(output).serialize(payload);
+ }
+ catch (SOAPException ex)
+ {
+ IOException ioex = new IOException("Cannot serialize: " +
dataObject);
+ ioex.initCause(ex);
+ throw ioex;
+ }
+ }
+
+ public Marshaller cloneMarshaller() throws CloneNotSupportedException
+ {
+ return new JsonMessageMarshaller();
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageMarshaller.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageUnMarshaller.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageUnMarshaller.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageUnMarshaller.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.core.jaxws.binding;
+
+// $Id$
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.ws.core.soap.MessageFactoryImpl;
+import org.jboss.ws.extensions.json.DOMDocumentParser;
+import org.w3c.dom.Document;
+
+/**
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 25-Nov-2004
+ */
+public class JsonMessageUnMarshaller implements UnMarshaller
+{
+ // Provide logging
+ private static Logger log = Logger.getLogger(JsonMessageUnMarshaller.class);
+
+ public Object read(InputStream inputStream, Map metadata) throws IOException,
ClassNotFoundException
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Read input stream with metadata=" + metadata);
+ }
+
+ // TODO: this should not be a SOAP message
+ try
+ {
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ SOAPMessage soapMsg = factory.createMessage();
+ Document doc = new DOMDocumentParser().parse(inputStream);
+ soapMsg.getSOAPBody().addDocument(doc);
+ return soapMsg;
+ }
+ catch (SOAPException ex)
+ {
+ IOException ioex = new IOException("Cannot unmarshall json input
stream");
+ ioex.initCause(ex);
+ throw ioex;
+ }
+ }
+
+ /**
+ * Set the class loader to use for unmarhsalling. This may
+ * be needed when need to have access to class definitions that
+ * are not part of this unmarshaller's parent classloader (especially
+ * when doing remote classloading).
+ *
+ * @param classloader
+ */
+ public void setClassLoader(ClassLoader classloader)
+ {
+ //NO OP
+ }
+
+ public UnMarshaller cloneUnMarshaller() throws CloneNotSupportedException
+ {
+ return new JsonMessageUnMarshaller();
+ }
+
+ private MimeHeaders getMimeHeaders(Map metadata)
+ {
+ log.debug("getMimeHeaders from: " + metadata);
+
+ MimeHeaders headers = new MimeHeaders();
+ Iterator i = metadata.keySet().iterator();
+ while (i.hasNext())
+ {
+ String key = (String)i.next();
+ Object value = metadata.get(key);
+ if (key != null && value instanceof List)
+ {
+ for (Object listValue : (List)value)
+ {
+ headers.addHeader(key, listValue.toString());
+ }
+ }
+ }
+ return headers;
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/core/jaxws/binding/JsonMessageUnMarshaller.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/BadgerFishXMLEventWriter.java
(from rev 5982,
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/BadgerFishXMLEventWriter.java)
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/BadgerFishXMLEventWriter.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/BadgerFishXMLEventWriter.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.json;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+/**
+ * An BadgerFishXMLEventWriter that delegates to an XMLStreamWriter.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 12-Mar-2008
+ */
+public class BadgerFishXMLEventWriter implements XMLEventWriter
+{
+ private XMLStreamWriter streamWriter;
+
+ public BadgerFishXMLEventWriter(XMLStreamWriter streamWriter)
+ {
+ this.streamWriter = streamWriter;
+ }
+
+ public void add(XMLEvent event) throws XMLStreamException
+ {
+ if (event.isStartDocument())
+ {
+ streamWriter.writeStartDocument();
+ }
+ else if (event.isStartElement())
+ {
+ StartElement element = event.asStartElement();
+ QName elQName = element.getName();
+ if (elQName.getPrefix().length() > 0 &&
elQName.getNamespaceURI().length() > 0)
+ streamWriter.writeStartElement(elQName.getPrefix(), elQName.getLocalPart(),
elQName.getNamespaceURI());
+ else if (elQName.getNamespaceURI().length() > 0)
+ streamWriter.writeStartElement(elQName.getNamespaceURI(),
elQName.getLocalPart());
+ else
+ streamWriter.writeStartElement(elQName.getLocalPart());
+
+ // Add element namespaces
+ Iterator namespaces = element.getNamespaces();
+ while (namespaces.hasNext())
+ {
+ Namespace ns = (Namespace)namespaces.next();
+ String prefix = ns.getPrefix();
+ String nsURI = ns.getNamespaceURI();
+ streamWriter.writeNamespace(prefix, nsURI);
+ }
+
+ // Add element attributes
+ Iterator attris = element.getAttributes();
+ while (attris.hasNext())
+ {
+ Attribute attr = (Attribute)attris.next();
+ QName atQName = attr.getName();
+ String value = attr.getValue();
+ if (atQName.getPrefix().length() > 0 &&
atQName.getNamespaceURI().length() > 0)
+ streamWriter.writeAttribute(atQName.getPrefix(),
atQName.getNamespaceURI(), atQName.getLocalPart(), value);
+ else if (atQName.getNamespaceURI().length() > 0)
+ streamWriter.writeAttribute(atQName.getNamespaceURI(),
atQName.getLocalPart(), value);
+ else
+ streamWriter.writeAttribute(atQName.getLocalPart(), value);
+ }
+ }
+ else if (event.isCharacters())
+ {
+ Characters chars = event.asCharacters();
+ streamWriter.writeCharacters(chars.getData());
+ }
+ else if (event.isEndElement())
+ {
+ streamWriter.writeEndElement();
+ }
+ else if (event.isEndDocument())
+ {
+ streamWriter.writeEndDocument();
+ }
+ else
+ {
+ throw new XMLStreamException("Unsupported event type: " + event);
+ }
+ }
+
+ public void add(XMLEventReader eventReader) throws XMLStreamException
+ {
+ while (eventReader.hasNext())
+ {
+ XMLEvent event = eventReader.nextEvent();
+ add(event);
+ }
+ close();
+ }
+
+ public void close() throws XMLStreamException
+ {
+ streamWriter.close();
+ }
+
+ public void flush() throws XMLStreamException
+ {
+ streamWriter.flush();
+ }
+
+ public NamespaceContext getNamespaceContext()
+ {
+ return streamWriter.getNamespaceContext();
+ }
+
+ public String getPrefix(String prefix) throws XMLStreamException
+ {
+ return streamWriter.getPrefix(prefix);
+ }
+
+ public void setDefaultNamespace(String namespace) throws XMLStreamException
+ {
+ streamWriter.setDefaultNamespace(namespace);
+ }
+
+ public void setNamespaceContext(NamespaceContext nsContext) throws XMLStreamException
+ {
+ streamWriter.setNamespaceContext(nsContext);
+ }
+
+ public void setPrefix(String prefix, String uri) throws XMLStreamException
+ {
+ streamWriter.setPrefix(prefix, uri);
+ }
+}
\ No newline at end of file
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentParser.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentParser.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentParser.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.json;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.codehaus.jettison.badgerfish.BadgerFishXMLInputFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * An JSON BadgerFish DOM parser
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 12-Mar-2008
+ */
+public class DOMDocumentParser
+{
+ public Document parse(InputStream input) throws IOException
+ {
+ try
+ {
+ BadgerFishXMLInputFactory inputFactory = new BadgerFishXMLInputFactory();
+ XMLStreamReader streamReader = inputFactory.createXMLStreamReader(input);
+ XMLInputFactory readerFactory = XMLInputFactory.newInstance();
+ XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader);
+
+ // Can not create a STaX writer for a DOMResult in woodstox-3.1.1
+ // DOMResult result = new DOMResult();
+ // XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(result);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+ XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(baos);
+ eventWriter.add(eventReader);
+ eventWriter.close();
+
+ // This parsing step should not be necessary, if we could output to a DOMResult
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ return getDocumentBuilder().parse(bais);
+ }
+ catch (XMLStreamException ex)
+ {
+ IOException ioex = new IOException("Cannot parse input stream");
+ ioex.initCause(ex);
+ throw ioex;
+ }
+ catch (SAXException ex)
+ {
+ IOException ioex = new IOException("Cannot import in target
document");
+ ioex.initCause(ex);
+ throw ioex;
+ }
+ }
+
+ private DocumentBuilder getDocumentBuilder()
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder;
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new RuntimeException("Failed to create DocumentBuilder", e);
+ }
+ }
+}
\ No newline at end of file
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentParser.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentSerializer.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentSerializer.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentSerializer.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.json;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMSource;
+
+import org.codehaus.jettison.badgerfish.BadgerFishXMLOutputFactory;
+import org.w3c.dom.Element;
+
+/**
+ * An JSON BadgerFish DOM serializer
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 12-Mar-2008
+ */
+public class DOMDocumentSerializer
+{
+ private OutputStream output;
+
+ public DOMDocumentSerializer(OutputStream output)
+ {
+ this.output = output;
+ }
+
+ public void serialize(Element el) throws IOException
+ {
+ if (output == null)
+ throw new IllegalStateException("OutputStream cannot be null");
+
+ try
+ {
+ DOMSource source = new DOMSource(el);
+ XMLInputFactory readerFactory = XMLInputFactory.newInstance();
+ XMLStreamReader streamReader = readerFactory.createXMLStreamReader(source);
+ XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader);
+
+ BadgerFishXMLOutputFactory writerFactory = new BadgerFishXMLOutputFactory();
+ XMLStreamWriter streamWriter = writerFactory.createXMLStreamWriter(output);
+ // Not implemented in jettison-1.0-RC2
+ // XMLEventWriter eventWriter = writerFactory.createXMLEventWriter(output);
+ XMLEventWriter eventWriter = new BadgerFishXMLEventWriter(streamWriter);
+ eventWriter.add(eventReader);
+ eventWriter.close();
+ }
+ catch (XMLStreamException ex)
+ {
+ IOException ioex = new IOException("Cannot serialize: " + el);
+ ioex.initCause(ex);
+ throw ioex;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/json/DOMDocumentSerializer.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: stack/native/trunk/src/main/java/org/jboss/ws/feature/FastInfosetFeature.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/feature/FastInfosetFeature.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/main/java/org/jboss/ws/feature/FastInfosetFeature.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -36,12 +36,12 @@
public final class FastInfosetFeature extends WebServiceFeature
{
/**
- * Constant value identifying the SchemaValidationFeature
+ * Constant value identifying the FastInfosetFeature
*/
public static final String ID = Constants.NS_JBOSSWS_URI +
"/features/fastinfoset";
/**
- * Create an <code>SchemaValidationFeature</code>.
+ * Create an <code>FastInfosetFeature</code>.
* The instance created will be enabled.
*/
public FastInfosetFeature()
@@ -50,7 +50,7 @@
}
/**
- * Creates an <code>SchemaValidationFeature</code>.
+ * Creates an <code>FastInfosetFeature</code>.
*
* @param enabled specifies if this feature should be enabled or not
*/
Added: stack/native/trunk/src/main/java/org/jboss/ws/feature/JsonEncodingFeature.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/feature/JsonEncodingFeature.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/feature/JsonEncodingFeature.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.feature;
+
+// $Id$
+
+import javax.xml.ws.WebServiceFeature;
+
+import org.jboss.ws.Constants;
+
+/**
+ * This feature represents the use of JSON encoding
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 29-Feb-2008
+ */
+public final class JsonEncodingFeature extends WebServiceFeature
+{
+ /**
+ * Constant value identifying the JSON encoding feature
+ */
+ public static final String ID = Constants.NS_JBOSSWS_URI +
"/features/json";
+
+ /**
+ * Create an <code>JsonFeature</code>.
+ * The instance created will be enabled.
+ */
+ public JsonEncodingFeature()
+ {
+ this.enabled = true;
+ }
+
+ /**
+ * Creates an <code>JsonFeature</code>.
+ *
+ * @param enabled specifies if this feature should be enabled or not
+ */
+ public JsonEncodingFeature(boolean enabled)
+ {
+ this.enabled = enabled;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getID()
+ {
+ return ID;
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/feature/JsonEncodingFeature.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/EndpointFeatureProcessor.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/EndpointFeatureProcessor.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/main/java/org/jboss/ws/metadata/builder/jaxws/EndpointFeatureProcessor.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -29,8 +29,10 @@
import org.jboss.ws.WSException;
import org.jboss.ws.annotation.FastInfoset;
+import org.jboss.ws.annotation.JsonEncoding;
import org.jboss.ws.annotation.SchemaValidation;
import org.jboss.ws.feature.FastInfosetFeature;
+import org.jboss.ws.feature.JsonEncodingFeature;
import org.jboss.ws.feature.SchemaValidationFeature;
import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
import org.jboss.wsf.spi.deployment.ArchiveDeployment;
@@ -55,18 +57,19 @@
}
else if (an.annotationType() == FastInfoset.class)
{
- processFastInfoset(dep, sepMetaData, sepClass);
+ FastInfoset anFeature = sepClass.getAnnotation(FastInfoset.class);
+ FastInfosetFeature feature = new FastInfosetFeature(anFeature.enabled());
+ sepMetaData.addFeature(feature);
}
+ else if (an.annotationType() == JsonEncoding.class)
+ {
+ JsonEncoding anFeature = sepClass.getAnnotation(JsonEncoding.class);
+ JsonEncodingFeature feature = new JsonEncodingFeature(anFeature.enabled());
+ sepMetaData.addFeature(feature);
+ }
}
}
- private void processFastInfoset(Deployment dep, ServerEndpointMetaData sepMetaData,
Class<?> sepClass)
- {
- FastInfoset anFeature = sepClass.getAnnotation(FastInfoset.class);
- FastInfosetFeature feature = new FastInfosetFeature(anFeature.enabled());
- sepMetaData.addFeature(feature);
- }
-
private void processSchemaValidation(Deployment dep, ServerEndpointMetaData
sepMetaData, Class<?> sepClass)
{
SchemaValidation anFeature = sepClass.getAnnotation(SchemaValidation.class);
Modified:
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/main/java/org/jboss/wsf/stack/jbws/RequestHandlerImpl.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -44,6 +44,7 @@
import javax.xml.namespace.QName;
import javax.xml.rpc.JAXRPCException;
import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
@@ -74,13 +75,16 @@
import org.jboss.ws.core.server.WSDLRequestHandler;
import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.core.soap.MessageFactoryImpl;
+import org.jboss.ws.core.soap.SOAPBodyImpl;
import org.jboss.ws.core.soap.SOAPConnectionImpl;
import org.jboss.ws.core.soap.SOAPMessageImpl;
import org.jboss.ws.core.utils.ThreadLocalAssociation;
import org.jboss.ws.extensions.addressing.AddressingConstantsImpl;
+import org.jboss.ws.extensions.json.DOMDocumentParser;
import org.jboss.ws.extensions.wsrm.RMConstant;
import org.jboss.ws.extensions.xop.XOPContext;
import org.jboss.ws.feature.FastInfosetFeature;
+import org.jboss.ws.feature.JsonEncodingFeature;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
import org.jboss.ws.metadata.umdm.EndpointMetaData.Type;
@@ -98,8 +102,6 @@
import org.jboss.wsf.common.IOUtils;
import org.w3c.dom.Document;
-import com.sun.xml.fastinfoset.dom.DOMDocumentSerializer;
-
/**
* A request handler
*
@@ -359,6 +361,7 @@
}
else
{
+ // FastInfoset support
if (epMetaData.isFeatureEnabled(FastInfosetFeature.class) && resMessage
instanceof SOAPMessage)
{
SOAPMessage soapMessage = (SOAPMessage)resMessage;
@@ -366,10 +369,21 @@
throw new IllegalStateException("Attachments not supported with
FastInfoset");
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
- DOMDocumentSerializer serializer = new DOMDocumentSerializer();
+ com.sun.xml.fastinfoset.dom.DOMDocumentSerializer serializer = new
com.sun.xml.fastinfoset.dom.DOMDocumentSerializer();
serializer.setOutputStream(output);
serializer.serialize(soapEnv);
}
+ // JSON support
+ else if (epMetaData.isFeatureEnabled(JsonEncodingFeature.class) &&
resMessage instanceof SOAPMessage)
+ {
+ SOAPMessage soapMessage = (SOAPMessage)resMessage;
+ if (soapMessage.getAttachments().hasNext())
+ throw new IllegalStateException("Attachments not supported with
JSON");
+
+ SOAPBodyImpl soapBody = (SOAPBodyImpl)soapMessage.getSOAPBody();
+ SOAPBodyElement payload = soapBody.getBodyElement();
+ new
org.jboss.ws.extensions.json.DOMDocumentSerializer(output).serialize(payload);
+ }
else
{
resMessage.writeTo(output);
@@ -413,9 +427,16 @@
{
reqMessage = new HTTPMessageImpl(headers, inputStream);
}
+ else if (sepMetaData.isFeatureEnabled(JsonEncodingFeature.class))
+ {
+ MessageFactoryImpl factory = new MessageFactoryImpl();
+ SOAPMessageImpl soapMsg = (SOAPMessageImpl)factory.createMessage();
+ Document doc = new DOMDocumentParser().parse(inputStream);
+ soapMsg.getSOAPBody().addDocument(doc);
+ reqMessage = soapMsg;
+ }
else
{
-
msgFactory.setServiceMode(sepMetaData.getServiceMode());
msgFactory.setStyle(sepMetaData.getStyle());
msgFactory.setFeatures(sepMetaData.getFeatures());
Added:
stack/native/trunk/src/main/resources/jbossws-core.jar/META-INF/services/org.jboss.ws.core.client.RemoteConnection.http.json
===================================================================
---
stack/native/trunk/src/main/resources/jbossws-core.jar/META-INF/services/org.jboss.ws.core.client.RemoteConnection.http.json
(rev 0)
+++
stack/native/trunk/src/main/resources/jbossws-core.jar/META-INF/services/org.jboss.ws.core.client.RemoteConnection.http.json 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1 @@
+org.jboss.ws.core.client.JsonConnectionHTTP
\ No newline at end of file
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/fastinfoset/FastInfosetAPITestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/fastinfoset/FastInfosetAPITestCase.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/fastinfoset/FastInfosetAPITestCase.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -24,14 +24,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
-import org.jboss.ws.core.soap.MessageContextAssociation;
import org.jboss.ws.core.soap.MessageFactoryImpl;
import org.jboss.ws.feature.FastInfosetFeature;
import org.jboss.wsf.common.DOMUtils;
Deleted:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/BadgerFishXMLEventWriter.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/BadgerFishXMLEventWriter.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/BadgerFishXMLEventWriter.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -1,153 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.jaxws.json;
-
-import java.util.Iterator;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-import javax.xml.stream.events.Attribute;
-import javax.xml.stream.events.Characters;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
-
-/**
- * An BadgerFishXMLEventWriter that delegates to an XMLStreamWriter.
- *
- * @author Thomas.Diesler(a)jboss.com
- * @since 12-Mar-2008
- */
-public class BadgerFishXMLEventWriter implements XMLEventWriter
-{
- private XMLStreamWriter streamWriter;
-
- public BadgerFishXMLEventWriter(XMLStreamWriter streamWriter)
- {
- this.streamWriter = streamWriter;
- }
-
- public void add(XMLEvent event) throws XMLStreamException
- {
- if (event.isStartDocument())
- {
- streamWriter.writeStartDocument();
- }
- else if (event.isStartElement())
- {
- StartElement element = event.asStartElement();
- QName elQName = element.getName();
- if (elQName.getPrefix().length() > 0 &&
elQName.getNamespaceURI().length() > 0)
- streamWriter.writeStartElement(elQName.getPrefix(), elQName.getLocalPart(),
elQName.getNamespaceURI());
- else if (elQName.getNamespaceURI().length() > 0)
- streamWriter.writeStartElement(elQName.getNamespaceURI(),
elQName.getLocalPart());
- else
- streamWriter.writeStartElement(elQName.getLocalPart());
-
- Iterator attris = element.getAttributes();
- while (attris.hasNext())
- {
- Attribute attr = (Attribute)attris.next();
- QName atQName = attr.getName();
- String value = attr.getValue();
- if (atQName.getPrefix().length() > 0 &&
atQName.getNamespaceURI().length() > 0)
- streamWriter.writeAttribute(atQName.getPrefix(),
atQName.getNamespaceURI(), atQName.getLocalPart(), value);
- else if (atQName.getNamespaceURI().length() > 0)
- streamWriter.writeAttribute(atQName.getNamespaceURI(),
atQName.getLocalPart(), value);
- else
- streamWriter.writeAttribute(atQName.getLocalPart(), value);
- }
- }
- else if (event.isNamespace())
- {
- Attribute attr = (Attribute)event;
- QName qname = attr.getName();
- String nsURI = attr.getValue();
- streamWriter.writeNamespace(qname.getPrefix(), nsURI);
- }
- else if (event.isCharacters())
- {
- Characters chars = event.asCharacters();
- streamWriter.writeCharacters(chars.getData());
- }
- else if (event.isEndElement())
- {
- streamWriter.writeEndElement();
- }
- else if (event.isEndDocument())
- {
- streamWriter.writeEndDocument();
- }
- else
- {
- throw new XMLStreamException("Unsupported event type: " + event);
- }
- }
-
- public void add(XMLEventReader eventReader) throws XMLStreamException
- {
- while (eventReader.hasNext())
- {
- XMLEvent event = eventReader.nextEvent();
- add(event);
- }
- close();
- }
-
- public void close() throws XMLStreamException
- {
- streamWriter.close();
- }
-
- public void flush() throws XMLStreamException
- {
- streamWriter.flush();
- }
-
- public NamespaceContext getNamespaceContext()
- {
- return streamWriter.getNamespaceContext();
- }
-
- public String getPrefix(String prefix) throws XMLStreamException
- {
- return streamWriter.getPrefix(prefix);
- }
-
- public void setDefaultNamespace(String namespace) throws XMLStreamException
- {
- streamWriter.setDefaultNamespace(namespace);
- }
-
- public void setNamespaceContext(NamespaceContext nsContext) throws XMLStreamException
- {
- streamWriter.setNamespaceContext(nsContext);
- }
-
- public void setPrefix(String prefix, String uri) throws XMLStreamException
- {
- streamWriter.setPrefix(prefix, uri);
- }
-}
\ No newline at end of file
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonAPITestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonAPITestCase.java 2008-03-14
15:12:14 UTC (rev 5982)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonAPITestCase.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -23,24 +23,17 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.StringWriter;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.codehaus.jettison.badgerfish.BadgerFishXMLInputFactory;
-import org.codehaus.jettison.badgerfish.BadgerFishXMLOutputFactory;
-import org.codehaus.jettison.json.JSONTokener;
+import org.jboss.ws.extensions.json.DOMDocumentParser;
+import org.jboss.ws.extensions.json.DOMDocumentSerializer;
+import org.jboss.wsf.common.DOMUtils;
+import org.jboss.wsf.common.DOMWriter;
import org.jboss.wsf.test.JBossWSTest;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
- * Test Json functionality
+ * Test Json API
*
* @author Thomas.Diesler(a)jboss.com
* @since 12-Mar-2008
@@ -49,77 +42,70 @@
{
public void testSimple() throws Exception
{
- String xmlStr = "<root>hello world</root>";
- String expStr = "{\"root\":{\"$\":\"hello
world\"}}";
- String resStr = toJSON(xmlStr);
+ String xmlStr = "<kermit>the frog</kermit>";
+ String expStr = "{\"kermit\":{\"$\":\"the
frog\"}}";
+ String resStr = toJSON(DOMUtils.parse(xmlStr));
assertEquals("Unexpected result: " + resStr, expStr, resStr);
-
+
String resXML = toXML(resStr);
assertEquals("Unexpected result: " + resXML, xmlStr, resXML);
}
public void testSimpleAttribute() throws Exception
{
- String xmlStr = "<root myat=\"value\">hello
world</root>";
- String expStr =
"{\"root\":{\"@myat\":\"value\",\"$\":\"hello
world\"}}";
- String resStr = toJSON(xmlStr);
+ String xmlStr = "<kermit mygirl='piggy'>the
frog</kermit>";
+ String expStr =
"{\"kermit\":{\"@mygirl\":\"piggy\",\"$\":\"the
frog\"}}";
+ String resStr = toJSON(DOMUtils.parse(xmlStr));
assertEquals("Unexpected result: " + resStr, expStr, resStr);
-
+
String resXML = toXML(resStr);
assertEquals("Unexpected result: " + resXML, xmlStr, resXML);
}
- public void _testDefaultNamespace() throws Exception
+ public void testDefaultNamespace() throws Exception
{
- String xmlStr = "<root xmlns=\"http://somns\">hello
world</root>";
- String expStr = "{\"root\":{\"$\":\"hello
world\"}}";
- String resStr = toJSON(xmlStr);
+ String xmlStr = "<kermit xmlns='http://somens'>the
frog</kermit>";
+ String expStr =
"{\"kermit\":{\"@xmlns\":{\"$\":\"http:\\/\\/somens\"},\"$\":\"the
frog\"}}";
+ String resStr = toJSON(DOMUtils.parse(xmlStr));
assertEquals("Unexpected result: " + resStr, expStr, resStr);
-
+
String resXML = toXML(resStr);
assertEquals("Unexpected result: " + resXML, xmlStr, resXML);
}
- private String toJSON(String srcXML) throws FactoryConfigurationError,
XMLStreamException
+ public void testElementNamespace() throws Exception
{
- ByteArrayInputStream bais = new ByteArrayInputStream(srcXML.getBytes());
+ String xmlStr = "<ns1:kermit xmlns:ns1='http://somens'>the
frog</ns1:kermit>";
+ String expStr =
"{\"ns1:kermit\":{\"@xmlns\":{\"ns1\":\"http:\\/\\/somens\"},\"$\":\"the
frog\"}}";
+ String resStr = toJSON(DOMUtils.parse(xmlStr));
+ assertEquals("Unexpected result: " + resStr, expStr, resStr);
- XMLInputFactory readerFactory = XMLInputFactory.newInstance();
- XMLStreamReader streamReader = readerFactory.createXMLStreamReader(bais);
- XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader);
+ String resXML = toXML(resStr);
+ assertEquals("Unexpected result: " + resXML, xmlStr, resXML);
+ }
- StringWriter strWriter = new StringWriter();
- BadgerFishXMLOutputFactory writerFactory = new BadgerFishXMLOutputFactory();
- XMLStreamWriter streamWriter = writerFactory.createXMLStreamWriter(strWriter);
+ public void testElementAttributeNamespace() throws Exception
+ {
+ String xmlStr = "<ns1:kermit ns1:mygirl='piggy'
xmlns:ns1='http://somens'>the frog</ns1:kermit>";
+ String expStr =
"{\"ns1:kermit\":{\"@xmlns\":{\"ns1\":\"http:\\/\\/somens\"},\"@ns1:mygirl\":\"piggy\",\"$\":\"the
frog\"}}";
+ String resStr = toJSON(DOMUtils.parse(xmlStr));
+ assertEquals("Unexpected result: " + resStr, expStr, resStr);
- // UnsupportedOperationException in jettison-1.0-RC2
- //XMLEventWriter eventWriter = writerFactory.createXMLEventWriter(strWriter);
-
- XMLEventWriter eventWriter = new BadgerFishXMLEventWriter(streamWriter);
- eventWriter.add(eventReader);
- eventWriter.close();
-
- String jsonStr = strWriter.toString();
- return jsonStr;
+ String resXML = toXML(resStr);
+ assertEquals("Unexpected result: " + resXML, xmlStr, resXML);
}
- private String toXML(String jsonStr) throws XMLStreamException,
FactoryConfigurationError
+ private String toJSON(Element srcDOM) throws Exception
{
- BadgerFishXMLInputFactory inputFactory = new BadgerFishXMLInputFactory();
- XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new
JSONTokener(jsonStr));
- XMLInputFactory readerFactory = XMLInputFactory.newInstance();
- XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader);
-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(baos);
- eventWriter.add(eventReader);
- eventWriter.close();
-
- String resXML = new String(baos.toByteArray());
- if (resXML.startsWith("<?xml "))
- resXML = resXML.substring(resXML.indexOf("?>") + 2);
-
- return resXML;
+ new DOMDocumentSerializer(baos).serialize(srcDOM);
+ return new String(baos.toByteArray());
}
+
+ private String toXML(String jsonStr) throws Exception
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(jsonStr.getBytes());
+ Document resDOM = new DOMDocumentParser().parse(bais);
+ return DOMWriter.printNode(resDOM, false);
+ }
}
Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonEndpoint.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonEndpoint.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonEndpoint.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.json;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.annotation.JsonEncoding;
+
+@WebService(targetNamespace = "http://org.jboss.ws/json")
+@JsonEncoding
+public class JsonEndpoint
+{
+ // provide logging
+ private static Logger log = Logger.getLogger(JsonEndpoint.class);
+
+ @WebMethod
+ public String echo(String code)
+ {
+ log.info(code);
+ return code;
+ }
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonEndpoint.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonPort.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonPort.java
(rev 0)
+++ stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonPort.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.json;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://org.jboss.ws/json")
+public interface JsonPort
+{
+ @WebMethod
+ String echo(String code);
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonPort.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonTestCase.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonTestCase.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonTestCase.java 2008-03-15
03:42:44 UTC (rev 5983)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.json;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service21;
+
+import junit.framework.Test;
+
+import org.jboss.ws.feature.JsonEncodingFeature;
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * Test JSON functionality
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 12-Mar-2008
+ */
+public class JsonTestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(JsonTestCase.class, "jaxws-json.war");
+ }
+
+ public void testRoundTrip() throws Exception
+ {
+ URL wsdlURL = new URL("http://" + getServerHost() +
":8080/jaxws-json?wsdl");
+ QName serviceName = new QName("http://org.jboss.ws/json",
"JsonEndpointService");
+ Service21 service = Service21.create(wsdlURL, serviceName);
+
+ JsonEncodingFeature feature = new JsonEncodingFeature();
+ JsonPort port = service.getPort(JsonPort.class, feature);
+ String retStr = port.echo("hello world");
+ assertEquals("hello world", retStr);
+ }
+
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/json/JsonTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/web.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/web.xml
(rev 0)
+++ stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/web.xml 2008-03-15 03:42:44
UTC (rev 5983)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <servlet>
+ <servlet-name>JsonEndpoint</servlet-name>
+ <servlet-class>org.jboss.test.ws.jaxws.json.JsonEndpoint</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JsonEndpoint</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
Property changes on: stack/native/trunk/src/test/resources/jaxws/json/WEB-INF/web.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF