You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by jr...@apache.org on 2010/06/14 20:18:52 UTC
svn commit: r954578 [1/3] - in /incubator/wink/branches/wink-1.1-incubating:
wink-client/src/main/java/org/apache/wink/client/internal/handlers/
wink-common/src/main/java/org/apache/wink/common/internal/
wink-common/src/main/java/org/apache/wink/common...
Author: jramos
Date: Mon Jun 14 18:18:51 2010
New Revision: 954578
URL: http://svn.apache.org/viewvc?rev=954578&view=rev
Log:
[WINK-293] Merge new files from trunk to 1.1 branch
Added:
incubator/wink/branches/wink-1.1-incubating/wink-client/src/main/java/org/apache/wink/client/internal/handlers/DeflateHandler.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/WinkConfiguration.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/
incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/WinkSystemProperties.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/WinkSystemPropertiesTest.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProviderTest.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/AbstractJAXBCollectionProviderTest.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/MyPojo.java
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/ProvidersJAXBTest.txt
incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/SourceProviderTest.txt
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/pom.xml
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedApplication.java
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedResource.java
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/RegularResource.java
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/geronimo-web.xml
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.filter.xml
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.servlet.xml
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/apache/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/apache/wink/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/apache/wink/itests/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/apache/wink/itests/contentencode/
incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/test/java/org/apache/wink/itests/contentencode/ContentEncodedTest.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/
incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/ContentEncodingRequestFilter.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/ContentEncodingResponseFilter.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/application/ApplicationLifecycleManagamentTest.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/application/ApplicationLifecycleManagement2Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ProvidersLifecycle1Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ProvidersLifecycle2Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle1Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle2Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle3Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle4Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle5Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle6Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/lifecycle/ResourceLifecycle7Test.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/SourceProviderDTDSupportedTest.java
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/resources/etc/
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/resources/etc/JAXBElementProviderTest.txt
incubator/wink/branches/wink-1.1-incubating/wink-server/src/test/resources/etc/SourceProviderTest.txt
Added: incubator/wink/branches/wink-1.1-incubating/wink-client/src/main/java/org/apache/wink/client/internal/handlers/DeflateHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-client/src/main/java/org/apache/wink/client/internal/handlers/DeflateHandler.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-client/src/main/java/org/apache/wink/client/internal/handlers/DeflateHandler.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-client/src/main/java/org/apache/wink/client/internal/handlers/DeflateHandler.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.client.internal.handlers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterInputStream;
+
+import org.apache.wink.client.ClientRequest;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.handlers.ClientHandler;
+import org.apache.wink.client.handlers.HandlerContext;
+import org.apache.wink.client.handlers.InputStreamAdapter;
+import org.apache.wink.client.handlers.OutputStreamAdapter;
+
+public class DeflateHandler implements ClientHandler {
+
+ public ClientResponse handle(ClientRequest request, HandlerContext context) throws Exception {
+ request.getHeaders().add("Accept-Encoding", "deflate"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (request.getEntity() != null) {
+ request.getHeaders().add("Content-Encoding", "deflate"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ context.addInputStreamAdapter(new DeflateAdapter());
+ context.addOutputStreamAdapter(new DeflateAdapter());
+ return context.doChain(request);
+ }
+
+ private static class DeflateAdapter implements InputStreamAdapter, OutputStreamAdapter {
+
+ public OutputStream adapt(OutputStream os, ClientRequest request) throws IOException {
+ return new DeflaterOutputStream(os);
+ }
+
+ public InputStream adapt(InputStream is, ClientResponse response) throws IOException {
+ String header = response.getHeaders().getFirst("Content-Encoding"); //$NON-NLS-1$
+ if (header != null && header.equalsIgnoreCase("deflate")) { //$NON-NLS-1$
+ return new InflaterInputStream(is);
+ }
+ return is;
+ }
+ }
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/WinkConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/WinkConfiguration.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/WinkConfiguration.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/WinkConfiguration.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+package org.apache.wink.common.internal;
+
+import java.util.Properties;
+
+public interface WinkConfiguration {
+
+ /**
+ * get configuration properties
+ *
+ * @return configuration properties as defined by the server or client Wink module
+ */
+ public Properties getProperties();
+
+ /**
+ * @param properties the properties you intend to set for configuration on the server or client Wink module
+ */
+ public void setProperties(Properties properties);
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/WinkSystemProperties.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/WinkSystemProperties.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/WinkSystemProperties.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/main/java/org/apache/wink/common/internal/properties/WinkSystemProperties.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.properties;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WinkSystemProperties {
+
+ private static final Logger logger = LoggerFactory.getLogger(WinkSystemProperties.class);
+
+ /**
+ * Walks through each of the passed-in properties--presumably, these are
+ * all defined in a configuration file. - If the property is already set, do
+ * nothing. - If not, read it as a JVM property; if detected, set the
+ * property on systemProperties, which is returned.
+ */
+ public static Properties loadSystemProperties(Properties properties) {
+ String key = null;
+ String value = null;
+ Properties systemProperties = new Properties();
+
+ // Read the properties contained in passed-in properties
+ if (properties != null) {
+ Enumeration<?> keyEnum = properties.propertyNames();
+ while (keyEnum.hasMoreElements()) {
+ key = (String)keyEnum.nextElement();
+ value = (String)properties.get(key);
+
+ // If value is null or empty, try to read as JVM property
+ if (value == null || value.length() == 0) {
+ value = getSystemProperty(key);
+ if(value != null) {
+ systemProperties.setProperty(key, value);
+ }
+ } else {
+ logger.debug("Property {} is already defined with value {}", key, value); //$NON-NLS-1$
+ }
+ }
+ } else {
+ logger.debug("Properties are null"); //$NON-NLS-1$
+ }
+ return systemProperties;
+ }
+
+ /**
+ * Reads the JVM property and returns the value (which could be null).
+ */
+ private static String getSystemProperty(final String key) {
+ String value = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ String v = System.getProperty(key);
+ logger.debug(key + " = " + v); //$NON-NLS-1$
+ return v;
+ }
+ });
+ return value;
+ }
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/WinkSystemPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/WinkSystemPropertiesTest.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/WinkSystemPropertiesTest.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/properties/WinkSystemPropertiesTest.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+package org.apache.wink.common.internal.properties;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+public class WinkSystemPropertiesTest extends TestCase {
+
+ private static final String PROP_KEY = "someSysPropKey";
+
+ @Override
+ public void setUp() {
+ System.clearProperty(PROP_KEY);
+ }
+
+ @Test
+ public void testNullToleration() {
+ System.setProperty(PROP_KEY, "false");
+ // loadSystemProperties can only override an existing key in the properties bag. We should get an empty bag back
+ Properties props = WinkSystemProperties.loadSystemProperties(null);
+ assertTrue("expected empty properties bag", props.isEmpty());
+ }
+
+
+ @Test
+ public void testEmptyValue() {
+ Properties startProps = new Properties();
+ startProps.put(PROP_KEY, "");
+ System.setProperty(PROP_KEY, "false");
+ // loadSystemProperties can override an existing key in the properties bag when the value is empty
+ Properties props = WinkSystemProperties.loadSystemProperties(startProps);
+ assertEquals("expected non-null \""+PROP_KEY+"\" property to be \"false\"", "false", props.getProperty(PROP_KEY));
+ }
+
+ @Test
+ public void testGetSystemProperties() throws Exception {
+ Properties startProps = new Properties(); // empty
+ System.setProperty(PROP_KEY, "false");
+ // loadSystemProperties can only override an existing key in the properties bag. We should get an empty bag back
+ Properties props = WinkSystemProperties.loadSystemProperties(startProps);
+ assertTrue("expected empty properties bag", props.isEmpty());
+ }
+
+ @Test
+ public void testPropsOverride() throws Exception {
+ Properties startProps = new Properties();
+ startProps.setProperty(PROP_KEY, "true");
+ System.setProperty(PROP_KEY, "false");
+ // make sure the system property does NOT override what's already in the bag. We should get an empty bag back
+ Properties props = WinkSystemProperties.loadSystemProperties(startProps);
+ assertTrue("expected empty properties bag", props.isEmpty());
+ }
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProviderTest.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProviderTest.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProviderTest.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.entity.xml;
+
+import java.io.ByteArrayInputStream;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.wink.common.RuntimeContext;
+import org.apache.wink.common.internal.WinkConfiguration;
+import org.apache.wink.common.internal.runtime.RuntimeContextTLS;
+import org.jmock.Expectations;
+import org.jmock.integration.junit3.MockObjectTestCase;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * this test class is relatively new compared to the various
+ * XML provider tests here in wink-common and wink-server.
+ * Hence there are not as many tests as you might expect. I'm
+ * confident in the amount of testing being done in other places.
+ *
+ */
+public class AbstractJAXBProviderTest extends MockObjectTestCase {
+
+ /*
+ * this test class is relatively new compared to the various
+ * XML provider tests here in wink-common and wink-server.
+ * Hence there are not as many tests as you might expect. I'm
+ * confident in the amount of testing being done in other places.
+ */
+
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlRootElement(name = "message")
+ public static class Message {
+
+ protected String arg0;
+
+ /**
+ * Gets the value of the arg0 property.
+ *
+ */
+ public String getArg0() {
+ return arg0;
+ }
+
+ /**
+ * Sets the value of the arg0 property.
+ *
+ */
+ public void setArg0(String value) {
+ this.arg0 = value;
+ }
+
+ }
+
+ static String TEST_CLASSES_PATH = null;
+ static {
+ String classpath = System.getProperty("java.class.path");
+ StringTokenizer tokenizer = new StringTokenizer(classpath, System.getProperty("path.separator"));
+ while (tokenizer.hasMoreTokens()) {
+ TEST_CLASSES_PATH = tokenizer.nextToken();
+ if (TEST_CLASSES_PATH.endsWith("test-classes")) {
+ break;
+ }
+ }
+ // for windows:
+ int driveIndex = TEST_CLASSES_PATH.indexOf(":");
+ if(driveIndex != -1) {
+ TEST_CLASSES_PATH = TEST_CLASSES_PATH.substring(driveIndex + 1);
+ }
+ }
+
+ public WinkConfiguration winkConfiguration = null;
+
+ @Before
+ public void setUp() {
+ winkConfiguration = mock(WinkConfiguration.class);
+ final RuntimeContext runtimeContext = mock(RuntimeContext.class);
+ checking(new Expectations() {{
+ allowing(runtimeContext).getAttribute(WinkConfiguration.class); will(returnValue(winkConfiguration));
+ }});
+ RuntimeContextTLS.setRuntimeContext(runtimeContext);
+ }
+
+ @After
+ public void tearDown() {
+ // clean up the mess. :)
+ RuntimeContextTLS.setRuntimeContext(null);
+ }
+
+ public void testGetXMLStreamReader1() throws Exception {
+
+ final Properties props = new Properties();
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, empty document
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try {
+ AbstractJAXBProvider.getXMLStreamReader(bais);
+ fail("should have got an exception");
+ } catch (XMLStreamException e) {
+ // any other exception type will cause test failure
+ }
+ }
+
+ public void testGetXMLStreamReader2() throws Exception {
+
+ final Properties props = new Properties();
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, comment only
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><!-- comment -->";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try {
+ AbstractJAXBProvider.getXMLStreamReader(bais);
+ fail("should have got an exception");
+ } catch (XMLStreamException e) {
+ // any other exception type will cause test failure
+ }
+ }
+
+ public void testGetXMLStreamReader3() throws Exception {
+
+ final Properties props = new Properties();
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, whitespace and comment
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <!-- comment -->";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try {
+ AbstractJAXBProvider.getXMLStreamReader(bais);
+ fail("should have got an exception");
+ } catch (XMLStreamException e) {
+ // any other exception type will cause test failure
+ }
+ }
+
+ public void testGetXMLStreamReader4() throws Exception {
+
+ final Properties props = new Properties();
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, whitespace, comment, and whitespace
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <!-- comment --> ";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try {
+ AbstractJAXBProvider.getXMLStreamReader(bais);
+ fail("should have got an exception");
+ } catch (XMLStreamException e) {
+ // any other exception type will cause test failure
+ }
+ }
+
+ public void testGetXMLStreamReaderWithDTDUnsupported() throws Exception {
+
+ final Properties props = new Properties();
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, whitespace, comment, whitespace, and DOCTYPE unsupported
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <!-- comment --> " +
+ "<!DOCTYPE data [<!ENTITY file SYSTEM \"file:"+ TEST_CLASSES_PATH +"/etc/ProvidersJAXBTest.txt\">]>" +
+ "<message>&file;</message>";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ try {
+ AbstractJAXBProvider.getXMLStreamReader(bais);
+ fail("should have got an exception");
+ } catch (XMLStreamException e) {
+ // any other exception type will cause test failure
+ }
+ }
+
+ public void testGetXMLStreamReaderWithDTDSupported() throws Exception {
+
+ final Properties props = new Properties();
+ props.put("wink.supportDTDEntityExpansion", "true");
+ checking(new Expectations() {{
+ allowing(winkConfiguration).getProperties(); will(returnValue(props));
+ }});
+
+ // check for infinite loop, whitespace, comment, whitespace, and DOCTYPE supported
+ final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> <!-- comment --> " +
+ "<!DOCTYPE data [<!ENTITY file SYSTEM \"file:"+ TEST_CLASSES_PATH +"/etc/ProvidersJAXBTest.txt\">]>" +
+ "<message><arg0>&file;</arg0></message>";
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ XMLStreamReader reader = AbstractJAXBProvider.getXMLStreamReader(bais);
+ assertEquals("reader event should be start element", XMLStreamReader.START_ELEMENT, reader.getEventType());
+
+ JAXBContext context = JAXBContext.newInstance(Message.class);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ Message message = (Message)unmarshaller.unmarshal(reader);
+
+ assertEquals("message object should contain text from ProvidersJAXBTest.txt file", "99999999", message.getArg0().trim());
+ }
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/AbstractJAXBCollectionProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/AbstractJAXBCollectionProviderTest.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/AbstractJAXBCollectionProviderTest.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/AbstractJAXBCollectionProviderTest.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,261 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+package org.apache.wink.common.internal.providers.jaxb;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.ws.rs.core.GenericEntity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Providers;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.wink.common.RuntimeContext;
+import org.apache.wink.common.internal.WinkConfiguration;
+import org.apache.wink.common.internal.contexts.MediaTypeCharsetAdjuster;
+import org.apache.wink.common.internal.providers.entity.xml.JAXBCollectionXmlProvider;
+import org.apache.wink.common.internal.providers.jaxb.jaxb1.AddNumbers;
+import org.apache.wink.common.internal.providers.jaxb.jaxb1.MyPojo;
+import org.apache.wink.common.internal.runtime.RuntimeContextTLS;
+import org.apache.wink.common.model.JAXBUnmarshalOptions;
+import org.apache.wink.common.model.XmlFormattingOptions;
+import org.jmock.Expectations;
+import org.jmock.integration.junit3.MockObjectTestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.w3c.dom.Document;
+
+
+public class AbstractJAXBCollectionProviderTest extends MockObjectTestCase {
+
+ public class MyJAXBXmlProvider extends JAXBCollectionXmlProvider {
+
+ MyJAXBXmlProvider() {
+ super();
+ providers = AbstractJAXBCollectionProviderTest.this.providers;
+ }
+
+ /*
+ * simulate what would happen if application had supplied a JAXBContext provider
+ */
+ @Override
+ protected JAXBContext getContext(Class<?> type, MediaType mediaType)
+ throws JAXBException {
+ // use JAXBContext.newInstance(String). The default in AbstractJAXBProvider is JAXBContext.newInstance(Class)
+ return JAXBContext.newInstance(type.getPackage().getName());
+ }
+
+ }
+
+ static String path = null;
+ static {
+ String classpath = System.getProperty("java.class.path");
+ StringTokenizer tokenizer = new StringTokenizer(classpath, System.getProperty("path.separator"));
+ while (tokenizer.hasMoreTokens()) {
+ path = tokenizer.nextToken();
+ if (path.endsWith("test-classes")) {
+ break;
+ }
+ }
+ // for windows:
+ int driveIndex = path.indexOf(":");
+ if(driveIndex != -1) {
+ path = path.substring(driveIndex + 1);
+ }
+ }
+
+ static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<addNumberss>" +
+ "<ns2:addNumbers xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:arg0>1</ns2:arg0>" +
+ "<ns2:arg1>2</ns2:arg1>" +
+ "</ns2:addNumbers>" +
+ "<ns2:addNumbers xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:arg0>1</ns2:arg0>" +
+ "<ns2:arg1>3</ns2:arg1>" +
+ "</ns2:addNumbers>" +
+ "</addNumberss>";
+
+ static final String xmlMyPojo = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<myPojos>" +
+ "<ns2:myPojo xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:stringdata>1</ns2:stringdata>" +
+ "</ns2:myPojo>" +
+ "<ns2:myPojo xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:stringdata>2</ns2:stringdata>" +
+ "</ns2:myPojo>" +
+ "</myPojos>";
+
+ static final String xmlWithDTD = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<!DOCTYPE data [<!ENTITY file SYSTEM \"file:"+ path +"/etc/ProvidersJAXBTest.txt\">]>" +
+ "<addNumberss>" +
+ "<ns2:addNumbers xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:arg0>&file;</ns2:arg0>" +
+ "<ns2:arg1>2</ns2:arg1>" +
+ "</ns2:addNumbers>" +
+ "<ns2:addNumbers xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:arg0>&file;</ns2:arg0>" +
+ "<ns2:arg1>3</ns2:arg1>" +
+ "</ns2:addNumbers>" +
+ "</addNumberss>";
+
+ static final String xmlMyPojoWithDTD = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
+ "<!DOCTYPE data [<!ENTITY file SYSTEM \"file:"+ path +"/etc/ProvidersJAXBTest.txt\">]>" +
+ "<myPojos>" +
+ "<ns2:myPojo xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:stringdata>&file;</ns2:stringdata>" +
+ "</ns2:myPojo>" +
+ "<ns2:myPojo xmlns:ns2=\"http://org/apache/wink/common/internal/providers/jaxb/jaxb1\">" +
+ "<ns2:stringdata>&file;</ns2:stringdata>" +
+ "</ns2:myPojo>" +
+ "</myPojos>";
+
+ private MessageBodyReader jaxbProviderReader = null;
+ private MessageBodyWriter jaxbProviderWriter = null;
+ private Providers providers;
+
+ public class MyJAXBContextResolver implements ContextResolver<JAXBContext> {
+
+ public JAXBContext getContext(Class<?> arg0) {
+ try {
+ return JAXBContext.newInstance(arg0);
+ } catch (JAXBException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Before
+ public void setUp() {
+ providers = mock(Providers.class);
+ final RuntimeContext runtimeContext = mock(RuntimeContext.class);
+ final WinkConfiguration winkConfiguration = mock(WinkConfiguration.class);
+ checking(new Expectations() {{
+ allowing(providers).getContextResolver(JAXBContext.class, MediaType.TEXT_XML_TYPE); will(returnValue(new MyJAXBContextResolver()));
+ allowing(providers).getContextResolver(XmlFormattingOptions.class, MediaType.TEXT_XML_TYPE); will(returnValue(null));
+ allowing(providers).getContextResolver(JAXBUnmarshalOptions.class, MediaType.TEXT_XML_TYPE); will(returnValue(null));
+ allowing(runtimeContext).getAttribute(MediaTypeCharsetAdjuster.class); will(returnValue(null));
+ allowing(runtimeContext).getAttribute(WinkConfiguration.class); will(returnValue(winkConfiguration));
+ allowing(winkConfiguration).getProperties(); will(returnValue(null));
+ }});
+ RuntimeContextTLS.setRuntimeContext(runtimeContext);
+ jaxbProviderReader = new MyJAXBXmlProvider();
+ jaxbProviderWriter = new MyJAXBXmlProvider();
+
+ }
+
+ @After
+ public void tearDown() {
+ // clean up the mess.
+ RuntimeContextTLS.setRuntimeContext(null);
+ }
+
+ public void testXml() throws Exception {
+
+ GenericEntity<List<AddNumbers>> type1 =
+ new GenericEntity<List<AddNumbers>>(new ArrayList<AddNumbers>()) {
+ };
+
+ assertTrue(jaxbProviderReader.isReadable(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE));
+ ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
+ Object obj = jaxbProviderReader.readFrom(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE, null, bais);
+ assertTrue(obj instanceof ArrayList);
+ ArrayList alist = (ArrayList)obj;
+ // make sure the objects in the returned list are the actual jaxb objects, not JAXBElement, and the unmarshal worked:
+ assertEquals(1, ((AddNumbers)alist.get(0)).getArg0());
+ assertEquals(2, ((AddNumbers)alist.get(0)).getArg1());
+ assertEquals(1, ((AddNumbers)alist.get(1)).getArg0());
+ assertEquals(3, ((AddNumbers)alist.get(1)).getArg1());
+ }
+
+ public void testXmlWithDTD() throws Exception {
+
+ GenericEntity<List<AddNumbers>> type1 =
+ new GenericEntity<List<AddNumbers>>(new ArrayList<AddNumbers>()) {
+ };
+
+ assertTrue(jaxbProviderReader.isReadable(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE));
+ Exception ex = null;
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(xmlWithDTD.getBytes());
+ Object obj = jaxbProviderReader.readFrom(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE, null, bais);
+ fail("should have got an exception");
+ } catch (Exception e) {
+ ex = e;
+ }
+ assertTrue("expected an XMLStreamException", ex.getCause() instanceof XMLStreamException);
+
+ // parse it just as a sanity check to make sure our xml is good. No exceptions means good xml!
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document dom = db.parse(new ByteArrayInputStream(xmlWithDTD.getBytes()));
+
+ }
+
+ public void testXmlMyPojo() throws Exception {
+
+ GenericEntity<List<MyPojo>> type1 =
+ new GenericEntity<List<MyPojo>>(new ArrayList<MyPojo>()) {
+ };
+
+ assertTrue(jaxbProviderReader.isReadable(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE));
+ ByteArrayInputStream bais = new ByteArrayInputStream(xmlMyPojo.getBytes());
+ Object obj = jaxbProviderReader.readFrom(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE, null, bais);
+ assertTrue(obj instanceof ArrayList);
+ ArrayList alist = (ArrayList)obj;
+ // make sure the objects in the returned list are the actual jaxb objects, not JAXBElement, and the unmarshal worked:
+ assertEquals("1", ((MyPojo)alist.get(0)).getStringdata());
+ assertEquals("2", ((MyPojo)alist.get(1)).getStringdata());
+ }
+
+ public void testXmlMyPojoWithDTD() throws Exception {
+
+ GenericEntity<List<MyPojo>> type1 =
+ new GenericEntity<List<MyPojo>>(new ArrayList<MyPojo>()) {
+ };
+
+ assertTrue(jaxbProviderReader.isReadable(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE));
+ Exception ex = null;
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream(xmlMyPojoWithDTD.getBytes());
+ Object obj = jaxbProviderReader.readFrom(type1.getRawType(), type1.getType(), null, MediaType.TEXT_XML_TYPE, null, bais);
+ fail("should have got an exception");
+ } catch (Exception e) {
+ ex = e;
+ }
+ assertTrue("expected an XMLStreamException", ex.getCause() instanceof XMLStreamException);
+
+ // parse it just as a sanity check to make sure our xml is good. No exceptions means good xml!
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document dom = db.parse(new ByteArrayInputStream(xmlMyPojoWithDTD.getBytes()));
+
+ }
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/MyPojo.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/MyPojo.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/MyPojo.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/java/org/apache/wink/common/internal/providers/jaxb/jaxb1/MyPojo.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *******************************************************************************/
+
+package org.apache.wink.common.internal.providers.jaxb.jaxb1;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+// do NOT annotate with @XmlRootElement
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name="MyPojo", propOrder = {"stringdata"})
+public class MyPojo {
+ @XmlElement(required = true)
+ private String stringdata = null;
+ public MyPojo() {}
+ public void setStringdata(String stringdata) {
+ this.stringdata = stringdata;
+ }
+ public String getStringdata() {
+ return stringdata;
+ }
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/ProvidersJAXBTest.txt
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/ProvidersJAXBTest.txt?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/ProvidersJAXBTest.txt (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/ProvidersJAXBTest.txt Mon Jun 14 18:18:51 2010
@@ -0,0 +1 @@
+99999999
Added: incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/SourceProviderTest.txt
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/SourceProviderTest.txt?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/SourceProviderTest.txt (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-common/src/test/resources/etc/SourceProviderTest.txt Mon Jun 14 18:18:51 2010
@@ -0,0 +1 @@
+99999999
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/pom.xml?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/pom.xml (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/pom.xml Mon Jun 14 18:18:51 2010
@@ -0,0 +1,12 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>wink-itest</artifactId>
+ <groupId>org.apache.wink</groupId>
+ <version>1.1.1-incubating-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-itest-contentencode</artifactId>
+ <packaging>war</packaging>
+ <name>Apache Wink Integration Content Encoding Tests</name>
+</project>
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedApplication.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedApplication.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedApplication.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.itests.contentencode;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+public class ContentEncodedApplication extends Application {
+
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(ContentEncodedResource.class);
+ classes.add(RegularResource.class);
+ return classes;
+ }
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedResource.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedResource.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/ContentEncodedResource.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.itests.contentencode;
+
+import javax.ws.rs.Path;
+
+@Path("contentencode")
+public class ContentEncodedResource extends RegularResource {
+
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/RegularResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/RegularResource.java?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/RegularResource.java (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/java/org/apache/wink/itests/contentencode/RegularResource.java Mon Jun 14 18:18:51 2010
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.wink.itests.contentencode;
+
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Variant;
+import javax.ws.rs.core.Variant.VariantListBuilder;
+
+@Path("regular")
+public class RegularResource {
+
+ /**
+ * Simple resource that has a string repeated.
+ *
+ * @return
+ */
+ @GET
+ @Path("repeatedstring")
+ public String getRepeatedContent() {
+ StringBuilder sb = new StringBuilder();
+ for (int c = 0; c < 1000; ++c) {
+ sb.append("Hello world! ");
+ }
+ return sb.toString();
+ }
+
+ @POST
+ @Path("echo")
+ public String echoSomething(String entity) {
+ return entity;
+ }
+
+ /**
+ * Resource method will modify the Vary header with an Accept value.
+ *
+ * @return
+ */
+ @GET
+ @Path("varyheaderwithaccept")
+ public String getResourceWithVaryAccept(@Context Request request) {
+ List<Variant> variants =
+ VariantListBuilder.newInstance().mediaTypes(MediaType.TEXT_PLAIN_TYPE,
+ MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .add().build();
+ Variant bestVariant = request.selectVariant(variants);
+ return bestVariant.toString();
+ }
+
+ /**
+ * Resource method will modify the Vary header with an Accept-Encoding
+ * value.
+ *
+ * @return
+ */
+ @GET
+ @Path("varyheaderwithacceptencoding")
+ public String getResourceWithVaryAcceptEncoding(@Context Request request) {
+ List<Variant> variants =
+ VariantListBuilder.newInstance().mediaTypes(MediaType.TEXT_PLAIN_TYPE,
+ MediaType.APPLICATION_OCTET_STREAM_TYPE)
+ .encodings("gzip", "identity", "deflate").add().build();
+ Variant bestVariant = request.selectVariant(variants);
+ return bestVariant.toString();
+ }
+
+ /**
+ * Resource method will modify the Vary header with an Accept-Encoding value
+ * added by the user.
+ *
+ * @return
+ */
+ @GET
+ @Path("varyheaderwithacceptencodingbyuser")
+ public Response getResourceWithVaryAcceptEncodingByUser() {
+ return Response.ok("text/plain content").header("vary",
+ HttpHeaders.ACCEPT_CHARSET + ","
+ + HttpHeaders.ACCEPT_ENCODING
+ .toLowerCase()
+ + " , "
+ + HttpHeaders.ACCEPT).build();
+ }
+
+ /**
+ * Resource that will return the HTTP header Content-Encoding values.
+ *
+ * @return
+ */
+ @POST
+ @Path("httpheadercontentencoding")
+ public Response getResourceHttpHeaderValues(String entity,
+ @Context HttpHeaders httpHeaders,
+ @Context HttpServletRequest servletRequest) {
+ Enumeration headerNames = servletRequest.getHeaderNames();
+ boolean isContentEncodingHeaderPresent = false;
+ while (headerNames.hasMoreElements()) {
+ if (HttpHeaders.CONTENT_ENCODING.equalsIgnoreCase((String)headerNames.nextElement())) {
+ isContentEncodingHeaderPresent = true;
+ }
+ }
+ return Response.ok(httpHeaders.getRequestHeader(HttpHeaders.CONTENT_ENCODING) + ":"
+ + servletRequest.getHeader(HttpHeaders.CONTENT_ENCODING)
+ + ":"
+ + servletRequest.getHeaders(HttpHeaders.CONTENT_ENCODING).hasMoreElements()
+ + ":"
+ + isContentEncodingHeaderPresent).build();
+ }
+}
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/geronimo-web.xml?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/geronimo-web.xml (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/geronimo-web.xml Mon Jun 14 18:18:51 2010
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
+ xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
+ xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
+
+ <sys:environment>
+ <sys:moduleId>
+ <sys:groupId>${groupId}</sys:groupId>
+ <sys:artifactId>${artifactId}</sys:artifactId>
+ <sys:version>${version}</sys:version>
+ <sys:type>war</sys:type>
+ </sys:moduleId>
+ </sys:environment>
+
+ <gbean name="DirectoryLog4jConfiguration"
+ class="org.apache.geronimo.system.logging.log4j.ApplicationLog4jConfigurationGBean">
+ <attribute name="log4jResource">META-INF/log4j.properties</attribute>
+ </gbean>
+
+ <context-root>${artifactId}</context-root>
+</web-app>
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.filter.xml
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.filter.xml?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.filter.xml (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.filter.xml Mon Jun 14 18:18:51 2010
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+ <filter>
+ <filter-name>ContentEncoderRequestFilter</filter-name>
+ <filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingRequestFilter</filter-class>
+ </filter>
+ <filter>
+ <filter-name>ContentEncoderResponseFilter</filter-name>
+ <filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingResponseFilter</filter-class>
+ </filter>
+ <filter>
+ <filter-name>ContentEncoded</filter-name>
+ <filter-class>${wink.rest.filter}</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itests.contentencode.ContentEncodedApplication</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>ContentEncoderRequestFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>ContentEncoderResponseFilter</filter-name>
+ <url-pattern>/contentencode/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>ContentEncoded</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
Added: incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.servlet.xml
URL: http://svn.apache.org/viewvc/incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.servlet.xml?rev=954578&view=auto
==============================================================================
--- incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.servlet.xml (added)
+++ incubator/wink/branches/wink-1.1-incubating/wink-itests/wink-itest/wink-itest-contentencode/src/main/webapp/WEB-INF/web.servlet.xml Mon Jun 14 18:18:51 2010
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or
+ more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information regarding
+ copyright ownership. The ASF licenses this file to you under the
+ Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain
+ a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed
+ under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions
+ and limitations under the License.
+ -->
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+<web-app>
+ <display-name>Archetype Created Web Application</display-name>
+
+ <filter>
+ <filter-name>ContentEncoderRequestFilter</filter-name>
+ <filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingRequestFilter</filter-class>
+ </filter>
+ <filter>
+ <filter-name>ContentEncoderResponseFilter</filter-name>
+ <filter-class>org.apache.wink.server.internal.servlet.contentencode.ContentEncodingResponseFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>ContentEncoderRequestFilter</filter-name>
+ <url-pattern>/rest/contentencode/*</url-pattern>
+ </filter-mapping>
+ <filter-mapping>
+ <filter-name>ContentEncoderResponseFilter</filter-name>
+ <url-pattern>/rest/contentencode/*</url-pattern>
+ </filter-mapping>
+ <servlet>
+ <servlet-name>ContentEncoded</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itests.contentencode.ContentEncodedApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>ContentEncoded</servlet-name>
+ <url-pattern>/rest/*</url-pattern>
+ </servlet-mapping>
+</web-app>