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/10/28 16:07:38 UTC
svn commit: r830568 - in /incubator/wink/trunk:
wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/
wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/
Author: bluk
Date: Wed Oct 28 15:07:38 2009
New Revision: 830568
URL: http://svn.apache.org/viewvc?rev=830568&view=rev
Log:
Be more lenient in isJAXBElement
See [WINK-221]
Added:
incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/AtomEntryInResponseProviderTest.java
Modified:
incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java?rev=830568&r1=830567&r2=830568&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/xml/AbstractJAXBProvider.java Wed Oct 28 15:07:38 2009
@@ -20,7 +20,6 @@
package org.apache.wink.common.internal.providers.entity.xml;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.ws.rs.WebApplicationException;
@@ -121,7 +120,7 @@
}
public static boolean isJAXBElement(Class<?> type, Type genericType) {
- return (type == JAXBElement.class && genericType instanceof ParameterizedType);
+ return (type == JAXBElement.class);
}
private JAXBContext getContext(Class<?> type, MediaType mediaType) throws JAXBException {
Added: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/AtomEntryInResponseProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/AtomEntryInResponseProviderTest.java?rev=830568&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/AtomEntryInResponseProviderTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/providers/entity/AtomEntryInResponseProviderTest.java Wed Oct 28 15:07:38 2009
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * 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.server.internal.providers.entity;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBElement;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.wink.common.model.atom.AtomEntry;
+import org.apache.wink.common.model.synd.SyndEntry;
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.apache.wink.test.mock.TestUtils;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+public class AtomEntryInResponseProviderTest extends MockServletInvocationTest {
+
+ @Override
+ protected Class<?>[] getClasses() {
+ return new Class<?>[] {TestResource.class};
+ }
+
+ @Path("test")
+ public static class TestResource {
+
+ @GET
+ @Path("atomentry")
+ @Produces("application/atom+xml")
+ public Response getAtomEntry() throws IOException {
+ AtomEntry entry = AtomEntry.unmarshal(new StringReader(ENTRY));
+ return Response.ok(entry).build();
+ }
+
+ @GET
+ @Path("atomentryelement")
+ @Produces("application/atom+xml")
+ public Response getAtomEntryElement() throws IOException {
+ AtomEntry entry = AtomEntry.unmarshal(new StringReader(ENTRY));
+ org.apache.wink.common.model.atom.ObjectFactory of =
+ new org.apache.wink.common.model.atom.ObjectFactory();
+ return Response.ok(of.createEntry(entry)).build();
+ }
+
+ @GET
+ @Path("atomsyndentry")
+ @Produces("application/atom+xml")
+ public Response getSyndEntry() throws IOException {
+ AtomEntry entry = AtomEntry.unmarshal(new StringReader(ENTRY));
+ return Response.ok(entry.toSynd(new SyndEntry())).build();
+ }
+
+ @POST
+ @Path("atomentry")
+ @Produces("application/atom+xml")
+ @Consumes("application/atom+xml")
+ public Response postAtomEntry(AtomEntry entry) {
+ return Response.ok(entry).build();
+ }
+
+ @POST
+ @Path("atomentryelement")
+ @Produces("application/atom+xml")
+ @Consumes("application/atom+xml")
+ public Response postAtomEntryElement(JAXBElement<AtomEntry> entry) {
+ return Response.ok(entry).build();
+ }
+
+ @POST
+ @Path("atomsyndentry")
+ @Produces("application/atom+xml")
+ @Consumes("application/atom+xml")
+ public Response postAtomSyndEntry(SyndEntry entry) {
+ return Response.ok(entry).build();
+ }
+
+ }
+
+ public void testGetAtomEntry() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("GET",
+ "/test/atomentry",
+ "application/atom+xml");
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ public void testGetAtomEntryElement() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("GET",
+ "/test/atomentryelement",
+ "application/atom+xml");
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ public void testGetAtomSyndEntry() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("GET",
+ "/test/atomsyndentry",
+ "application/atom+xml");
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ public void testPostAtomEntry() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("POST",
+ "/test/atomentry",
+ "application/atom+xml");
+ request.setContentType("application/atom+xml");
+ request.setContent(ENTRY.getBytes());
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ public void testPostAtomEntryElement() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("POST",
+ "/test/atomentryelement",
+ "application/atom+xml");
+ request.setContentType("application/atom+xml");
+ request.setContent(ENTRY.getBytes());
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ public void testPostAtomSyndEntry() throws Exception {
+ MockHttpServletRequest request =
+ MockRequestConstructor.constructMockRequest("POST",
+ "/test/atomsyndentry",
+ "application/atom+xml");
+ request.setContentType("application/atom+xml");
+ request.setContent(ENTRY.getBytes());
+ MockHttpServletResponse response = invoke(request);
+ assertEquals(200, response.getStatus());
+ String msg =
+ TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString());
+ assertNull(msg, msg);
+ }
+
+ private static final String ENTRY_STR =
+ "<entry xml:base=\"http://b216:8080/reporting/reports\" xmlns=\"http://www.w3.org/2005/Atom\">" + "<id>toptenvalidators</id>"
+ + "<updated>@TIME@</updated>"
+ + "<title type=\"text\" xml:lang=\"en\">top ten validators</title>"
+ + "<published>@TIME@</published>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/json\" type=\"application/json\" rel=\"alternate\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=text/plain\" type=\"text/plain\" rel=\"alternate\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators\" rel=\"self\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=text/xml\" type=\"text/xml\" rel=\"alternate\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators/documents/\" type=\"application/atom+xml\" rel=\"execute\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators\" type=\"application/atom+xml\" rel=\"edit\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators?alt=application/xml\" type=\"application/xml\" rel=\"alternate\"/>"
+ + "<link href=\"http://b216:8080/reporting/reports/toptenvalidators\" type=\"application/xml\" rel=\"edit-media\"/>"
+ + "<author>"
+ + "<name>admin</name>"
+ + "</author>"
+ + "<category label=\"report definition\" scheme=\"urn:com:systinet:reporting:kind\" term=\"urn:com:systinet:reporting:kind:definition\"/>"
+ + "<category label=\"Policy Manager - Homepage Report\" scheme=\"urn:com:systinet:policymgr:report:type\" term=\"aoi\"/>"
+ + "</entry>\n";
+
+ private static final String ENTRY;
+
+ static {
+ try {
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.setTimeInMillis((new Date()).getTime());
+ XMLGregorianCalendar xmlGregCal =
+ DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
+ ENTRY = ENTRY_STR.replace("@TIME@", xmlGregCal.toXMLFormat());
+ } catch (DatatypeConfigurationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}