Repository: cxf-dosgi Updated Branches: refs/heads/master abdd7419f -> 37cf7d355
http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/README.md ---------------------------------------------------------------------- diff --git a/samples/rest/README.md b/samples/rest/README.md new file mode 100644 index 0000000..0c74070 --- /dev/null +++ b/samples/rest/README.md @@ -0,0 +1,42 @@ +# CXF DOSGi example REST + +This example shows how to expose and use a REST service using declarative services. + +The API module defines the TaskResource interface which is annotated using JAXRS annotations. + +The impl module implements the TaskService using a simple HashMap internally. It allows to manage Task objects which represent items of a to do list. + + +## Installation + +Unpack karaf 4 into a server and client directory. + +### Install server + +Start the server karaf + +``` +feature:repo-add cxf-dosgi-samples 2.0-SNAPSHOT +feature:install cxf-dosgi-sample-rest-impl +rsa:endpoints +``` + +The last command should show one endpoint with a URI as id. You should be able to open the url in the browser. The browser should show the predefined tasks as xml. + +### Install client + +Start the client karaf + +``` +feature:repo-add cxf-dosgi-samples 2.0-SNAPSHOT +feature:install cxf-dosgi-sample-rest-client +``` +Use commands to test + +``` +rsa:endpoints +task:list +task:add 4 Mytask +task:list +``` + http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/api/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/rest/api/bnd.bnd b/samples/rest/api/bnd.bnd new file mode 100644 index 0000000..d81f90b --- /dev/null +++ b/samples/rest/api/bnd.bnd @@ -0,0 +1 @@ +Export-Package: org.apache.cxf.dosgi.samples.rest \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/api/pom.xml ---------------------------------------------------------------------- diff --git a/samples/rest/api/pom.xml b/samples/rest/api/pom.xml new file mode 100644 index 0000000..3c91d30 --- /dev/null +++ b/samples/rest/api/pom.xml @@ -0,0 +1,51 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-api</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples REST API</name> + + <parent> + <groupId>org.apache.cxf.dosgi</groupId> + <artifactId>cxf-dosgi-ri-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../../../parent/pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>../../..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.servicemix.specs</groupId> + <artifactId>org.apache.servicemix.specs.jsr339-api-m10</artifactId> + <version>${servicemix.specs.version}</version> + </dependency> + <dependency> + <groupId>org.apache.servicemix.specs</groupId> + <artifactId>org.apache.servicemix.specs.jaxb-api-2.1</artifactId> + <version>${servicemix.specs.version}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/Task.java ---------------------------------------------------------------------- diff --git a/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/Task.java b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/Task.java new file mode 100644 index 0000000..6ae15a1 --- /dev/null +++ b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/Task.java @@ -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.cxf.dosgi.samples.rest; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Task { + Integer id; + String title; + String description; + Date dueDate; + boolean finished; + + public Task() { + } + + public Task(Integer id, String title, String description) { + super(); + this.id = id; + this.title = title; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = new Integer(id); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getDueDate() { + return dueDate; + } + + public void setDueDate(Date dueDate) { + this.dueDate = dueDate; + } + + public boolean isFinished() { + return finished; + } + + public void setFinished(boolean finished) { + this.finished = finished; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java ---------------------------------------------------------------------- diff --git a/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java new file mode 100644 index 0000000..e4a6798 --- /dev/null +++ b/samples/rest/api/src/main/java/org/apache/cxf/dosgi/samples/rest/TaskResource.java @@ -0,0 +1,44 @@ +/** + * 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.dosgi.samples.rest; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +@Path("") +@Produces("application/xml") +public interface TaskResource { + @GET + @Path("/{id}") + Task get(@PathParam("id") Integer id); + + @PUT + void addOrUpdate(Task task); + + @DELETE + @Path("/{id}") + void delete(Integer id); + + @GET + Task[] getAll(); +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/api/src/main/resources/OSGI-INF/cxf/jaxrs/GreeterService2-model.xml ---------------------------------------------------------------------- diff --git a/samples/rest/api/src/main/resources/OSGI-INF/cxf/jaxrs/GreeterService2-model.xml b/samples/rest/api/src/main/resources/OSGI-INF/cxf/jaxrs/GreeterService2-model.xml new file mode 100644 index 0000000..2c4da17 --- /dev/null +++ b/samples/rest/api/src/main/resources/OSGI-INF/cxf/jaxrs/GreeterService2-model.xml @@ -0,0 +1,7 @@ +<model xmlns="http://cxf.apache.org/jaxrs"> + <resource name="org.apache.cxf.dosgi.samples.greeter.rest.GreeterService2" path="greeter"> + <operation name="greetMe" verb="GET" path="greeting/{name}"> + <param name="name" type="PATH"/> + </operation> + </resource> +</model> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/client/pom.xml ---------------------------------------------------------------------- diff --git a/samples/rest/client/pom.xml b/samples/rest/client/pom.xml new file mode 100644 index 0000000..bacde9d --- /dev/null +++ b/samples/rest/client/pom.xml @@ -0,0 +1,38 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-rest-client</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples REST Client</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>../..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/client/src/main/java/org/apache/cxf/dosgi/samples/rest/client/TaskResourceCommand.java ---------------------------------------------------------------------- diff --git a/samples/rest/client/src/main/java/org/apache/cxf/dosgi/samples/rest/client/TaskResourceCommand.java b/samples/rest/client/src/main/java/org/apache/cxf/dosgi/samples/rest/client/TaskResourceCommand.java new file mode 100644 index 0000000..9e13a52 --- /dev/null +++ b/samples/rest/client/src/main/java/org/apache/cxf/dosgi/samples/rest/client/TaskResourceCommand.java @@ -0,0 +1,63 @@ +/** + * 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.dosgi.samples.rest.client; + +import org.apache.cxf.dosgi.samples.rest.Task; +import org.apache.cxf.dosgi.samples.rest.TaskResource; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component// +(// + service = TaskResourceCommand.class, + property = // + { + "osgi.command.scope=task", // + "osgi.command.function=list", // + "osgi.command.function=add", // + "osgi.command.function=delete" + }// +) +public class TaskResourceCommand { + + private TaskResource taskService; + + public void list() { + System.out.println("Open tasks:"); + Task[] tasks = taskService.getAll(); + for (Task task : tasks) { + String line = String.format("%d %s", task.getId(), task.getTitle()); + System.out.println(line); + } + } + + public void add(Integer id, String title) { + Task task = new Task(id, title, ""); + taskService.addOrUpdate(task); + } + + public void delete(Integer id) { + taskService.delete(id); + } + + @Reference + public void setTaskService(TaskResource taskService) { + this.taskService = taskService; + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml ---------------------------------------------------------------------- diff --git a/samples/rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml b/samples/rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml new file mode 100644 index 0000000..db5bb14 --- /dev/null +++ b/samples/rest/client/src/main/resources/OSGI-INF/remote-service/remote-services.xml @@ -0,0 +1,24 @@ +<?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. + --> +<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> + <service-description> + <provide interface="org.apache.cxf.dosgi.samples.greeter.rest.GreeterService" /> + <property name="service.exported.interfaces">*</property> + <property name="service.exported.configs">org.apache.cxf.rs</property> + <property name="service.exported.intents">HTTP</property> + <property name="org.apache.cxf.rs.address">http://localhost:8080/greeter</property> + </service-description> +</service-descriptions> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/impl/pom.xml ---------------------------------------------------------------------- diff --git a/samples/rest/impl/pom.xml b/samples/rest/impl/pom.xml new file mode 100644 index 0000000..dc18337 --- /dev/null +++ b/samples/rest/impl/pom.xml @@ -0,0 +1,44 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-rest-impl</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples REST Impl</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + <version>2.0.1</version> + </dependency> + <dependency> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/impl/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskServiceImpl.java ---------------------------------------------------------------------- diff --git a/samples/rest/impl/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskServiceImpl.java b/samples/rest/impl/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskServiceImpl.java new file mode 100644 index 0000000..2644e8d --- /dev/null +++ b/samples/rest/impl/src/main/java/org/apache/cxf/dosgi/samples/rest/impl/TaskServiceImpl.java @@ -0,0 +1,74 @@ +/** + * 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.dosgi.samples.rest.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.cxf.dosgi.samples.rest.Task; +import org.apache.cxf.dosgi.samples.rest.TaskResource; +import org.osgi.service.component.annotations.Component; + +@Component(immediate = true, // +property = // +{ // + "name=TaskResource", + "service.exported.interfaces=*", // + "service.exported.configs=org.apache.cxf.rs", // + "org.apache.cxf.rs.address=/tasks" // +} // +) +public class TaskServiceImpl implements TaskResource { + Map<Integer, Task> taskMap; + + public TaskServiceImpl() { + taskMap = new HashMap<Integer, Task>(); + Task task = new Task(); + task.setId(1); + task.setTitle("Buy some coffee"); + task.setDescription("Take the extra strong"); + addOrUpdate(task); + task = new Task(); + task.setId(2); + task.setTitle("Finish DOSGi example"); + task.setDescription(""); + addOrUpdate(task); + } + + @Override + public Task get(Integer id) { + return taskMap.get(id); + } + + @Override + public void addOrUpdate(Task task) { + taskMap.put(task.getId(), task); + } + + @Override + public Task[] getAll() { + return taskMap.values().toArray(new Task[]{}); + } + + @Override + public void delete(Integer id) { + taskMap.remove(id); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/rest/pom.xml ---------------------------------------------------------------------- diff --git a/samples/rest/pom.xml b/samples/rest/pom.xml new file mode 100644 index 0000000..b40e0f7 --- /dev/null +++ b/samples/rest/pom.xml @@ -0,0 +1,47 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-rest-parent</artifactId> + <packaging>pom</packaging> + <name>CXF DOSGi samples REST Parent</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modules> + <module>api</module> + <module>impl</module> + <module>client</module> + </modules> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/security_filter/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/security_filter/bnd.bnd b/samples/security_filter/bnd.bnd index 2056f10..6c23d21 100644 --- a/samples/security_filter/bnd.bnd +++ b/samples/security_filter/bnd.bnd @@ -1,2 +1 @@ Private-Package: org.apache.cxf.dosgi.samples.security -Bundle-Activator: org.apache.cxf.dosgi.samples.security.Activator \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/security_filter/pom.xml ---------------------------------------------------------------------- diff --git a/samples/security_filter/pom.xml b/samples/security_filter/pom.xml index 754b71f..bdaec00 100644 --- a/samples/security_filter/pom.xml +++ b/samples/security_filter/pom.xml @@ -13,9 +13,9 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-security</artifactId> + <artifactId>cxf-dosgi-ri-samples-security-filter</artifactId> <packaging>bundle</packaging> - <name>CXF DOSGi Security Sample Bundle</name> + <name>CXF DOSGi Samples Security Filter</name> <parent> <groupId>org.apache.cxf.dosgi</groupId> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java ---------------------------------------------------------------------- diff --git a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java b/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java deleted file mode 100644 index 2514106..0000000 --- a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/Activator.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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.dosgi.samples.security; - -import java.util.Dictionary; -import java.util.Hashtable; - -import javax.servlet.Filter; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -/** - * Registers a REST endpoint and a servlet filter to control access to the - * endpoint. - */ -public class Activator implements BundleActivator { - - private ServiceRegistration restRegistration; - private ServiceRegistration filterRegistration; - - public void start(BundleContext bundleContext) throws Exception { - // Register a rest endpoint - Dictionary<String, Object> restProps = new Hashtable<String, Object>(); - restProps.put("service.exported.interfaces", SecureRestEndpoint.class.getName()); - restProps.put("service.exported.configs", "org.apache.cxf.rs"); - restProps.put("org.apache.cxf.rs.httpservice.context", "/secure"); - restRegistration = bundleContext.registerService(SecureRestEndpoint.class.getName(), - new SecureRestEndpoint(), restProps); - - // Register a servlet filter (this could be done in another OSGi bundle, - // too) - Dictionary<String, Object> filterProps = new Hashtable<String, Object>(); - filterProps.put("org.apache.cxf.httpservice.filter", Boolean.TRUE); - // Pax-Web whiteboard (if deployed) will attempt to apply this filter to - // servlets by name or URL, and will complain - // if neither servletName or urlPatterns are specified. The felix http - // service whiteboard may do something similar. - filterProps.put("servletNames", "none"); - filterRegistration = bundleContext.registerService(Filter.class.getName(), - new SampleSecurityFilter(), filterProps); - } - - public void stop(BundleContext bundleContext) throws Exception { - restRegistration.unregister(); - filterRegistration.unregister(); - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java ---------------------------------------------------------------------- diff --git a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java b/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java index bfc8504..92c65b3 100644 --- a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java +++ b/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SampleSecurityFilter.java @@ -29,13 +29,23 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * A filter that requires a query string of "secure" to invoke the protected - * resource. + * A filter that requires a query string of "secure" to invoke the protected resource. Pax-Web whiteboard (if + * deployed) will attempt to apply this filter to servlets by name or URL, and will complain if neither + * servletName or urlPatterns are specified. The felix http service whiteboard may do something similar. */ +@Component // +(// + service = javax.servlet.Filter.class, + property = // + { + "org.apache.cxf.httpservice.filter=true", "servletNames=none" + }// +) public class SampleSecurityFilter implements Filter { private static final Logger LOG = LoggerFactory.getLogger(SampleSecurityFilter.class); http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java ---------------------------------------------------------------------- diff --git a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java b/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java index 8c066ac..a646c2d 100644 --- a/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java +++ b/samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/SecureRestEndpoint.java @@ -23,6 +23,18 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.osgi.service.component.annotations.Component; + +@Component // +(// + service = SecureRestEndpoint.class, + property = // + { // + "service.exported.interfaces=*", + "service.exported.configs=org.apache.cxf.rs", + "org.apache.cxf.rs.httpservice.context=/secure" + } +) @Path("/") public class SecureRestEndpoint { http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/README.md ---------------------------------------------------------------------- diff --git a/samples/soap/README.md b/samples/soap/README.md new file mode 100644 index 0000000..638b3cb --- /dev/null +++ b/samples/soap/README.md @@ -0,0 +1,42 @@ +# CXF DOSGi example SOAP + +This example shows how to expose and use a SOAP service using declarative services. + +The API module defines the TaskService interface which is annotated using @WebService to signal that +we want to create a JAXWS based SOAP service. + +The impl module implements the TaskService using a simple HashMap internally. It allows to manage Task objects which represent items of a to do list. + + +## Installation + +Unpack karaf 4 into a server and client directory. + +### Install server + +Start the server karaf + +``` +feature:repo-add cxf-dosgi-samples 2.0-SNAPSHOT +feature:install cxf-dosgi-sample-soap-impl +rsa:endpoints +``` + +The last command should show one endpoint with a URI as id. You should be able to open the url in the browser. + +### Install client + +Start the client karaf + +``` +feature:repo-add cxf-dosgi-samples 2.0-SNAPSHOT +feature:install cxf-dosgi-sample-soap-client +``` +Use commands to test + +``` +rsa:endpoints +task:list +task:add 4 Mytask +task:list +``` http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/api/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/soap/api/bnd.bnd b/samples/soap/api/bnd.bnd new file mode 100644 index 0000000..7f29e80 --- /dev/null +++ b/samples/soap/api/bnd.bnd @@ -0,0 +1 @@ +Export-Package: org.apache.cxf.dosgi.samples.soap \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/api/pom.xml ---------------------------------------------------------------------- diff --git a/samples/soap/api/pom.xml b/samples/soap/api/pom.xml new file mode 100644 index 0000000..9468c1a --- /dev/null +++ b/samples/soap/api/pom.xml @@ -0,0 +1,38 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-soap-api</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples SOAP API</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-soap-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/Task.java ---------------------------------------------------------------------- diff --git a/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/Task.java b/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/Task.java new file mode 100644 index 0000000..a689ed4 --- /dev/null +++ b/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/Task.java @@ -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.cxf.dosgi.samples.soap; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Task { + Integer id; + String title; + String description; + Date dueDate; + boolean finished; + + public Task() { + } + + public Task(Integer id, String title, String description) { + super(); + this.id = id; + this.title = title; + this.description = description; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = new Integer(id); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Date getDueDate() { + return dueDate; + } + + public void setDueDate(Date dueDate) { + this.dueDate = dueDate; + } + + public boolean isFinished() { + return finished; + } + + public void setFinished(boolean finished) { + this.finished = finished; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/TaskService.java ---------------------------------------------------------------------- diff --git a/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/TaskService.java b/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/TaskService.java new file mode 100644 index 0000000..45face5 --- /dev/null +++ b/samples/soap/api/src/main/java/org/apache/cxf/dosgi/samples/soap/TaskService.java @@ -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.cxf.dosgi.samples.soap; + +import java.util.Collection; + +import javax.jws.WebService; + +@WebService +public interface TaskService { + Task get(Integer id); + + void addOrUpdate(Task task); + + void delete(Integer id); + + Collection<Task> getAll(); +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/client/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/soap/client/bnd.bnd b/samples/soap/client/bnd.bnd new file mode 100644 index 0000000..c2afb9b --- /dev/null +++ b/samples/soap/client/bnd.bnd @@ -0,0 +1 @@ +Export-Package: org.apache.cxf.dosgi.samples.soap.client \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/client/pom.xml ---------------------------------------------------------------------- diff --git a/samples/soap/client/pom.xml b/samples/soap/client/pom.xml new file mode 100644 index 0000000..f850e56 --- /dev/null +++ b/samples/soap/client/pom.xml @@ -0,0 +1,37 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-soap-client</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples SOAP Client</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-soap-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-soap-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/client/src/main/java/org/apache/cxf/dosgi/samples/soap/client/TaskServiceCommand.java ---------------------------------------------------------------------- diff --git a/samples/soap/client/src/main/java/org/apache/cxf/dosgi/samples/soap/client/TaskServiceCommand.java b/samples/soap/client/src/main/java/org/apache/cxf/dosgi/samples/soap/client/TaskServiceCommand.java new file mode 100644 index 0000000..a249d38 --- /dev/null +++ b/samples/soap/client/src/main/java/org/apache/cxf/dosgi/samples/soap/client/TaskServiceCommand.java @@ -0,0 +1,65 @@ +/** + * 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.dosgi.samples.soap.client; + +import java.util.Collection; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +@Component// +(// + service = TaskServiceCommand.class, + property = // + { + "osgi.command.scope=task", // + "osgi.command.function=list", // + "osgi.command.function=add", // + "osgi.command.function=delete" + }// +) +public class TaskServiceCommand { + + private TaskService taskService; + + public void list() { + System.out.println("Open tasks:"); + Collection<Task> tasks = taskService.getAll(); + for (Task task : tasks) { + String line = String.format("%d %s", task.getId(), task.getTitle()); + System.out.println(line); + } + } + + public void add(Integer id, String title) { + Task task = new Task(id, title, ""); + taskService.addOrUpdate(task); + } + + public void delete(Integer id) { + taskService.delete(id); + } + + @Reference + public void setTaskService(TaskService taskService) { + this.taskService = taskService; + } +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/impl/pom.xml ---------------------------------------------------------------------- diff --git a/samples/soap/impl/pom.xml b/samples/soap/impl/pom.xml new file mode 100644 index 0000000..2dfb07a --- /dev/null +++ b/samples/soap/impl/pom.xml @@ -0,0 +1,45 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-soap-impl</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi samples SOAP Impl</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-soap-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-soap-api</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/impl/src/main/java/org/apache/cxf/dosgi/samples/soap/impl/TaskServiceImpl.java ---------------------------------------------------------------------- diff --git a/samples/soap/impl/src/main/java/org/apache/cxf/dosgi/samples/soap/impl/TaskServiceImpl.java b/samples/soap/impl/src/main/java/org/apache/cxf/dosgi/samples/soap/impl/TaskServiceImpl.java new file mode 100644 index 0000000..d2f94bf --- /dev/null +++ b/samples/soap/impl/src/main/java/org/apache/cxf/dosgi/samples/soap/impl/TaskServiceImpl.java @@ -0,0 +1,77 @@ +/** + * 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.dosgi.samples.soap.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.cxf.dosgi.samples.soap.Task; +import org.apache.cxf.dosgi.samples.soap.TaskService; +import org.osgi.service.component.annotations.Component; + +@Component(immediate = true, // +property = // +{ // + "name=TaskService", + "service.exported.interfaces=*", // + "service.exported.configs=org.apache.cxf.ws", // + "org.apache.cxf.ws.address=/taskservice" // +} // +) +public class TaskServiceImpl implements TaskService { + Map<Integer, Task> taskMap; + + public TaskServiceImpl() { + taskMap = new HashMap<Integer, Task>(); + Task task = new Task(); + task.setId(1); + task.setTitle("Buy some coffee"); + task.setDescription("Take the extra strong"); + addOrUpdate(task); + task = new Task(); + task.setId(2); + task.setTitle("Finish DOSGi example"); + task.setDescription(""); + addOrUpdate(task); + } + + @Override + public Task get(Integer id) { + return taskMap.get(id); + } + + @Override + public void addOrUpdate(Task task) { + taskMap.put(task.getId(), task); + } + + @Override + public Collection<Task> getAll() { + // taskMap.values is not serializable + return new ArrayList<Task>(taskMap.values()); + } + + @Override + public void delete(Integer id) { + taskMap.remove(id); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/soap/pom.xml ---------------------------------------------------------------------- diff --git a/samples/soap/pom.xml b/samples/soap/pom.xml new file mode 100644 index 0000000..59801ad --- /dev/null +++ b/samples/soap/pom.xml @@ -0,0 +1,45 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-soap-parent</artifactId> + <packaging>pom</packaging> + <name>CXF DOSGi samples SOAP Parent</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <modules> + <module>api</module> + <module>impl</module> + <module>client</module> + </modules> + + <dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/README.md ---------------------------------------------------------------------- diff --git a/samples/ssl/README.md b/samples/ssl/README.md index dce022a..d3c66e5 100644 --- a/samples/ssl/README.md +++ b/samples/ssl/README.md @@ -2,6 +2,10 @@ This example demonstrates how to configure ssl with a custom keystore and required key based client auth using a plain DOSGi service with a custom intent. +The example reuses the soap example code. It then adds the ssl intent to the service impl by using a config. This prevents the service from starting up. + +We then install the ssl-intent bundle which implements the intent. This allows the service and client to start up. + ## Karaf SSL config We want the karaf HttpService to be secured by https and require a client certificate for authentication. @@ -27,7 +31,7 @@ We want the karaf HttpService to be secured by https and require a client certif keytool -importcert -storepass password -keystore etc/keystores/client.jks -alias serverKey -file server.cert -- Copy the file org.ops4j.pax.web.cfg to the karaf etc dir. +- Copy thes files in etc to the karaf etc dir - Copy the keystores (*.jks) into the karaf etc directory. ## Installation @@ -40,9 +44,10 @@ We want the karaf HttpService to be secured by https and require a client certif feature:repo-add cxf-dosgi 2.0-SNAPSHOT feature:install cxf-dosgi-provider-ws -install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-ri-samples-ssl-interface/2.0_SNAPSHOT -install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-ri-samples-ssl-impl/2.0-SNAPSHOT -install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-ri-samples-ssl-client/2.0-SNAPSHOT +install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-samples-soap-api/2.0_SNAPSHOT +install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-samples-soap-impl/2.0-SNAPSHOT +install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-samples-soap-client/2.0-SNAPSHOT +install -s mvn:org.apache.cxf.dosgi.samples/cxf-dosgi-samples-ssl-intent/2.0-SNAPSHOT ``` # Test using browser http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/client/pom.xml ---------------------------------------------------------------------- diff --git a/samples/ssl/client/pom.xml b/samples/ssl/client/pom.xml deleted file mode 100644 index dbea300..0000000 --- a/samples/ssl/client/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?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"> - - <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-dosgi-ri-samples-ssl-client</artifactId> - <packaging>bundle</packaging> - <name>CXF DOSGi Greeter Bundle Client</name> - - <parent> - <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-parent</artifactId> - <version>2.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <properties> - <topDirectoryLocation>../../..</topDirectoryLocation> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-interface</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/client/src/main/java/org/apache/cxf/dosgi/samples/ssl/client/EchoClient.java ---------------------------------------------------------------------- diff --git a/samples/ssl/client/src/main/java/org/apache/cxf/dosgi/samples/ssl/client/EchoClient.java b/samples/ssl/client/src/main/java/org/apache/cxf/dosgi/samples/ssl/client/EchoClient.java deleted file mode 100644 index 0b701e2..0000000 --- a/samples/ssl/client/src/main/java/org/apache/cxf/dosgi/samples/ssl/client/EchoClient.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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.dosgi.samples.ssl.client; - -import org.apache.cxf.dosgi.samples.ssl.EchoService; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -@Component// -(// - immediate = true // -) -public class EchoClient { - private EchoService echoService; - - @Activate - public void activate() { - System.out.println(echoService.echo("Hello")); - } - - @Reference(target = "(service.imported=*)") - public void setEchoService(EchoService echoService) { - this.echoService = echoService; - } -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/etc/cxf.dosgi.sample.impl.cfg ---------------------------------------------------------------------- diff --git a/samples/ssl/etc/cxf.dosgi.sample.impl.cfg b/samples/ssl/etc/cxf.dosgi.sample.impl.cfg new file mode 100644 index 0000000..37de3ca --- /dev/null +++ b/samples/ssl/etc/cxf.dosgi.sample.impl.cfg @@ -0,0 +1 @@ +service.exported.intents=ssl http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/etc/org.ops4j.pax.web.cfg ---------------------------------------------------------------------- diff --git a/samples/ssl/etc/org.ops4j.pax.web.cfg b/samples/ssl/etc/org.ops4j.pax.web.cfg new file mode 100644 index 0000000..8061c7f --- /dev/null +++ b/samples/ssl/etc/org.ops4j.pax.web.cfg @@ -0,0 +1,12 @@ +# Configure pax web with a server key and allowed client cert +javax.servlet.context.tempdir = ${karaf.home}/data/pax-web-jsp +org.ops4j.pax.web.config.file = ${karaf.home}/etc/jetty.xml +org.osgi.service.http.port = 8181 +org.osgi.service.http.secure.enabled=true +org.ops4j.pax.web.ssl.keystore=etc/keystores/keystore.jks +org.ops4j.pax.web.ssl.truststore=etc/keystores/keystore.jks +org.ops4j.pax.web.ssl.password=password +org.ops4j.pax.web.ssl.keypassword=password +org.osgi.service.http.port.secure=8443 +org.ops4j.pax.web.ssl.clientauthneeded=true + http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/impl/pom.xml ---------------------------------------------------------------------- diff --git a/samples/ssl/impl/pom.xml b/samples/ssl/impl/pom.xml deleted file mode 100644 index 7a1025f..0000000 --- a/samples/ssl/impl/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?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"> - <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-dosgi-ri-samples-ssl-impl</artifactId> - <packaging>bundle</packaging> - <name>CXF DOSGi Greeter Implementation Bundle</name> - - <parent> - <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-parent</artifactId> - <version>2.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <properties> - <topDirectoryLocation>..</topDirectoryLocation> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-interface</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/impl/src/main/java/org/apache/cxf/dosgi/samples/ssl/impl/GreeterServiceImpl.java ---------------------------------------------------------------------- diff --git a/samples/ssl/impl/src/main/java/org/apache/cxf/dosgi/samples/ssl/impl/GreeterServiceImpl.java b/samples/ssl/impl/src/main/java/org/apache/cxf/dosgi/samples/ssl/impl/GreeterServiceImpl.java deleted file mode 100644 index ba56916..0000000 --- a/samples/ssl/impl/src/main/java/org/apache/cxf/dosgi/samples/ssl/impl/GreeterServiceImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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.dosgi.samples.ssl.impl; - -import org.apache.cxf.dosgi.samples.ssl.EchoService; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -@Component(// - immediate = true, // - property = // - { - "service.exported.interfaces=*", // - "service.exported.configs=org.apache.cxf.ws", // - "org.apache.cxf.ws.address=/echo", // - RemoteConstants.SERVICE_EXPORTED_INTENTS + "=ssl" - } // -) -public class GreeterServiceImpl implements EchoService { - - @Override - public String echo(String msg) { - return msg; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/interface/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/ssl/interface/bnd.bnd b/samples/ssl/interface/bnd.bnd deleted file mode 100644 index a89d016..0000000 --- a/samples/ssl/interface/bnd.bnd +++ /dev/null @@ -1 +0,0 @@ -Export-Package: org.apache.cxf.dosgi.samples.ssl \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/interface/pom.xml ---------------------------------------------------------------------- diff --git a/samples/ssl/interface/pom.xml b/samples/ssl/interface/pom.xml deleted file mode 100644 index d705a41..0000000 --- a/samples/ssl/interface/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?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"> - - <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-dosgi-ri-samples-ssl-interface</artifactId> - <packaging>bundle</packaging> - <name>CXF DOSGi Greeter Interface Bundle</name> - - <parent> - <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-parent</artifactId> - <version>2.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <properties> - <topDirectoryLocation>..</topDirectoryLocation> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-transports-http-jetty</artifactId> - <version>${cxf.version}</version> - </dependency> - </dependencies> -</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java ---------------------------------------------------------------------- diff --git a/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java b/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java deleted file mode 100644 index 6669f24..0000000 --- a/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * 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.dosgi.samples.ssl; - -public interface EchoService { - String echo(String msg); -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java ---------------------------------------------------------------------- diff --git a/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java b/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java deleted file mode 100644 index 558f7a7..0000000 --- a/samples/ssl/interface/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * 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.dosgi.samples.ssl; - -import static javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm; - -import java.io.FileInputStream; -import java.security.KeyStore; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Callable; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; - -import org.apache.cxf.configuration.jsse.TLSClientParameters; -import org.apache.cxf.transport.http.HttpConduitConfig; -import org.apache.cxf.transport.http.HttpConduitFeature; -import org.osgi.service.component.annotations.Component; - -/** - * Configures the client side conduit to trust the server certificate and authenticate by using - * a client certificate - */ -@Component // -(// - property = "org.apache.cxf.dosgi.IntentName=ssl" // -) -public class SslIntent implements Callable<List<Object>> { - - private static final String CLIENT_PASSWORD = "password"; - - @Override - public List<Object> call() throws Exception { - HttpConduitFeature conduitFeature = new HttpConduitFeature(); - HttpConduitConfig conduitConfig = new HttpConduitConfig(); - TLSClientParameters tls = new TLSClientParameters(); - String karafHome = System.getProperty("karaf.home"); - tls.setKeyManagers(keyManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD), - CLIENT_PASSWORD)); - tls.setTrustManagers(trustManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD))); - //tls.setTrustManagers(new TrustManager[]{new DefaultTrustManager()}); - HostnameVerifier verifier = new HostnameVerifier() { - - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - tls.setHostnameVerifier(verifier); - tls.setCertAlias("clientkey"); - tls.setDisableCNCheck(true); - conduitConfig.setTlsClientParameters(tls); - conduitFeature.setConduitConfig(conduitConfig); - - return Arrays.asList((Object)conduitFeature); - } - - private TrustManager[] trustManager(KeyStore ks) throws Exception { - TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - factory.init(ks); - return factory.getTrustManagers(); - } - - private KeyManager[] keyManager(KeyStore ks, String keyPassword) throws Exception { - KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(getDefaultAlgorithm()); - kmfactory.init(ks, keyPassword.toCharArray()); - return kmfactory.getKeyManagers(); - } - - private KeyStore keystore(String keystorePath, String storePassword) throws Exception { - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(new FileInputStream(keystorePath), storePassword.toCharArray()); - return ks; - } - - -} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/org.ops4j.pax.web.cfg ---------------------------------------------------------------------- diff --git a/samples/ssl/org.ops4j.pax.web.cfg b/samples/ssl/org.ops4j.pax.web.cfg deleted file mode 100644 index 8061c7f..0000000 --- a/samples/ssl/org.ops4j.pax.web.cfg +++ /dev/null @@ -1,12 +0,0 @@ -# Configure pax web with a server key and allowed client cert -javax.servlet.context.tempdir = ${karaf.home}/data/pax-web-jsp -org.ops4j.pax.web.config.file = ${karaf.home}/etc/jetty.xml -org.osgi.service.http.port = 8181 -org.osgi.service.http.secure.enabled=true -org.ops4j.pax.web.ssl.keystore=etc/keystores/keystore.jks -org.ops4j.pax.web.ssl.truststore=etc/keystores/keystore.jks -org.ops4j.pax.web.ssl.password=password -org.ops4j.pax.web.ssl.keypassword=password -org.osgi.service.http.port.secure=8443 -org.ops4j.pax.web.ssl.clientauthneeded=true - http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/pom.xml ---------------------------------------------------------------------- diff --git a/samples/ssl/pom.xml b/samples/ssl/pom.xml index e48404e..0fe4033 100644 --- a/samples/ssl/pom.xml +++ b/samples/ssl/pom.xml @@ -21,15 +21,15 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.cxf.dosgi.samples</groupId> - <artifactId>cxf-dosgi-ri-samples-ssl-parent</artifactId> + <artifactId>cxf-dosgi-samples-ssl-parent</artifactId> <packaging>pom</packaging> <name>CXF DOSGi Greeter Bundles</name> <parent> - <groupId>org.apache.cxf.dosgi</groupId> - <artifactId>cxf-dosgi-ri-parent</artifactId> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-parent</artifactId> <version>2.0-SNAPSHOT</version> - <relativePath>../../parent/pom.xml</relativePath> + <relativePath>../pom.xml</relativePath> </parent> <dependencies> @@ -46,9 +46,6 @@ </dependencies> <modules> - <module>interface</module> - <module>impl</module> - <module>client</module> + <module>ssl-intent</module> </modules> - </project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/ssl-intent/bnd.bnd ---------------------------------------------------------------------- diff --git a/samples/ssl/ssl-intent/bnd.bnd b/samples/ssl/ssl-intent/bnd.bnd new file mode 100644 index 0000000..e69de29 http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/ssl-intent/pom.xml ---------------------------------------------------------------------- diff --git a/samples/ssl/ssl-intent/pom.xml b/samples/ssl/ssl-intent/pom.xml new file mode 100644 index 0000000..5c69ff5 --- /dev/null +++ b/samples/ssl/ssl-intent/pom.xml @@ -0,0 +1,45 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>cxf-dosgi-samples-ssl-intent</artifactId> + <packaging>bundle</packaging> + <name>CXF DOSGi Greeter Interface Bundle</name> + + <parent> + <groupId>org.apache.cxf.dosgi.samples</groupId> + <artifactId>cxf-dosgi-samples-ssl-parent</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <properties> + <topDirectoryLocation>..</topDirectoryLocation> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-transports-http-jetty</artifactId> + <version>${cxf.version}</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java ---------------------------------------------------------------------- diff --git a/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java b/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java new file mode 100644 index 0000000..6669f24 --- /dev/null +++ b/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/EchoService.java @@ -0,0 +1,23 @@ +/** + * 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.dosgi.samples.ssl; + +public interface EchoService { + String echo(String msg); +} http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/37cf7d35/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java ---------------------------------------------------------------------- diff --git a/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java b/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java new file mode 100644 index 0000000..558f7a7 --- /dev/null +++ b/samples/ssl/ssl-intent/src/main/java/org/apache/cxf/dosgi/samples/ssl/SslIntent.java @@ -0,0 +1,98 @@ +/** + * 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.dosgi.samples.ssl; + +import static javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm; + +import java.io.FileInputStream; +import java.security.KeyStore; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.Callable; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.cxf.configuration.jsse.TLSClientParameters; +import org.apache.cxf.transport.http.HttpConduitConfig; +import org.apache.cxf.transport.http.HttpConduitFeature; +import org.osgi.service.component.annotations.Component; + +/** + * Configures the client side conduit to trust the server certificate and authenticate by using + * a client certificate + */ +@Component // +(// + property = "org.apache.cxf.dosgi.IntentName=ssl" // +) +public class SslIntent implements Callable<List<Object>> { + + private static final String CLIENT_PASSWORD = "password"; + + @Override + public List<Object> call() throws Exception { + HttpConduitFeature conduitFeature = new HttpConduitFeature(); + HttpConduitConfig conduitConfig = new HttpConduitConfig(); + TLSClientParameters tls = new TLSClientParameters(); + String karafHome = System.getProperty("karaf.home"); + tls.setKeyManagers(keyManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD), + CLIENT_PASSWORD)); + tls.setTrustManagers(trustManager(keystore(karafHome + "/etc/keystores/client.jks", CLIENT_PASSWORD))); + //tls.setTrustManagers(new TrustManager[]{new DefaultTrustManager()}); + HostnameVerifier verifier = new HostnameVerifier() { + + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + tls.setHostnameVerifier(verifier); + tls.setCertAlias("clientkey"); + tls.setDisableCNCheck(true); + conduitConfig.setTlsClientParameters(tls); + conduitFeature.setConduitConfig(conduitConfig); + + return Arrays.asList((Object)conduitFeature); + } + + private TrustManager[] trustManager(KeyStore ks) throws Exception { + TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + factory.init(ks); + return factory.getTrustManagers(); + } + + private KeyManager[] keyManager(KeyStore ks, String keyPassword) throws Exception { + KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(getDefaultAlgorithm()); + kmfactory.init(ks, keyPassword.toCharArray()); + return kmfactory.getKeyManagers(); + } + + private KeyStore keystore(String keystorePath, String storePassword) throws Exception { + KeyStore ks = KeyStore.getInstance("JKS"); + ks.load(new FileInputStream(keystorePath), storePassword.toCharArray()); + return ks; + } + + +}