Repository: cxf Updated Branches: refs/heads/master da963ab6e -> 307b3ed0a
Prototyping a NoOsgi JAX-RS Blueprint test Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/307b3ed0 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/307b3ed0 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/307b3ed0 Branch: refs/heads/master Commit: 307b3ed0a693ba4fb7e380e6604952ae39e5b44a Parents: da963ab Author: Sergey Beryozkin <[email protected]> Authored: Fri May 15 15:13:33 2015 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Fri May 15 15:13:33 2015 +0100 ---------------------------------------------------------------------- .../main/resources/schemas/blueprint/jaxrs.xsd | 2 +- systests/jaxrs/pom.xml | 12 +++ .../jaxrs/JAXRSBlueprintContextListener.java | 42 ++++++++ .../jaxrs/JAXRSUriInfoBlueprintTest.java | 103 +++++++++++++++++++ .../jaxrs_uriinfo_blueprint/WEB-INF/beans.xml | 41 ++++++++ .../jaxrs_uriinfo_blueprint/WEB-INF/web.xml | 45 ++++++++ 6 files changed, 244 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/rt/frontend/jaxrs/src/main/resources/schemas/blueprint/jaxrs.xsd ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/resources/schemas/blueprint/jaxrs.xsd b/rt/frontend/jaxrs/src/main/resources/schemas/blueprint/jaxrs.xsd index 74bc24f..749703a 100644 --- a/rt/frontend/jaxrs/src/main/resources/schemas/blueprint/jaxrs.xsd +++ b/rt/frontend/jaxrs/src/main/resources/schemas/blueprint/jaxrs.xsd @@ -29,7 +29,7 @@ <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0" schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"/> <xsd:import namespace="http://cxf.apache.org/configuration/beans" schemaLocation="http://cxf.apache.org/schemas/configuration/cxf-beans.xsd"/> - <xsd:include schemaLocation="jaxrs-common.xsd"/> + <xsd:include schemaLocation="http://cxf.apache.org/schemas/blueprint/jaxrs-common.xsd"/> <xsd:element name="server"> <xsd:complexType> http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/systests/jaxrs/pom.xml ---------------------------------------------------------------------- diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml index b41c3b5..91d1340 100644 --- a/systests/jaxrs/pom.xml +++ b/systests/jaxrs/pom.xml @@ -88,6 +88,18 @@ <version>${cxf.glassfish.el.version}</version> </dependency> <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>org.apache.aries.blueprint.web</artifactId> + <version>1.1.0</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.aries.blueprint</groupId> + <artifactId>org.apache.aries.blueprint.noosgi</artifactId> + <version>1.1.0</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.olingo</groupId> <artifactId>olingo-odata2-core</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSBlueprintContextListener.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSBlueprintContextListener.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSBlueprintContextListener.java new file mode 100644 index 0000000..8aa8889 --- /dev/null +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSBlueprintContextListener.java @@ -0,0 +1,42 @@ +/** + * 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 java.net.URI; + +import org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet; +import org.apache.aries.blueprint.parser.NamespaceHandlerSet; +import org.apache.aries.blueprint.web.BlueprintContextListener; +import org.apache.cxf.internal.CXFAPINamespaceHandler; +import org.apache.cxf.jaxrs.blueprint.JAXRSBPNamespaceHandler; + +public class JAXRSBlueprintContextListener extends BlueprintContextListener { + @Override + protected NamespaceHandlerSet getNamespaceHandlerSet(ClassLoader tccl) { + SimpleNamespaceHandlerSet set = new SimpleNamespaceHandlerSet(); + + set.addNamespace(URI.create("http://cxf.apache.org/blueprint/core"), + getClass().getResource("/schemas/blueprint/core.xsd"), + new CXFAPINamespaceHandler()); + set.addNamespace(URI.create("http://cxf.apache.org/blueprint/jaxrs"), + getClass().getResource("/schemas/blueprint/jaxrs.xsd"), + new JAXRSBPNamespaceHandler()); + return set; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoBlueprintTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoBlueprintTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoBlueprintTest.java new file mode 100644 index 0000000..3ff2e8f --- /dev/null +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoBlueprintTest.java @@ -0,0 +1,103 @@ +/** + * 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 JAXRSUriInfoBlueprintTest extends AbstractClientServerTestBase { + public static final int PORT = SpringServer.PORT; + @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 static final int PORT = allocatePortAsInt(SpringServer.class); + public SpringServer() { + super("/jaxrs_uriinfo_blueprint", "/bp", PORT); + } + } + + /** + * 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:" + PORT + "/bp/v1", "\"\"", "/"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/", "\"\"", "/"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/test", "\"test\"", "test"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/", "\"\"", "/"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1", "\"\"", "/"); + + checkUriInfo("http://localhost:" + PORT + "/bp/v1/bar", "\"bar\"", "bar"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/bar", "\"bar\"", "bar"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/bar/test", "\"bar/test\"", "bar/test"); + checkUriInfo("http://localhost:" + PORT + "/bp/v1/bar", "\"bar\"", "bar"); + checkUriInfo("http://localhost:" + PORT + "/bp/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:" + PORT + "/bp/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(); + } + + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/beans.xml ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/beans.xml new file mode 100644 index 0000000..dd056e2 --- /dev/null +++ b/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/beans.xml @@ -0,0 +1,41 @@ +<?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. +--> + +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs" + xmlns:cxf="http://cxf.apache.org/blueprint/core" + xsi:schemaLocation=" + http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd + http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd + http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd + "> + <!-- + NoOsi container does not find a 'cxf' component without ExtensionManagerBus instantiated in this context. + Having cxf:bus has no effect: <cxf:bus/> + Having cxf:bus with id causes NPE in BusDefinitionParser: <cxf:bus id="cxf"/> + --> + <bean id="cxf" class="org.apache.cxf.bus.extension.ExtensionManagerBus"/> + + <jaxrs:server id="resourceServer" address="/"> + <jaxrs:serviceBeans> + <ref component-id="resourceBean" /> + </jaxrs:serviceBeans> + </jaxrs:server> + + <bean id="resourceBean" class="org.apache.cxf.systest.jaxrs.JAXRSUriInfoBlueprintTest.Resource"/> +</blueprint> http://git-wip-us.apache.org/repos/asf/cxf/blob/307b3ed0/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/web.xml b/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/web.xml new file mode 100644 index 0000000..81c4b08 --- /dev/null +++ b/systests/jaxrs/src/test/resources/jaxrs_uriinfo_blueprint/WEB-INF/web.xml @@ -0,0 +1,45 @@ +<?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>blueprintLocation</param-name> + <param-value>jaxrs_uriinfo_blueprint/WEB-INF/beans.xml</param-value> + </context-param> + <listener> + <listener-class> + org.apache.cxf.systest.jaxrs.JAXRSBlueprintContextListener + </listener-class> + </listener> + <servlet> + <servlet-name>CXFServlet</servlet-name> + <display-name>CXF Servlet</display-name> + <servlet-class> + org.apache.cxf.transport.servlet.blueprint.CXFBlueprintServlet + </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 -->
