[CXF-7060] Provide Karaf 4 specific features and commands Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/042d1dbe Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/042d1dbe Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/042d1dbe
Branch: refs/heads/master Commit: 042d1dbe5f236125c77db8348bf66d4a3d4d2385 Parents: 56dab42 Author: Guillaume Nodet <gno...@apache.org> Authored: Mon Sep 19 14:19:26 2016 +0200 Committer: Guillaume Nodet <gno...@apache.org> Committed: Mon Sep 19 14:22:59 2016 +0200 ---------------------------------------------------------------------- osgi/karaf4/commands/pom.xml | 84 +++ .../cxf/karaf/commands/ListBussesCommand.java | 65 +++ .../karaf/commands/ListEndpointsCommand.java | 160 ++++++ .../karaf/commands/StartEndpointCommand.java | 68 +++ .../cxf/karaf/commands/StopEndpointCommand.java | 68 +++ .../karaf/commands/completers/BusCompleter.java | 53 ++ .../completers/EndpointCompleterSupport.java | 68 +++ .../completers/StartedEndpointCompleter.java | 33 ++ .../completers/StoppedEndpointCompleter.java | 34 ++ .../karaf/commands/internal/CXFController.java | 94 ++++ osgi/karaf4/features/pom.xml | 127 +++++ .../src/main/resources/config.properties | 334 ++++++++++++ .../features/src/main/resources/features.xml | 517 +++++++++++++++++++ osgi/karaf4/pom.xml | 36 ++ osgi/pom.xml | 1 + parent/pom.xml | 1 + rt/management-web/pom.xml | 4 + rt/transports/http-netty/netty-client/pom.xml | 1 + rt/transports/http-netty/netty-server/pom.xml | 2 + 19 files changed, 1750 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/pom.xml b/osgi/karaf4/commands/pom.xml new file mode 100644 index 0000000..4a6e5fc --- /dev/null +++ b/osgi/karaf4/commands/pom.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + <!-- + + 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. + --> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.cxf.karaf4</groupId> + <artifactId>karaf4-parent</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + <artifactId>cxf-karaf4-commands</artifactId> + <packaging>bundle</packaging> + <name>Apache CXF Karaf4 Commands</name> + <description>Apache CXF Karaf4 Commands</description> + <dependencies> + <!-- cxf --> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-core</artifactId> + <version>${project.version}</version> + </dependency> + <!-- karaf --> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.core</artifactId> + <version>${cxf.karaf4.version}</version> + </dependency> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + <version>${cxf.karaf4.version}</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-services-maven-plugin</artifactId> + <version>${cxf.karaf4.version}</version> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Karaf-Commands>*</Karaf-Commands> + <Import-Package> + !org.apache.cxf.karaf.commands, + org.apache.cxf*;version="[3,4)", + org.apache.karaf.shell*;version="[4,5)", + * + </Import-Package> + <_nouses>true</_nouses> + <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.java new file mode 100644 index 0000000..820f065 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListBussesCommand.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.karaf.commands; + +import java.util.List; + +import org.apache.cxf.Bus; +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.lifecycle.Service; + +/** + * + */ +@Command(scope = "cxf", name = "list-busses", description = "Lists all CXF Busses.") +@Service +public class ListBussesCommand extends CXFController implements Action { + protected static final int DEFAULT_BUSID_LENGTH = 38; + protected String headerFormat = "%-40s %-20s"; + protected String outputFormat = "[%-38s] [%-18s]"; + + @Override + public Object execute() throws Exception { + List<Bus> busses = getBusses(); + renderFormat(busses); + System.out.println(String.format(headerFormat, "Name", "State")); + + for (Bus bus : busses) { + String state = bus.getState().toString(); + System.out.println(String.format(outputFormat, bus.getId(), state)); + } + return null; + } + + private void renderFormat(List<Bus> busses) { + int longestBusId = DEFAULT_BUSID_LENGTH; + for (Bus bus : busses) { + if (bus.getId().length() > longestBusId) { + longestBusId = bus.getId().length(); + } + } + if (longestBusId > DEFAULT_BUSID_LENGTH) { + headerFormat = "%-" + (longestBusId + 2) + "s %-20s"; + outputFormat = "[%-" + longestBusId + "s] [%-18s]"; + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java new file mode 100644 index 0000000..1e4f7fa --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/ListEndpointsCommand.java @@ -0,0 +1,160 @@ +/** + * 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.karaf.commands; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import org.apache.cxf.Bus; +import org.apache.cxf.common.util.StringUtils; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.endpoint.ServerRegistry; +import org.apache.cxf.karaf.commands.completers.BusCompleter; +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +/** + * + */ +@Command(scope = "cxf", name = "list-endpoints", + description = "Lists all CXF Endpoints on a Bus.") +@Service +public class ListEndpointsCommand extends CXFController implements Action { + protected static final String HEADER_FORMAT = "%-25s %-10s %-60s %-40s"; + protected static final String OUTPUT_FORMAT = "[%-23s] [%-8s] [%-58s] [%-38s]"; + + @Argument(index = 0, name = "bus", + description = "The CXF bus name where to look for the Endpoints", + required = false, multiValued = false) + @Completion(BusCompleter.class) + String name; + + @Option(name = "-f", aliases = {"--fulladdress" }, + description = "Display full address of an endpoint ", required = false, multiValued = false) + boolean fullAddress; + + @Override + public Object execute() throws Exception { + List<Bus> busses; + if (name == null) { + busses = getBusses(); + } else { + Bus b = getBus(name); + if (b != null) { + busses = Collections.singletonList(getBus(name)); + } else { + busses = Collections.emptyList(); + } + } + System.out.println(String.format(HEADER_FORMAT, + "Name", "State", "Address", "BusID")); + for (Bus b : busses) { + ServerRegistry reg = b.getExtension(ServerRegistry.class); + List<Server> servers = reg.getServers(); + + for (Server serv : servers) { + String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart(); + String started = serv.isStarted() ? "Started" : "Stopped"; + String address = serv.getEndpoint().getEndpointInfo().getAddress(); + if (fullAddress) { + address = toFullAddress(address); + } + String busId = b.getId(); + System.out.println(String.format(OUTPUT_FORMAT, qname, started, address, busId)); + } + } + return null; + } + + private String toFullAddress(String address) throws IOException, InvalidSyntaxException { + ConfigurationAdmin configAdmin = getConfigAdmin(); + if (address.startsWith("/") && configAdmin != null) { + String httpPort = null; + String cxfContext = null; + httpPort = extractConfigProperty(configAdmin, "org.ops4j.pax.web", "org.osgi.service.http.port"); + cxfContext = extractConfigProperty(configAdmin, "org.apache.cxf.osgi", "org.apache.cxf.servlet.context"); + if (StringUtils.isEmpty(cxfContext)) { + cxfContext = getCXFOSGiServletContext(); + } + if (StringUtils.isEmpty(httpPort)) { + httpPort = getHttpOSGiServicePort(); + } + if (!StringUtils.isEmpty(httpPort) && !StringUtils.isEmpty(cxfContext)) { + address = "http://localhost:" + httpPort + cxfContext + address; + } + } + return address; + } + + private String extractConfigProperty(ConfigurationAdmin configAdmin, + String pid, String propertyName) throws IOException, + InvalidSyntaxException { + String ret = null; + Configuration[] configs = configAdmin.listConfigurations("(service.pid=" + pid + ")"); + if (configs != null && configs.length > 0) { + Configuration configuration = configs[0]; + if (configuration != null) { + ret = (String)configuration.getProperties().get(propertyName); + } + } + return ret; + } + + private String getCXFOSGiServletContext() throws InvalidSyntaxException { + String ret = null; + String filter = "(&(" + "objectclass=" + "javax.servlet.Servlet" + + ")(servlet-name=cxf-osgi-transport-servlet))"; + + ServiceReference ref = getBundleContext().getServiceReferences(null, filter)[0]; + + if (ref != null) { + ret = (String)ref.getProperty("alias"); + } + + return ret; + + } + + private String getHttpOSGiServicePort() throws InvalidSyntaxException { + String ret = null; + String filter = "(&(" + "objectclass=" + "org.osgi.service.http.HttpService" + + "))"; + + ServiceReference ref = getBundleContext().getServiceReferences(null, filter)[0]; + + if (ref != null) { + ret = (String) ref.getProperty("org.osgi.service.http.port"); + } + + return ret; + + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StartEndpointCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StartEndpointCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StartEndpointCommand.java new file mode 100644 index 0000000..d2bf6be --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StartEndpointCommand.java @@ -0,0 +1,68 @@ +/** + * 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.karaf.commands; + +import java.util.List; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.endpoint.ServerRegistry; +import org.apache.cxf.karaf.commands.completers.BusCompleter; +import org.apache.cxf.karaf.commands.completers.StoppedEndpointCompleter; +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.lifecycle.Service; + +/** + * + */ +@Command(scope = "cxf", name = "start-endpoint", + description = "Starts a CXF Endpoint on a Bus.") +@Service +public class StartEndpointCommand extends CXFController implements Action { + + @Argument(index = 0, name = "bus", + description = "The CXF bus name where to look for the Endpoint", + required = true, multiValued = false) + @Completion(BusCompleter.class) + String busName; + + @Argument(index = 1, name = "endpoint", + description = "The Endpoint name to start", + required = true, multiValued = false) + @Completion(StoppedEndpointCompleter.class) + String endpoint; + + @Override + public Object execute() throws Exception { + Bus b = getBus(busName); + ServerRegistry reg = b.getExtension(ServerRegistry.class); + List<Server> servers = reg.getServers(); + for (Server serv : servers) { + if (endpoint.equals(serv.getEndpoint().getEndpointInfo().getName().getLocalPart())) { + serv.start(); + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StopEndpointCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StopEndpointCommand.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StopEndpointCommand.java new file mode 100644 index 0000000..9ffdbf9 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/StopEndpointCommand.java @@ -0,0 +1,68 @@ +/** + * 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.karaf.commands; + +import java.util.List; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.endpoint.ServerRegistry; +import org.apache.cxf.karaf.commands.completers.BusCompleter; +import org.apache.cxf.karaf.commands.completers.StartedEndpointCompleter; +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.action.Action; +import org.apache.karaf.shell.api.action.Argument; +import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.Completion; +import org.apache.karaf.shell.api.action.lifecycle.Service; + +/** + * + */ +@Command(scope = "cxf", name = "stop-endpoint", + description = "Stops a CXF Endpoint on a Bus.") +@Service +public class StopEndpointCommand extends CXFController implements Action { + + @Argument(index = 0, name = "bus", + description = "The CXF bus name where to look for the Endpoint", + required = true, multiValued = false) + @Completion(BusCompleter.class) + String busName; + + @Argument(index = 1, name = "endpoint", + description = "The Endpoint name to stop", + required = true, multiValued = false) + @Completion(StartedEndpointCompleter.class) + String endpoint; + + @Override + public Object execute() throws Exception { + Bus b = getBus(busName); + ServerRegistry reg = b.getExtension(ServerRegistry.class); + List<Server> servers = reg.getServers(); + for (Server serv : servers) { + if (endpoint.equals(serv.getEndpoint().getEndpointInfo().getName().getLocalPart())) { + serv.stop(); + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java new file mode 100644 index 0000000..47217e1 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/BusCompleter.java @@ -0,0 +1,53 @@ +/** + * 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.karaf.commands.completers; + +import java.util.List; + +import org.apache.cxf.Bus; + +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.action.lifecycle.Service; +import org.apache.karaf.shell.api.console.CommandLine; +import org.apache.karaf.shell.api.console.Completer; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.support.completers.StringsCompleter; + +@Service +public class BusCompleter extends CXFController implements Completer { + + @Override + public int complete(Session session, + CommandLine commandLine, + List<String> list) { + StringsCompleter delegate = new StringsCompleter(); + try { + List<Bus> busses = getBusses(); + + for (Bus bus : busses) { + delegate.getStrings().add(bus.getId()); + } + + } catch (Exception e) { + // Ignore + } + return delegate.complete(session, commandLine, list); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java new file mode 100644 index 0000000..463a5ad --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/EndpointCompleterSupport.java @@ -0,0 +1,68 @@ +/** + * 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.karaf.commands.completers; + +import java.util.List; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.endpoint.ServerRegistry; +import org.apache.cxf.karaf.commands.internal.CXFController; +import org.apache.karaf.shell.api.console.CommandLine; +import org.apache.karaf.shell.api.console.Completer; +import org.apache.karaf.shell.api.console.Session; +import org.apache.karaf.shell.support.completers.StringsCompleter; + +public abstract class EndpointCompleterSupport extends CXFController implements Completer { + + @Override + public int complete(Session session, + CommandLine commandLine, + List<String> list) { + StringsCompleter delegate = new StringsCompleter(); + try { + List<Bus> busses = getBusses(); + + for (Bus b : busses) { + ServerRegistry reg = b.getExtension(ServerRegistry.class); + List<Server> servers = reg.getServers(); + + for (Server serv : servers) { + if (acceptsFeature(serv)) { + String qname = serv.getEndpoint().getEndpointInfo().getName().getLocalPart(); + delegate.getStrings().add(qname); + } + } + } + + } catch (Exception e) { + // Ignore + } + return delegate.complete(session, commandLine, list); + } + + /** + * Method for filtering endpoint. + * + * @param server The endpoint Server. + * @return True if endpoint Server should be available in completer. + */ + protected abstract boolean acceptsFeature(Server server); + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java new file mode 100644 index 0000000..1e2d529 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StartedEndpointCompleter.java @@ -0,0 +1,33 @@ +/** + * 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.karaf.commands.completers; + + +import org.apache.cxf.endpoint.Server; +import org.apache.karaf.shell.api.action.lifecycle.Service; + +@Service +public class StartedEndpointCompleter extends EndpointCompleterSupport { + + @Override + protected boolean acceptsFeature(Server server) { + return server.isStarted(); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.java new file mode 100644 index 0000000..fb53ae7 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/completers/StoppedEndpointCompleter.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.karaf.commands.completers; + + +import org.apache.cxf.endpoint.Server; +import org.apache.karaf.shell.api.action.lifecycle.Service; + +@Service +public class StoppedEndpointCompleter extends EndpointCompleterSupport { + + + @Override + protected boolean acceptsFeature(Server server) { + return !server.isStarted(); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFController.java ---------------------------------------------------------------------- diff --git a/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFController.java b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFController.java new file mode 100644 index 0000000..0daf0e7 --- /dev/null +++ b/osgi/karaf4/commands/src/main/java/org/apache/cxf/karaf/commands/internal/CXFController.java @@ -0,0 +1,94 @@ +/** + * 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.karaf.commands.internal; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + + +import org.apache.cxf.Bus; +import org.apache.cxf.common.logging.LogUtils; +import org.apache.karaf.shell.api.action.lifecycle.Reference; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.ConfigurationAdmin; + + +/** + */ +public class CXFController { + private static final Logger LOG = LogUtils.getL7dLogger(CXFController.class); + + @Reference + private BundleContext bundleContext; + + @Reference + private ConfigurationAdmin configAdmin; + + public List<Bus> getBusses() { + List<Bus> busses = new ArrayList<Bus>(); + try { + ServiceReference[] references = bundleContext.getServiceReferences(Bus.class.getName(), null); + if (references != null) { + for (ServiceReference reference : references) { + if (reference != null) { + Bus bus = (Bus) bundleContext.getService(reference); + if (bus != null) { + busses.add(bus); + } + } + } + } + } catch (Exception e) { + LOG.log(Level.INFO, "Cannot retrieve the list of CXF Busses.", e); + } + return busses; + } + + public Bus getBus(String name) { + try { + ServiceReference[] references = bundleContext.getServiceReferences(Bus.class.getName(), null); + if (references != null) { + for (ServiceReference reference : references) { + if (reference != null + && name.equals(reference.getProperty("cxf.bus.id"))) { + return (Bus) bundleContext.getService(reference); + } + } + } + } catch (Exception e) { + LOG.log(Level.INFO, "Cannot retrieve the CXF Bus.", e); + return null; + } + LOG.log(Level.INFO, "Cannot retrieve the CXF Bus " + name + "."); + return null; + } + + public ConfigurationAdmin getConfigAdmin() { + return configAdmin; + } + + public BundleContext getBundleContext() { + return bundleContext; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/features/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/karaf4/features/pom.xml b/osgi/karaf4/features/pom.xml new file mode 100644 index 0000000..eaa2fce --- /dev/null +++ b/osgi/karaf4/features/pom.xml @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + <!-- + + 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. + --> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.cxf.karaf4</groupId> + <artifactId>karaf4-parent</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + <artifactId>apache-cxf</artifactId> + <packaging>pom</packaging> + <name>Apache CXF Karaf4 Features</name> + <description>Apache CXF Karaf4 Features</description> + <!-- The validate plugin will export these provided dependencies bundles' export packages first --> + <dependencies> + <!-- Framework distribution --> + <dependency> + <groupId>org.apache.karaf.features</groupId> + <artifactId>framework</artifactId> + <version>${cxf.karaf4.version}</version> + <type>kar</type> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.karaf.features</groupId> + <artifactId>standard</artifactId> + <version>${cxf.karaf4.version}</version> + <classifier>features</classifier> + <type>xml</type> + <scope>provided</scope> + </dependency> + </dependencies> + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>filter</id> + <phase>generate-resources</phase> + <goals> + <goal>resources</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>attach-artifacts</id> + <phase>package</phase> + <goals> + <goal>attach-artifact</goal> + </goals> + <configuration> + <artifacts> + <artifact> + <file>target/classes/features.xml</file> + <type>xml</type> + <classifier>features</classifier> + </artifact> + </artifacts> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.karaf.tooling</groupId> + <artifactId>karaf-maven-plugin</artifactId> + <version>${cxf.karaf4.version}</version> + <executions> + <execution> + <id>verify</id> + <phase>process-resources</phase> + <goals> + <goal>verify</goal> + </goals> + <configuration> + <descriptors> + <descriptor>mvn:org.apache.karaf.features/framework/${cxf.karaf4.version}/xml/features</descriptor> + <descriptor>mvn:org.apache.karaf.features/standard/${cxf.karaf4.version}/xml/features</descriptor> + <descriptor>mvn:org.apache.karaf.features/spring/${cxf.karaf4.version}/xml/features</descriptor> + <descriptor>file:${project.build.directory}/classes/features.xml</descriptor> + </descriptors> + <distribution>org.apache.karaf.features:framework</distribution> + <javase>1.8</javase> + <framework> + <feature>framework</feature> + </framework> + <features> + <!--<feature>cxf-*</feature>--> + <feature>cxf-management-web</feature> + <feature>cxf-wsn</feature> + </features> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/cxf/blob/042d1dbe/osgi/karaf4/features/src/main/resources/config.properties ---------------------------------------------------------------------- diff --git a/osgi/karaf4/features/src/main/resources/config.properties b/osgi/karaf4/features/src/main/resources/config.properties new file mode 100755 index 0000000..cb66f0a --- /dev/null +++ b/osgi/karaf4/features/src/main/resources/config.properties @@ -0,0 +1,334 @@ +################################################################################ +# +# 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. +# +################################################################################ + +# +# Framework config properties. +# +org.osgi.framework.system.packages=org.osgi.framework; version=1.5.0, \ + org.osgi.framework.launch; version=1.0.0, \ + org.osgi.framework.hooks.service; version=1.0.0, \ + org.osgi.service.packageadmin; version=1.2.0, \ + org.osgi.service.startlevel; version=1.1.0, \ + org.osgi.service.url; version=1.0.0, \ + org.osgi.util.tracker; version=1.3.0 \ + ${jre-${java.specification.version}} + +org.osgi.framework.bootdelegation=sun.*,com.sun*,javax.transaction,javax.transaction.* + +# Standard package set. Note that: +# - some com.sun.org.apache.* are exported +# - com.sun.jndi.ldap package is exported +# - javax.transaction* is exported with a mandatory attribute +jre-1.5=, \ + com.sun.org.apache.xalan.internal.xsltc.trax, \ + com.sun.org.apache.xerces.internal.dom, \ + com.sun.org.apache.xerces.internal.jaxp, \ + com.sun.org.apache.xerces.internal.xni, \ + com.sun.jndi.ldap, \ + javax.accessibility, \ + javax.activity, \ + javax.crypto, \ + javax.crypto.interfaces, \ + javax.crypto.spec, \ + javax.imageio, \ + javax.imageio.event, \ + javax.imageio.metadata, \ + javax.imageio.plugins.bmp, \ + javax.imageio.plugins.jpeg, \ + javax.imageio.spi, \ + javax.imageio.stream, \ + javax.management, \ + javax.management.loading, \ + javax.management.modelmbean, \ + javax.management.monitor, \ + javax.management.openmbean, \ + javax.management.relation, \ + javax.management.remote, \ + javax.management.remote.rmi, \ + javax.management.timer, \ + javax.naming, \ + javax.naming.directory, \ + javax.naming.event, \ + javax.naming.ldap, \ + javax.naming.spi, \ + javax.net, \ + javax.net.ssl, \ + javax.print, \ + javax.print.attribute, \ + javax.print.attribute.standard, \ + javax.print.event, \ + javax.rmi, \ + javax.rmi.CORBA, \ + javax.rmi.ssl, \ + javax.security.auth, \ + javax.security.auth.callback, \ + javax.security.auth.kerberos, \ + javax.security.auth.login, \ + javax.security.auth.spi, \ + javax.security.auth.x500, \ + javax.security.cert, \ + javax.security.sasl, \ + javax.sound.midi, \ + javax.sound.midi.spi, \ + javax.sound.sampled, \ + javax.sound.sampled.spi, \ + javax.sql, \ + javax.sql.rowset, \ + javax.sql.rowset.serial, \ + javax.sql.rowset.spi, \ + javax.swing, \ + javax.swing.border, \ + javax.swing.colorchooser, \ + javax.swing.event, \ + javax.swing.filechooser, \ + javax.swing.plaf, \ + javax.swing.plaf.basic, \ + javax.swing.plaf.metal, \ + javax.swing.plaf.multi, \ + javax.swing.plaf.synth, \ + javax.swing.table, \ + javax.swing.text, \ + javax.swing.text.html, \ + javax.swing.text.html.parser, \ + javax.swing.text.rtf, \ + javax.swing.tree, \ + javax.swing.undo, \ + javax.transaction; javax.transaction.xa; partial=true; mandatory:=partial, \ + javax.xml, \ + javax.xml.datatype, \ + javax.xml.namespace, \ + javax.xml.parsers, \ + javax.xml.transform, \ + javax.xml.transform.dom, \ + javax.xml.transform.sax, \ + javax.xml.transform.stream, \ + javax.xml.validation, \ + javax.xml.xpath, \ + org.ietf.jgss, \ + org.omg.CORBA, \ + org.omg.CORBA_2_3, \ + org.omg.CORBA_2_3.portable, \ + org.omg.CORBA.DynAnyPackage, \ + org.omg.CORBA.ORBPackage, \ + org.omg.CORBA.portable, \ + org.omg.CORBA.TypeCodePackage, \ + org.omg.CosNaming, \ + org.omg.CosNaming.NamingContextExtPackage, \ + org.omg.CosNaming.NamingContextPackage, \ + org.omg.Dynamic, \ + org.omg.DynamicAny, \ + org.omg.DynamicAny.DynAnyFactoryPackage, \ + org.omg.DynamicAny.DynAnyPackage, \ + org.omg.IOP, \ + org.omg.IOP.CodecFactoryPackage, \ + org.omg.IOP.CodecPackage, \ + org.omg.Messaging, \ + org.omg.PortableInterceptor, \ + org.omg.PortableInterceptor.ORBInitInfoPackage, \ + org.omg.PortableServer, \ + org.omg.PortableServer.CurrentPackage, \ + org.omg.PortableServer.POAManagerPackage, \ + org.omg.PortableServer.POAPackage, \ + org.omg.PortableServer.portable, \ + org.omg.PortableServer.ServantLocatorPackage, \ + org.omg.SendingContext, \ + org.omg.stub.java.rmi, \ + org.omg.stub.javax.management.remote.rmi, \ + org.w3c.dom, \ + org.w3c.dom.bootstrap, \ + org.w3c.dom.css, \ + org.w3c.dom.events, \ + org.w3c.dom.html, \ + org.w3c.dom.ls, \ + org.w3c.dom.ranges, \ + org.w3c.dom.stylesheets, \ + org.w3c.dom.traversal, \ + org.w3c.dom.views, \ + org.xml.sax, \ + org.xml.sax.ext, \ + org.xml.sax.helpers + +# Standard package set. Note that: +# - some com.sun.org.apache.* are exported +# - com.sun.jndi.ldap package is exported +# - javax.transaction* is exported with a mandatory attribute +# - javax.activation, javax.annotation*, javax.jws*, javax.script*, javax.xml.bind*, javax.xml.soap, javax.xml.ws* packages are not exported +jre-1.6=, \ + com.sun.org.apache.xalan.internal.xsltc.trax, \ + com.sun.org.apache.xerces.internal.dom, \ + com.sun.org.apache.xerces.internal.jaxp, \ + com.sun.org.apache.xerces.internal.xni, \ + com.sun.jndi.ldap, \ + javax.accessibility, \ +# javax.activation, \ + javax.activity, \ +# javax.annotation, \ +# javax.annotation.processing, \ + javax.crypto, \ + javax.crypto.interfaces, \ + javax.crypto.spec, \ + javax.imageio, \ + javax.imageio.event, \ + javax.imageio.metadata, \ + javax.imageio.plugins.bmp, \ + javax.imageio.plugins.jpeg, \ + javax.imageio.spi, \ + javax.imageio.stream, \ +# javax.jws, \ +# javax.jws.soap, \ + javax.lang.model, \ + javax.lang.model.element, \ + javax.lang.model.type, \ + javax.lang.model.util, \ + javax.management, \ + javax.management.loading, \ + javax.management.modelmbean, \ + javax.management.monitor, \ + javax.management.openmbean, \ + javax.management.relation, \ + javax.management.remote, \ + javax.management.remote.rmi, \ + javax.management.timer, \ + javax.naming, \ + javax.naming.directory, \ + javax.naming.event, \ + javax.naming.ldap, \ + javax.naming.spi, \ + javax.net, \ + javax.net.ssl, \ + javax.print, \ + javax.print.attribute, \ + javax.print.attribute.standard, \ + javax.print.event, \ + javax.rmi, \ + javax.rmi.CORBA, \ + javax.rmi.ssl, \ + javax.script, \ + javax.security.auth, \ + javax.security.auth.callback, \ + javax.security.auth.kerberos, \ + javax.security.auth.login, \ + javax.security.auth.spi, \ + javax.security.auth.x500, \ + javax.security.cert, \ + javax.security.sasl, \ + javax.sound.midi, \ + javax.sound.midi.spi, \ + javax.sound.sampled, \ + javax.sound.sampled.spi, \ + javax.sql, \ + javax.sql.rowset, \ + javax.sql.rowset.serial, \ + javax.sql.rowset.spi, \ + javax.swing, \ + javax.swing.border, \ + javax.swing.colorchooser, \ + javax.swing.event, \ + javax.swing.filechooser, \ + javax.swing.plaf, \ + javax.swing.plaf.basic, \ + javax.swing.plaf.metal, \ + javax.swing.plaf.multi, \ + javax.swing.plaf.synth, \ + javax.swing.table, \ + javax.swing.text, \ + javax.swing.text.html, \ + javax.swing.text.html.parser, \ + javax.swing.text.rtf, \ + javax.swing.tree, \ + javax.swing.undo, \ + javax.tools, \ + javax.transaction; javax.transaction.xa; partial=true; mandatory:=partial, \ + javax.xml, \ +# javax.xml.bind, \ +# javax.xml.bind.annotation, \ +# javax.xml.bind.annotation.adapters, \ +# javax.xml.bind.attachment, \ +# javax.xml.bind.helpers, \ +# javax.xml.bind.util, \ + javax.xml.crypto, \ + javax.xml.crypto.dom, \ + javax.xml.crypto.dsig, \ + javax.xml.crypto.dsig.dom, \ + javax.xml.crypto.dsig.keyinfo, \ + javax.xml.crypto.dsig.spec, \ + javax.xml.datatype, \ + javax.xml.namespace, \ + javax.xml.parsers, \ +# javax.xml.soap, \ +# javax.xml.stream, \ +# javax.xml.stream.events, \ +# javax.xml.stream.util, \ + javax.xml.transform, \ + javax.xml.transform.dom, \ + javax.xml.transform.sax, \ + javax.xml.transform.stax, \ + javax.xml.transform.stream, \ + javax.xml.validation, \ +# javax.xml.ws, \ +# javax.xml.ws.handler, \ +# javax.xml.ws.handler.soap, \ +# javax.xml.ws.http, \ +# javax.xml.ws.soap, \ +# javax.xml.ws.spi, \ + javax.xml.xpath, \ + org.ietf.jgss, \ + org.omg.CORBA, \ + org.omg.CORBA_2_3, \ + org.omg.CORBA_2_3.portable, \ + org.omg.CORBA.DynAnyPackage, \ + org.omg.CORBA.ORBPackage, \ + org.omg.CORBA.portable, \ + org.omg.CORBA.TypeCodePackage, \ + org.omg.CosNaming, \ + org.omg.CosNaming.NamingContextExtPackage, \ + org.omg.CosNaming.NamingContextPackage, \ + org.omg.Dynamic, \ + org.omg.DynamicAny, \ + org.omg.DynamicAny.DynAnyFactoryPackage, \ + org.omg.DynamicAny.DynAnyPackage, \ + org.omg.IOP, \ + org.omg.IOP.CodecFactoryPackage, \ + org.omg.IOP.CodecPackage, \ + org.omg.Messaging, \ + org.omg.PortableInterceptor, \ + org.omg.PortableInterceptor.ORBInitInfoPackage, \ + org.omg.PortableServer, \ + org.omg.PortableServer.CurrentPackage, \ + org.omg.PortableServer.POAManagerPackage, \ + org.omg.PortableServer.POAPackage, \ + org.omg.PortableServer.portable, \ + org.omg.PortableServer.ServantLocatorPackage, \ + org.omg.SendingContext, \ + org.omg.stub.java.rmi, \ + org.omg.stub.javax.management.remote.rmi, \ + org.w3c.dom, \ + org.w3c.dom.bootstrap, \ + org.w3c.dom.css, \ + org.w3c.dom.events, \ + org.w3c.dom.html, \ + org.w3c.dom.ls, \ + org.w3c.dom.ranges, \ + org.w3c.dom.stylesheets, \ + org.w3c.dom.traversal, \ + org.w3c.dom.views, \ + org.w3c.dom.xpath, \ + org.xml.sax, \ + org.xml.sax.ext, \ + org.xml.sax.helpers