You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2018/10/11 14:00:33 UTC
[1/2] activemq git commit: [AMQ-7063] Be able to configure ActiveMQ
http transport connector by providing a jetty.xml
Repository: activemq
Updated Branches:
refs/heads/master a311139bf -> bdf9fcf5a
[AMQ-7063] Be able to configure ActiveMQ http transport connector by providing a jetty.xml
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/ba2447e3
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/ba2447e3
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/ba2447e3
Branch: refs/heads/master
Commit: ba2447e39ad513ff1a37833887cfd2e9bf49a0b5
Parents: a311139
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Thu Oct 11 09:18:32 2018 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Thu Oct 11 14:47:05 2018 +0200
----------------------------------------------------------------------
.../transport/WebTransportServerSupport.java | 67 +++++++++++++++++---
.../transport/http/HttpTransportFactory.java | 2 +
.../http/HttpJettyConfigurationTest.java | 49 ++++++++++++++
activemq-http/src/test/resources/jetty.xml | 22 +++++++
4 files changed, 132 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/ba2447e3/activemq-http/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java b/activemq-http/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
index 7f2ce7e..eba63ab 100644
--- a/activemq-http/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
+++ b/activemq-http/src/main/java/org/apache/activemq/transport/WebTransportServerSupport.java
@@ -16,6 +16,7 @@
*/
package org.apache.activemq.transport;
+import java.io.File;
import java.net.InetAddress;
import java.net.URI;
import java.util.Map;
@@ -27,15 +28,21 @@ import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.security.Constraint;
+import org.eclipse.jetty.xml.XmlConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
abstract public class WebTransportServerSupport extends TransportServerSupport {
+ private final static Logger LOG = LoggerFactory.getLogger(WebTransportServerSupport.class);
+
protected URI bindAddress;
protected Server server;
protected Connector connector;
protected SocketConnectorFactory socketConnectorFactory;
protected String host;
protected final HttpOptions httpOptions = new HttpOptions();
+ protected final JettyOptions jettyOptions = new JettyOptions();
public WebTransportServerSupport(URI location) {
super(location);
@@ -46,7 +53,22 @@ abstract public class WebTransportServerSupport extends TransportServerSupport {
}
protected void createServer() {
- server = new Server();
+ LOG.info("Starting Jetty server");
+ if (jettyOptions.getConfig() != null) {
+ try {
+ LOG.info("Configuring Jetty server using {}", jettyOptions.getConfig());
+ File file = new File(jettyOptions.getConfig());
+ if (!file.exists()) {
+ throw new IllegalArgumentException("Jetty XML not found: " + file.getAbsolutePath());
+ }
+ XmlConfiguration xmlConfiguration = new XmlConfiguration(file.toURI().toURL());
+ server = (Server) xmlConfiguration.configure();
+ } catch (Throwable t) {
+ throw new IllegalStateException("Jetty configuration can't be loaded", t);
+ }
+ } else {
+ server = new Server();
+ }
try {
server.getClass().getMethod("setStopTimeout", Long.TYPE).invoke(server, 500l);
} catch (Throwable t) {
@@ -55,21 +77,31 @@ abstract public class WebTransportServerSupport extends TransportServerSupport {
}
public URI bind() throws Exception {
-
URI bind = getBindLocation();
-
String bindHost = bind.getHost();
bindHost = (bindHost == null || bindHost.length() == 0) ? "localhost" : bindHost;
InetAddress addr = InetAddress.getByName(bindHost);
host = addr.getCanonicalHostName();
-
- setConnectorProperty("Host", String.class, host);
- setConnectorProperty("Port", Integer.TYPE, bindAddress.getPort());
- server.addConnector(connector);
+ if (server.getConnectors().length == 0) {
+ LOG.info("Creating Jetty connector");
+ setConnectorProperty("Host", String.class, host);
+ setConnectorProperty("Port", Integer.TYPE, bindAddress.getPort());
+ server.addConnector(connector);
+ } else {
+ LOG.info("Using Jetty configured connector");
+ connector = server.getConnectors()[0];
+ for (Connector c : server.getConnectors()) {
+ if (c.getName() != null && c.getName().equalsIgnoreCase("activemq")) {
+ connector = c;
+ }
+ }
+ setConnectorProperty("Host", String.class, host);
+ setConnectorProperty("Port", Integer.TYPE, bindAddress.getPort());
+ server.addConnector(connector);
+ }
if (addr.isAnyLocalAddress()) {
host = InetAddressUtil.getLocalHostName();
}
-
URI boundUri = new URI(bind.getScheme(), bind.getUserInfo(), host, bindAddress.getPort(), bind.getPath(), bind.getQuery(), bind.getFragment());
setConnectURI(boundUri);
return boundUri;
@@ -94,6 +126,12 @@ abstract public class WebTransportServerSupport extends TransportServerSupport {
}
}
+ public void setJettyOptions(Map<String, Object> options) {
+ if (options != null) {
+ IntrospectionSupport.setProperties(this.jettyOptions, options);
+ }
+ }
+
protected static class HttpOptions {
private boolean enableTrace = false;
@@ -105,4 +143,17 @@ abstract public class WebTransportServerSupport extends TransportServerSupport {
this.enableTrace = enableTrace;
}
}
+
+ protected static class JettyOptions {
+ private String config;
+
+ public String getConfig() {
+ return config;
+ }
+
+ public void setConfig(String config) {
+ this.config = config;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/activemq/blob/ba2447e3/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
index 8332a95..02ecf77 100644
--- a/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
+++ b/activemq-http/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
@@ -45,8 +45,10 @@ public class HttpTransportFactory extends TransportFactory {
try {
Map<String, String> options = new HashMap<String, String>(URISupport.parseParameters(location));
HttpTransportServer result = new HttpTransportServer(location, this);
+ Map<String, Object> jettyOptions = IntrospectionSupport.extractProperties(options, "jetty.");
Map<String, Object> httpOptions = IntrospectionSupport.extractProperties(options, "http.");
Map<String, Object> transportOptions = IntrospectionSupport.extractProperties(options, "transport.");
+ result.setJettyOptions(jettyOptions);
result.setTransportOption(transportOptions);
result.setHttpOptions(httpOptions);
return result;
http://git-wip-us.apache.org/repos/asf/activemq/blob/ba2447e3/activemq-http/src/test/java/org/apache/activemq/transport/http/HttpJettyConfigurationTest.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/http/HttpJettyConfigurationTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/http/HttpJettyConfigurationTest.java
new file mode 100644
index 0000000..363dd4e
--- /dev/null
+++ b/activemq-http/src/test/java/org/apache/activemq/transport/http/HttpJettyConfigurationTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.activemq.transport.http;
+
+import org.apache.activemq.broker.BrokerService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HttpJettyConfigurationTest {
+
+ private BrokerService brokerService;
+
+ @Before
+ public void setUp() throws Exception {
+ brokerService = new BrokerService();
+ brokerService.setPersistent(false);
+ brokerService.setUseJmx(false);
+ brokerService.deleteAllMessages();
+ brokerService.addConnector("http://0.0.0.0:0?jetty.config=src/test/resources/jetty.xml");
+ brokerService.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ brokerService.stop();
+ }
+
+ @Test
+ public void test() throws Exception {
+ // nothing to do
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq/blob/ba2447e3/activemq-http/src/test/resources/jetty.xml
----------------------------------------------------------------------
diff --git a/activemq-http/src/test/resources/jetty.xml b/activemq-http/src/test/resources/jetty.xml
new file mode 100644
index 0000000..e6764fd
--- /dev/null
+++ b/activemq-http/src/test/resources/jetty.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+<Configure id="server" class="org.eclipse.jetty.server.Server">
+
+ <Arg>
+ <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
+ <Set name="minThreads">10</Set>
+ <Set name="maxThreads">1000</Set>
+ </New>
+ </Arg>
+
+ <Call name="addConnector">
+ <Arg>
+ <New id="activemq" class="org.eclipse.jetty.server.ServerConnector">
+ <Arg name="server"><Ref refid="server"/></Arg>
+ <Arg name="acceptors" type="int"><Property name="jetty.http.acceptors" default="-1"/></Arg>
+ <Arg name="selectors" type="int"><Property name="jetty.http.selectors" default="-1"/></Arg>
+ </New>
+ </Arg>
+ </Call>
+
+</Configure>
\ No newline at end of file
[2/2] activemq git commit: [AMQ-7063] This closes #307
Posted by jb...@apache.org.
[AMQ-7063] This closes #307
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/bdf9fcf5
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/bdf9fcf5
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/bdf9fcf5
Branch: refs/heads/master
Commit: bdf9fcf5a815520689b11ea3519a9966f9d1cc5a
Parents: a311139 ba2447e
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Thu Oct 11 16:00:23 2018 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Thu Oct 11 16:00:23 2018 +0200
----------------------------------------------------------------------
.../transport/WebTransportServerSupport.java | 67 +++++++++++++++++---
.../transport/http/HttpTransportFactory.java | 2 +
.../http/HttpJettyConfigurationTest.java | 49 ++++++++++++++
activemq-http/src/test/resources/jetty.xml | 22 +++++++
4 files changed, 132 insertions(+), 8 deletions(-)
----------------------------------------------------------------------