Author: sergeyb
Date: Mon Jan 11 09:31:09 2010
New Revision: 897812
URL: http://svn.apache.org/viewvc?rev=897812&view=rev
Log:
JAXRS support for reading Document and fixes to do with updating destinations
when request URIs are equal to endpoint addresses
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
(with props)
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
(with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractSpringServer.java
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
Mon Jan 11 09:31:09 2010
@@ -58,13 +58,18 @@
}
public boolean isReadable(Class<?> type, Type genericType, Annotation[]
annotations, MediaType mt) {
- return Source.class.isAssignableFrom(type) ||
XMLSource.class.isAssignableFrom(type);
+ return Source.class.isAssignableFrom(type)
+ || XMLSource.class.isAssignableFrom(type)
+ || Document.class.isAssignableFrom(type);
}
public Object readFrom(Class<Object> source, Type genericType,
Annotation[] annotations, MediaType m,
MultivaluedMap<String, String> headers, InputStream is)
throws IOException {
- if (DOMSource.class.isAssignableFrom(source)) {
+ if (DOMSource.class.isAssignableFrom(source) ||
Document.class.isAssignableFrom(source)) {
+
+ boolean docRequired = Document.class.isAssignableFrom(source);
+
Document doc = null;
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
@@ -77,7 +82,7 @@
throw ioex;
}
- return new DOMSource(doc);
+ return docRequired ? doc : new DOMSource(doc);
} else if (StreamSource.class.isAssignableFrom(source)
|| Source.class.isAssignableFrom(source)) {
return new StreamSource(is);
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
Mon Jan 11 09:31:09 2010
@@ -193,6 +193,10 @@
public static String getPathToMatch(String path, String address, boolean
addSlash) {
int ind = path.indexOf(address);
+ if (ind == -1 && address.equals(path + "/")) {
+ path += "/";
+ ind = 0;
+ }
if (ind == 0) {
path = path.substring(ind + address.length());
}
Modified:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/SourceProviderTest.java
Mon Jan 11 09:31:09 2010
@@ -29,6 +29,8 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
+import org.w3c.dom.Document;
+
import org.junit.Assert;
import org.junit.Test;
@@ -57,6 +59,7 @@
assertSame(StreamSource.class, verifyRead(p,
StreamSource.class).getClass());
assertSame(StreamSource.class, verifyRead(p, Source.class).getClass());
assertSame(DOMSource.class, verifyRead(p, DOMSource.class).getClass());
+ assertTrue(Document.class.isAssignableFrom(verifyRead(p,
Document.class).getClass()));
}
@Test
Modified:
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Mon Jan 11 09:31:09 2010
@@ -76,6 +76,7 @@
public void testPathToMatch() {
assertEquals("/", HttpUtils.getPathToMatch("/", "/", true));
assertEquals("/", HttpUtils.getPathToMatch("/", "/bar", true));
+ assertEquals("/", HttpUtils.getPathToMatch("/bar", "/bar/", true));
assertEquals("/bar", HttpUtils.getPathToMatch("/bar", "/", true));
assertEquals("/", HttpUtils.getPathToMatch("/bar", "/bar", true));
Modified:
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
(original)
+++
cxf/trunk/rt/transports/http-osgi/src/main/java/org/apache/cxf/transport/http_osgi/OsgiServletController.java
Mon Jan 11 09:31:09 2010
@@ -54,7 +54,7 @@
public class OsgiServletController extends AbstractServletController {
private static final Logger LOG = LogUtils.getL7dLogger(OsgiServlet.class);
- private String lastBase = "";
+ private volatile String lastBase = "";
private OsgiServlet servlet;
public OsgiServletController(OsgiServlet servlet) {
super(servlet.getServletConfig());
@@ -67,9 +67,10 @@
}
String base = forcedBaseAddress == null ? getBaseURL(request) :
forcedBaseAddress;
- //if (base.equals(lastBase)) {
- // return;
- //}
+ if (base.equals(lastBase)) {
+ return;
+ }
+
Set<String> paths = servlet.getTransport().getDestinationsPaths();
for (String path : paths) {
OsgiDestination d2 =
servlet.getTransport().getDestinationForPath(path);
@@ -144,7 +145,9 @@
}
}
}
- }
+ } else if ("/".equals(address) || address.length() == 0) {
+ updateDests(request);
+ }
invokeDestination(request, res, d);
}
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
(original)
+++
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
Mon Jan 11 09:31:09 2010
@@ -55,7 +55,7 @@
private ServletContext servletContext;
private ServletConfig servletConfig;
private Bus bus;
- private String lastBase = "";
+ private volatile String lastBase = "";
public ServletController(ServletTransportFactory df,
ServletConfig config,
@@ -141,7 +141,9 @@
}
} else {
ei = d.getEndpointInfo();
- if (null != request.getQueryString()
+
+ if ("GET".equals(request.getMethod())
+ && null != request.getQueryString()
&& request.getQueryString().length() > 0
&& bus.getExtension(QueryHandlerRegistry.class) != null) {
@@ -149,10 +151,8 @@
String baseUri = request.getRequestURL().toString()
+ "?" + request.getQueryString();
// update the EndPoint Address with request url
- if ("GET".equals(request.getMethod())) {
- updateDests(request);
- }
-
+ updateDests(request);
+
for (QueryHandler qh :
bus.getExtension(QueryHandlerRegistry.class).getHandlers()) {
if (qh.isRecognizedQuery(baseUri, ctxUri, ei)) {
@@ -171,6 +171,8 @@
return;
}
}
+ } else if ("/".equals(address) || address.length() == 0) {
+ updateDests(request);
}
invokeDestination(request, res, d);
Modified:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractSpringServer.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractSpringServer.java?rev=897812&r1=897811&r2=897812&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractSpringServer.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractSpringServer.java
Mon Jan 11 09:31:09 2010
@@ -47,7 +47,7 @@
protected AbstractSpringServer(String path, String cPath, int portNumber) {
resourcePath = path;
- contextPath = "/";
+ contextPath = cPath;
port = portNumber;
}
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java?rev=897812&view=auto
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
(added)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
Mon Jan 11 09:31:09 2010
@@ -0,0 +1,102 @@
+/**
+ * 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.cxf.systest.jaxrs;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSUriInfoTest extends AbstractClientServerTestBase {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // must be 'in-process' to communicate with inner class in single JVM
+ // and to spawn class SpringServer w/o using main() method
+ launchServer(SpringServer.class, true);
+ }
+
+ @Ignore
+ public static class SpringServer extends AbstractSpringServer {
+ public SpringServer() {
+ super("/jaxrs_uriinfo", "/app", 9080);
+ }
+ }
+
+ /**
+ * URI | getBaseUri | path param
+-------------+---------------------+-----------
+/app/v1 | http://host/ | "v1"
+/app/v1/ | http://host/ | "v1/"
+/app/v1/test | http://host/app/v1/ | "test"
+/app/v1/ | http://host/app/v1/ | ""
+/app/v1 | http://host/app/v1/ | "app/v1"
+ * @throws Exception
+ */
+ @Test
+ public void testBasePathAndPathAndPathParam() throws Exception {
+ checkUriInfo("http://localhost:9080/app/v1", "\"\"", "/");
+ checkUriInfo("http://localhost:9080/app/v1/", "\"\"", "/");
+ checkUriInfo("http://localhost:9080/app/v1/test", "\"test\"", "/test");
+ checkUriInfo("http://localhost:9080/app/v1/", "\"\"", "/");
+ checkUriInfo("http://localhost:9080/app/v1", "\"\"", "/");
+
+ checkUriInfo("http://localhost:9080/app/v1/bar", "\"bar\"", "/bar");
+ checkUriInfo("http://localhost:9080/app/v1/bar", "\"bar\"", "/bar");
+ checkUriInfo("http://localhost:9080/app/v1/bar/test", "\"bar/test\"",
"/bar/test");
+ checkUriInfo("http://localhost:9080/app/v1/bar", "\"bar\"", "/bar");
+ checkUriInfo("http://localhost:9080/app/v1/bar", "\"bar\"", "/bar");
+ }
+
+ private void checkUriInfo(String address, String path, String pathParam) {
+ WebClient wc = WebClient.create(address);
+ wc.accept("text/plain");
+ String data = wc.get(String.class);
+ assertEquals("http://localhost:9080/app/v1/," + path + "," +
pathParam, data);
+ }
+
+ @Ignore
+ @Path("/")
+ public static class Resource {
+
+ @Context
+ private UriInfo uriInfo;
+
+ @GET
+ @Path("/{path:.*}")
+ @Produces("text/plain")
+ public String getBasePathAndPathParam(@PathParam("path") String path) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(uriInfo.getBaseUri());
+ sb.append(",\"" + path + "\"");
+ sb.append("," + uriInfo.getPath());
+ return sb.toString();
+ }
+
+ }
+}
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml?rev=897812&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
(added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
Mon Jan 11 09:31:09 2010
@@ -0,0 +1,49 @@
+<?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.
+ -->
+ <!-- START SNIPPET: beans -->
+ <!--
+ beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:simple="http://cxf.apache.org/simple" xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/simple
http://cxf.apache.org/schemas/simple.xsd"
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+http://www.springframework.org/schema/beans
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxrs
+http://cxf.apache.org/schemas/jaxrs.xsd
+http://www.springframework.org/schema/util
+http://www.springframework.org/schema/util/spring-util-2.0.xsd">
+
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import
resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+
+ <jaxrs:server address="/">
+ <jaxrs:serviceBeans>
+ <bean
class="org.apache.cxf.systest.jaxrs.JAXRSUriInfoTest$Resource"/>
+ </jaxrs:serviceBeans>
+ </jaxrs:server>
+
+</beans>
+ <!-- END SNIPPET: beans -->
+
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/beans.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml?rev=897812&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
(added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
Mon Jan 11 09:31:09 2010
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--
+ 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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>WEB-INF/beans.xml</param-value>
+ </context-param>
+
+ <listener>
+ <listener-class>
+ org.springframework.web.context.ContextLoaderListener
+ </listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>CXFServlet</servlet-name>
+ <display-name>CXF Servlet</display-name>
+ <servlet-class>
+ org.apache.cxf.transport.servlet.CXFServlet
+ </servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>CXFServlet</servlet-name>
+ <url-pattern>/v1/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+<!-- END SNIPPET: webxml -->
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml