You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/09/08 22:40:51 UTC
svn commit: r812684 - in /incubator/wink/trunk/wink-itests/wink-itest: ./
wink-itest-client/ wink-itest-client/src/ wink-itest-client/src/main/
wink-itest-client/src/main/java/ wink-itest-client/src/main/java/org/
wink-itest-client/src/main/java/org/ap...
Author: bluk
Date: Tue Sep 8 20:40:50 2009
New Revision: 812684
URL: http://svn.apache.org/viewvc?rev=812684&view=rev
Log:
Add integration test for wink client Accept header
See [WINK-162]
Added:
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java (with props)
incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java (with props)
Modified:
incubator/wink/trunk/wink-itests/wink-itest/pom.xml
Modified: incubator/wink/trunk/wink-itests/wink-itest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/pom.xml?rev=812684&r1=812683&r2=812684&view=diff
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/pom.xml (original)
+++ incubator/wink/trunk/wink-itests/wink-itest/pom.xml Tue Sep 8 20:40:50 2009
@@ -37,6 +37,7 @@
<module>wink-itest-validation</module>
<module>wink-itest-extra-providers</module>
<module>wink-itest-filter</module>
+ <module>wink-itest-client</module>
</modules>
<properties>
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml Tue Sep 8 20:40:50 2009
@@ -0,0 +1,32 @@
+<?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.
+-->
+<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">
+ <parent>
+ <artifactId>wink-itest</artifactId>
+ <groupId>org.apache.wink</groupId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.wink</groupId>
+ <artifactId>wink-itest-client</artifactId>
+ <packaging>war</packaging>
+ <name>Apache Wink Integration Test Client</name>
+</project>
\ No newline at end of file
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.itest.client.jaxb;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class Echo {
+
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/Echo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.itest.client.jaxb;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+@XmlRegistry
+public class ObjectFactory {
+
+ public Echo createPerson() {
+ return new Echo();
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/client/jaxb/ObjectFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.itest.echoapp;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+
+
+public class EchoApplication extends Application {
+
+ @Override
+ public Set<Class<?>> getClasses() {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ classes.add(EchoResource.class);
+ return classes;
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoApplication.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,79 @@
+/*
+ * 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.itest.echoapp;
+
+import java.util.List;
+
+import javax.ws.rs.GET;
+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;
+
+import org.apache.wink.itest.client.jaxb.Echo;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+@Path("/echoaccept")
+public class EchoResource {
+
+ @Context
+ HttpHeaders requestHeaders;
+
+ @GET
+ public Response getAcceptHeaderEcho(@Context Request request) throws JSONException {
+ StringBuffer sb = new StringBuffer("echo: ");
+ List<String> acceptHeader = requestHeaders.getRequestHeader(HttpHeaders.ACCEPT);
+
+ if (acceptHeader != null) {
+ for (String s : acceptHeader) {
+ sb.append(s);
+ }
+ }
+
+ if (acceptHeader == null || acceptHeader.isEmpty()
+ || MediaType.WILDCARD_TYPE.equals(requestHeaders.getAcceptableMediaTypes().get(0))) {
+ return Response.ok(sb.toString()).type(MediaType.TEXT_PLAIN_TYPE).build();
+ }
+
+ Variant variant =
+ request.selectVariant(VariantListBuilder.newInstance()
+ .mediaTypes(MediaType.TEXT_PLAIN_TYPE,
+ MediaType.TEXT_XML_TYPE,
+ MediaType.APPLICATION_JSON_TYPE).add().build());
+ if (variant != null) {
+ if (MediaType.APPLICATION_JSON_TYPE.isCompatible(variant.getMediaType())) {
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("value", sb.toString());
+ return Response.ok(jsonObject).build();
+ } else if (MediaType.TEXT_XML_TYPE.isCompatible(variant.getMediaType())) {
+ Echo e = new Echo();
+ e.setValue(sb.toString());
+ return Response.ok(e).build();
+ }
+ }
+
+ return Response.ok(sb.toString()).type(MediaType.TEXT_PLAIN_TYPE).build();
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/java/org/apache/wink/itest/echoapp/EchoResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml Tue Sep 8 20:40:50 2009
@@ -0,0 +1,35 @@
+<?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>
+
+ <context-root>${artifactId}</context-root>
+</web-app>
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/geronimo-web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml Tue Sep 8 20:40:50 2009
@@ -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.
+-->
+
+<!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>EchoApplication</filter-name>
+ <filter-class>${wink.rest.filter}</filter-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.echoapp.EchoApplication</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>EchoApplication</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.filter.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml Tue Sep 8 20:40:50 2009
@@ -0,0 +1,40 @@
+<?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>
+ <servlet>
+ <servlet-name>EchoApplication</servlet-name>
+ <servlet-class>${wink.rest.servlet}</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.apache.wink.itest.echoapp.EchoApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>EchoApplication</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/main/webapp/WEB-INF/web.servlet.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.itest.client;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.RestClient;
+
+/**
+ * Tests the Accept Header Handler. Repeats the {@link AcceptHeaderHandlerTest}
+ * but with the Apache HTTP core client instead.
+ */
+public class AcceptHeaderHandlerApacheHTTPCoreTest extends AcceptHeaderHandlerTest {
+
+ public void setUp() throws Exception {
+ super.setUp();
+ client = new RestClient(new ApacheHttpClientConfig());
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerApacheHTTPCoreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,135 @@
+/*
+ * 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.itest.client;
+
+import java.io.StringReader;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.client.internal.handlers.AcceptHeaderHandler;
+import org.apache.wink.itest.client.jaxb.Echo;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+/**
+ * Tests the Accept Header Handler. The {@link AcceptHeaderHandler}
+ * automatically sets the Accept header if it is not already set by the client.
+ */
+public class AcceptHeaderHandlerTest extends TestCase {
+
+ public static String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI();
+ }
+
+ RestClient client = null;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ client = new RestClient();
+ }
+
+ /**
+ * If the Accept header is already set, then the Accept Header handler
+ * should not attempt to set it. This is particularly useful for types like
+ * String which would do MediaType.WILDCARD.
+ *
+ * @throws JSONException
+ * @throws JAXBException
+ */
+ public void testAcceptHeaderSet() throws JSONException, JAXBException {
+ String s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_JSON_TYPE)
+ .get(String.class);
+ JSONObject j = new JSONObject(new JSONTokener(s));
+ assertEquals("echo: " + MediaType.APPLICATION_JSON, j.get("value"));
+
+ s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.TEXT_XML)
+ .get(String.class);
+ Echo e =
+ (Echo)JAXBContext.newInstance(Echo.class).createUnmarshaller()
+ .unmarshal(new StringReader(s));
+ assertEquals(e.getValue(), "echo: " + MediaType.TEXT_XML);
+
+ /*
+ * this is actually a trick to make sure that plain text is returned.
+ * the server side piece does not produce APPLICATION_XML but will
+ * produce TEXT_PLAIN for any non-produced type. it really should return
+ * 415 status code.
+ */
+ s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_XML)
+ .get(String.class);
+ assertEquals("echo: " + MediaType.APPLICATION_XML, s);
+ }
+
+ /**
+ * If the Accept header is not set, then let the {@link AcceptHeaderHandler}
+ * set it automatically.
+ */
+ public void testAcceptHeaderNotSetString() {
+ String s = client.resource(getBaseURI() + "/echoaccept").get(String.class);
+ assertEquals("echo: " + MediaType.WILDCARD, s);
+ }
+
+ /**
+ * If no entity class is specified in the initial GET, then the
+ * {@link AcceptHeaderHandler} should not set anything. However, the
+ * underlying client may set the header as a failsafe.
+ */
+ public void testAcceptHeaderNoEntity() {
+ RestClient client = new RestClient();
+ ClientResponse resp = client.resource(getBaseURI() + "/echoaccept").get();
+ /*
+ * in this case the underlying client set the WILDCARD header for
+ * default HttpURLConnection based client.
+ */
+ assertEquals("echo: " + MediaType.WILDCARD, resp.getEntity(String.class));
+ }
+
+ /**
+ * For JAXB objects, the {@link AcceptHeaderHandler} should automatically
+ * take care of the Accept header.
+ */
+ public void testAcceptHeaderForJAXB() {
+ Echo p = client.resource(getBaseURI() + "/echoaccept").get(Echo.class);
+ assertTrue(p.getValue().contains(MediaType.TEXT_XML) && p.getValue()
+ .contains(MediaType.APPLICATION_XML));
+ }
+
+ /**
+ * For JSON objects, the {@link AcceptHeaderHandler} should automatically
+ * take care of the Accept header.
+ */
+ public void testAcceptHeaderForJSON() throws JSONException {
+ JSONObject j = client.resource(getBaseURI() + "/echoaccept").get(JSONObject.class);
+ String v = j.getString("value");
+ assertTrue(v.contains(MediaType.APPLICATION_JSON) && v.contains("application/javascript"));
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/AcceptHeaderHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.itest.client;
+
+import org.apache.wink.client.ApacheHttpClientConfig;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.client.internal.handlers.AcceptHeaderHandler;
+
+public class NoAcceptHeaderHandlerApacheHTTPCoreTest extends NoAcceptHeaderHandlerTest {
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ client = new RestClient(new ApacheHttpClientConfig().acceptHeaderAutoSet(false));
+ }
+
+ /**
+ * If the Accept header is not set, then let the client set a default to
+ * send. In RestClient with Apache HTTP core, it is set to nothing.
+ */
+ @Override
+ public void testAcceptHeaderNotSetString() {
+ String s = client.resource(getBaseURI() + "/echoaccept").get(String.class);
+ assertEquals("echo: ", s);
+ }
+
+ /**
+ * If no entity class is specified in the initial GET, then the
+ * {@link AcceptHeaderHandler} should not set anything. However, the
+ * underlying client may set the header as a failsafe.
+ */
+ @Override
+ public void testAcceptHeaderNoEntity() {
+ ClientResponse resp = client.resource(getBaseURI() + "/echoaccept").get();
+ /*
+ * in this case the underlying client does not set an Accept header at all
+ */
+ assertEquals("echo: ", resp.getEntity(String.class));
+ }
+
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerApacheHTTPCoreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java?rev=812684&view=auto
==============================================================================
--- incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java (added)
+++ incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java Tue Sep 8 20:40:50 2009
@@ -0,0 +1,148 @@
+/*
+ * 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.itest.client;
+
+import java.io.StringReader;
+
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import junit.framework.TestCase;
+
+import org.apache.wink.client.ClientConfig;
+import org.apache.wink.client.ClientResponse;
+import org.apache.wink.client.RestClient;
+import org.apache.wink.client.internal.handlers.AcceptHeaderHandler;
+import org.apache.wink.itest.client.jaxb.Echo;
+import org.apache.wink.test.integration.ServerEnvironmentInfo;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+/**
+ * Tests the Accept Header Handler is disabled when the appropriate client
+ * config option is set.
+ */
+public class NoAcceptHeaderHandlerTest extends TestCase {
+
+ public static String getBaseURI() {
+ return ServerEnvironmentInfo.getBaseURI();
+ }
+
+ RestClient client = null;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ client = new RestClient(new ClientConfig().acceptHeaderAutoSet(false));
+ }
+
+ /**
+ * If the Accept header is already set, then the Accept Header handler
+ * should not attempt to set it. This is particularly useful for types like
+ * String which would do MediaType.WILDCARD.
+ *
+ * @throws JSONException
+ * @throws JAXBException
+ */
+ public void testAcceptHeaderSet() throws JSONException, JAXBException {
+ String s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_JSON_TYPE)
+ .get(String.class);
+ JSONObject j = new JSONObject(new JSONTokener(s));
+ assertEquals("echo: " + MediaType.APPLICATION_JSON, j.get("value"));
+
+ s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.TEXT_XML)
+ .get(String.class);
+ Echo e =
+ (Echo)JAXBContext.newInstance(Echo.class).createUnmarshaller()
+ .unmarshal(new StringReader(s));
+ assertEquals(e.getValue(), "echo: " + MediaType.TEXT_XML);
+
+ /*
+ * this is actually a trick to make sure that plain text is returned.
+ * the server side piece does not produce APPLICATION_XML but will
+ * produce TEXT_PLAIN for any non-produced type. it really should return
+ * 415 status code.
+ */
+ s =
+ client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_XML)
+ .get(String.class);
+ assertEquals("echo: " + MediaType.APPLICATION_XML, s);
+ }
+
+ /**
+ * If the Accept header is not set, then let the client set a default to
+ * send. In regular RestClient, it is set to {@link MediaType.WILDCARD}
+ */
+ public void testAcceptHeaderNotSetString() {
+ String s = client.resource(getBaseURI() + "/echoaccept").get(String.class);
+ assertEquals("echo: " + MediaType.WILDCARD, s);
+ }
+
+ /**
+ * If no entity class is specified in the initial GET, then the
+ * {@link AcceptHeaderHandler} should not set anything. However, the
+ * underlying client may set the header as a failsafe.
+ *
+ * @throws JSONException
+ */
+ public void testAcceptHeaderNoEntity() {
+ ClientResponse resp = client.resource(getBaseURI() + "/echoaccept").get();
+ /*
+ * in this case the underlying client set the WILDCARD header for
+ * default HttpURLConnection based client.
+ */
+ assertEquals("echo: " + MediaType.WILDCARD, resp.getEntity(String.class));
+ }
+
+ /**
+ * For JAXB objects, there will be an error as the resource will return a
+ * text/plain representation.
+ */
+ public void testAcceptHeaderForJAXB() {
+ try {
+ client.resource(getBaseURI() + "/echoaccept").get(Echo.class);
+ fail();
+ } catch (RuntimeException e) {
+ assertEquals(e.getMessage(), String
+ .format("No reader for type class %s and media type %s",
+ Echo.class.getName(),
+ MediaType.TEXT_PLAIN));
+ }
+ }
+
+ /**
+ * For JSON objects, there will be an error as the resource will return a
+ * text/plain representation.
+ */
+ public void testAcceptHeaderForJSON() throws JSONException {
+ try {
+ client.resource(getBaseURI() + "/echoaccept").get(JSONObject.class);
+ fail();
+ } catch (RuntimeException e) {
+ assertEquals(e.getMessage(), String
+ .format("No reader for type class %s and media type %s",
+ JSONObject.class.getName(),
+ MediaType.TEXT_PLAIN));
+ }
+ }
+}
Propchange: incubator/wink/trunk/wink-itests/wink-itest/wink-itest-client/src/test/java/org/apache/wink/itest/client/NoAcceptHeaderHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native