├── .gitignore ├── LICENSE ├── README.md ├── example └── simple_request.jmx ├── pom.xml └── src └── main └── java └── jmeter └── plugins └── http2 └── sampler ├── HTTP2Sampler.java ├── Http2ClientInitializer.java ├── Http2SettingsHandler.java ├── HttpResponseHandler.java ├── NettyHttp2Client.java └── gui └── HTTP2SamplerGui.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jmeter-http2-plugin 2 | 3 | Jmeter HTTP/2 sampler 4 | 5 | ## Dependencies 6 | 7 | * [Netty 5 and netty-tcnative](http://netty.io/) 8 | * [hpack](https://github.com/twitter/hpack) 9 | 10 | ## Quickstart 11 | 12 | 1. Build Netty 5 (Alpha3+) and netty-tcnative for your platform 13 | 14 | 2. Copy HTTP2Sampler.jar, netty-all.jar, netty-tcnative.jar and hpack.jar to lib/ext of jmeter directory 15 | 16 | * If you use gzip encoding, you must prepare jzlib.jar too. 17 | 18 | 3. Run JMeter 19 | 20 | 4. Write your test scenario with HTTP2Sampler 21 | 22 | ## License 23 | 24 | Apache License 2.0 25 | -------------------------------------------------------------------------------- /example/simple_request.jmx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | continue 16 | 17 | false 18 | 1 19 | 20 | 1 21 | 1 22 | 1435427934000 23 | 1435427934000 24 | false 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | accept 33 | */* 34 | 35 | 36 | accept-encoding 37 | gzip 38 | 39 | 40 | accept-encoding 41 | deflate 42 | 43 | 44 | user-agent 45 | ApacheJMeterHTTP2Sampler 46 | 47 | 48 | 49 | 50 | 51 | GET 52 | 127.0.0.1 53 | 4430 54 | / 55 | 56 | 57 | 58 | 59 | 200 60 | 61 | Assertion.response_code 62 | false 63 | 1 64 | 65 | 66 | 67 | false 68 | 69 | saveConfig 70 | 71 | 72 | true 73 | true 74 | true 75 | 76 | true 77 | true 78 | true 79 | true 80 | false 81 | true 82 | true 83 | false 84 | false 85 | true 86 | false 87 | false 88 | false 89 | false 90 | false 91 | 0 92 | true 93 | true 94 | true 95 | 96 | 97 | result.jtl 98 | 99 | 100 | 101 | false 102 | 103 | saveConfig 104 | 105 | 106 | true 107 | true 108 | true 109 | 110 | true 111 | true 112 | true 113 | true 114 | false 115 | true 116 | true 117 | false 118 | false 119 | false 120 | false 121 | false 122 | false 123 | false 124 | false 125 | 0 126 | true 127 | true 128 | 129 | 130 | 131 | true 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | jmeter.plugins.http2.sampler 6 | HTTP2Sampler 7 | jar 8 | 1.0-SNAPSHOT 9 | HTTP/2 Sampler as JMeter plugin 10 | 11 | 12 | 13 | org.apache.jmeter 14 | ApacheJMeter_core 15 | 2.11 16 | test 17 | 18 | 19 | 20 | org.apache.jmeter 21 | jorphan 22 | 2.11 23 | test 24 | 25 | 26 | 27 | io.netty 28 | netty-all 29 | 5.0.0.Alpha2 30 | test 31 | 32 | 33 | 34 | io.netty 35 | netty-tcnative 36 | 1.1.33.Fork3 37 | test 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/HTTP2Sampler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Ryo Okubo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jmeter.plugins.http2.sampler; 17 | 18 | import java.net.InetSocketAddress; 19 | import java.util.concurrent.Phaser; 20 | import java.util.concurrent.TimeUnit; 21 | 22 | import org.apache.jmeter.protocol.http.control.HeaderManager; 23 | import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; 24 | import org.apache.jmeter.samplers.AbstractSampler; 25 | import org.apache.jmeter.samplers.Entry; 26 | import org.apache.jmeter.samplers.SampleResult; 27 | import org.apache.jmeter.testelement.TestElement; 28 | import org.apache.jmeter.testelement.property.*; 29 | import org.apache.jorphan.logging.LoggingManager; 30 | import org.apache.log.Logger; 31 | 32 | public class HTTP2Sampler extends AbstractSampler { 33 | 34 | private static final Logger log = LoggingManager.getLoggerForClass(); 35 | 36 | public static final String METHOD = "HTTP2Sampler.method"; 37 | public static final String DOMAIN = "HTTP2Sampler.domain"; 38 | public static final String PORT = "HTTP2Sampler.port"; 39 | public static final String PATH = "HTTP2Sampler.path"; 40 | 41 | public static final String DEFAULT_METHOD = "GET"; 42 | 43 | public HTTP2Sampler() { 44 | super(); 45 | setName("HTTP2 Sampler"); 46 | } 47 | 48 | @Override 49 | public void setName(String name) { 50 | if (name != null) { 51 | setProperty(TestElement.NAME, name); 52 | } 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | return getPropertyAsString(TestElement.NAME); 58 | } 59 | 60 | @Override 61 | public void addTestElement(TestElement el) { 62 | if (el instanceof HeaderManager) { 63 | HeaderManager value = (HeaderManager) el; 64 | HeaderManager currentHeaderManager = getHeaderManager(); 65 | if (currentHeaderManager != null) { 66 | value = currentHeaderManager.merge(value, true); 67 | } 68 | setProperty(new TestElementProperty(HTTPSamplerBase.HEADER_MANAGER, value)); 69 | } else { 70 | super.addTestElement(el); 71 | } 72 | } 73 | 74 | @Override 75 | public SampleResult sample(Entry e) 76 | { 77 | log.debug("sample()"); 78 | 79 | // Load test elements 80 | HeaderManager headerManager = (HeaderManager)getProperty(HTTPSamplerBase.HEADER_MANAGER).getObjectValue(); 81 | 82 | // Send H2 request 83 | NettyHttp2Client client = new NettyHttp2Client(getMethod(), getDomain(), getPort(), getPath(), headerManager); 84 | SampleResult res = client.request(); 85 | res.setSampleLabel(getName()); 86 | 87 | return res; 88 | } 89 | 90 | public void setMethod(String value) { 91 | setProperty(METHOD, value); 92 | } 93 | 94 | public String getMethod() { 95 | return getPropertyAsString(METHOD); 96 | } 97 | 98 | public void setDomain(String value) { 99 | setProperty(DOMAIN, value); 100 | } 101 | 102 | public String getDomain() { 103 | return getPropertyAsString(DOMAIN); 104 | } 105 | 106 | public void setPort(int value) { 107 | setProperty(PORT, value); 108 | } 109 | 110 | public int getPort() { 111 | return getPropertyAsInt(PORT); 112 | } 113 | 114 | public void setPath(String value) { 115 | setProperty(PATH, value); 116 | } 117 | 118 | public String getPath() { 119 | return getPropertyAsString(PATH); 120 | } 121 | 122 | private HeaderManager getHeaderManager() { 123 | return (HeaderManager)getProperty(HTTPSamplerBase.HEADER_MANAGER).getObjectValue(); 124 | } 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/Http2ClientInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was copied from HTTP/2 client examples of the Netty repository and modified only package name. 3 | */ 4 | 5 | /* 6 | * Copyright 2014 The Netty Project 7 | * 8 | * The Netty Project licenses this file to you under the Apache License, version 2.0 (the 9 | * "License"); you may not use this file except in compliance with the License. You may obtain a 10 | * copy of the License at: 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software distributed under the License 15 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 16 | * or implied. See the License for the specific language governing permissions and limitations under 17 | * the License. 18 | */ 19 | package jmeter.plugins.http2.sampler; 20 | 21 | import static io.netty.handler.logging.LogLevel.INFO; 22 | 23 | import io.netty.channel.ChannelFuture; 24 | import io.netty.channel.ChannelHandlerAdapter; 25 | import io.netty.channel.ChannelHandlerContext; 26 | import io.netty.channel.ChannelInitializer; 27 | import io.netty.channel.ChannelPipeline; 28 | import io.netty.channel.ChannelPromise; 29 | import io.netty.channel.socket.SocketChannel; 30 | import io.netty.handler.codec.http.DefaultFullHttpRequest; 31 | import io.netty.handler.codec.http.HttpClientCodec; 32 | import io.netty.handler.codec.http.HttpClientUpgradeHandler; 33 | import io.netty.handler.codec.http.HttpMethod; 34 | import io.netty.handler.codec.http.HttpVersion; 35 | import io.netty.handler.codec.http2.DefaultHttp2Connection; 36 | import io.netty.handler.codec.http2.DefaultHttp2FrameReader; 37 | import io.netty.handler.codec.http2.DefaultHttp2FrameWriter; 38 | import io.netty.handler.codec.http2.DelegatingDecompressorFrameListener; 39 | import io.netty.handler.codec.http2.Http2ClientUpgradeCodec; 40 | import io.netty.handler.codec.http2.Http2Connection; 41 | import io.netty.handler.codec.http2.Http2ConnectionHandler; 42 | import io.netty.handler.codec.http2.Http2FrameLogger; 43 | import io.netty.handler.codec.http2.Http2FrameReader; 44 | import io.netty.handler.codec.http2.Http2FrameWriter; 45 | import io.netty.handler.codec.http2.Http2InboundFrameLogger; 46 | import io.netty.handler.codec.http2.Http2OutboundFrameLogger; 47 | import io.netty.handler.codec.http2.Http2Settings; 48 | import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler; 49 | import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapter; 50 | import io.netty.handler.ssl.SslContext; 51 | 52 | /** 53 | * Configures the client pipeline to support HTTP/2 frames. 54 | */ 55 | public class Http2ClientInitializer extends ChannelInitializer { 56 | private static final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2ClientInitializer.class); 57 | 58 | private final SslContext sslCtx; 59 | private final int maxContentLength; 60 | /* private HttpToHttp2ConnectionHandler connectionHandler; */ 61 | private Http2ConnectionHandler connectionHandler; 62 | private HttpResponseHandler responseHandler; 63 | private Http2SettingsHandler settingsHandler; 64 | 65 | public Http2ClientInitializer(SslContext sslCtx, int maxContentLength) { 66 | this.sslCtx = sslCtx; 67 | this.maxContentLength = maxContentLength; 68 | } 69 | 70 | @Override 71 | public void initChannel(SocketChannel ch) throws Exception { 72 | final Http2Connection connection = new DefaultHttp2Connection(false); 73 | 74 | connectionHandler = new HttpToHttp2ConnectionHandler(connection, 75 | frameReader(), 76 | frameWriter(), 77 | new DelegatingDecompressorFrameListener(connection, 78 | new InboundHttp2ToHttpAdapter.Builder(connection) 79 | .maxContentLength(maxContentLength) 80 | .propagateSettings(true) 81 | .build())); 82 | responseHandler = new HttpResponseHandler(); 83 | settingsHandler = new Http2SettingsHandler(ch.newPromise()); 84 | if (sslCtx != null) { 85 | configureSsl(ch); 86 | } else { 87 | configureClearText(ch); 88 | } 89 | } 90 | 91 | public HttpResponseHandler responseHandler() { 92 | return responseHandler; 93 | } 94 | 95 | public Http2SettingsHandler settingsHandler() { 96 | return settingsHandler; 97 | } 98 | 99 | protected void configureEndOfPipeline(ChannelPipeline pipeline) { 100 | pipeline.addLast("Http2SettingsHandler", settingsHandler); 101 | pipeline.addLast("HttpResponseHandler", responseHandler); 102 | } 103 | 104 | /** 105 | * Configure the pipeline for TLS NPN negotiation to HTTP/2. 106 | */ 107 | private void configureSsl(SocketChannel ch) { 108 | ChannelPipeline pipeline = ch.pipeline(); 109 | pipeline.addLast("SslHandler", sslCtx.newHandler(ch.alloc())); 110 | pipeline.addLast("Http2Handler", connectionHandler); 111 | configureEndOfPipeline(pipeline); 112 | } 113 | 114 | /** 115 | * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. 116 | */ 117 | private void configureClearText(SocketChannel ch) { 118 | HttpClientCodec sourceCodec = new HttpClientCodec(); 119 | Http2ClientUpgradeCodec upgradeCodec = new Http2ClientUpgradeCodec(connectionHandler); 120 | HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 65536); 121 | 122 | ch.pipeline().addLast("Http2SourceCodec", sourceCodec); 123 | ch.pipeline().addLast("Http2UpgradeHandler", upgradeHandler); 124 | ch.pipeline().addLast("Http2UpgradeRequestHandler", new UpgradeRequestHandler()); 125 | ch.pipeline().addLast("Logger", new UserEventLogger()); 126 | } 127 | 128 | /** 129 | * A handler that triggers the cleartext upgrade to HTTP/2 by sending an initial HTTP request. 130 | */ 131 | private final class UpgradeRequestHandler extends ChannelHandlerAdapter { 132 | @Override 133 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 134 | DefaultFullHttpRequest upgradeRequest = 135 | new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); 136 | ctx.writeAndFlush(upgradeRequest); 137 | 138 | super.channelActive(ctx); 139 | 140 | // Done with this handler, remove it from the pipeline. 141 | ctx.pipeline().remove(this); 142 | 143 | Http2ClientInitializer.this.configureEndOfPipeline(ctx.pipeline()); 144 | } 145 | } 146 | 147 | /** 148 | * Class that logs any User Events triggered on this channel. 149 | */ 150 | private static class UserEventLogger extends ChannelHandlerAdapter { 151 | @Override 152 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 153 | System.out.println("User Event Triggered: " + evt); 154 | super.userEventTriggered(ctx, evt); 155 | } 156 | } 157 | 158 | private Http2FrameReader frameReader() { 159 | return new Http2InboundFrameLogger(new DefaultHttp2FrameReader(), logger); 160 | } 161 | 162 | private Http2FrameWriter frameWriter() { 163 | // Set initial SETTINGS 164 | Http2Settings settings = new Http2Settings(); 165 | settings.pushEnabled(false); 166 | settings.maxConcurrentStreams(100); 167 | 168 | return new Http2OutboundFrameLogger(new CustomHttp2FrameWriter(settings), logger); 169 | } 170 | 171 | /** 172 | * Custom HTTP/2 frame writer. 173 | */ 174 | private class CustomHttp2FrameWriter extends DefaultHttp2FrameWriter { 175 | private final Http2Settings settings; 176 | 177 | public CustomHttp2FrameWriter(Http2Settings settings) { 178 | this.settings = settings; 179 | } 180 | 181 | /** 182 | * write customized SETTINGS 183 | */ 184 | @Override 185 | public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings, ChannelPromise promise) { 186 | if(this.settings != null) { 187 | return super.writeSettings(ctx, this.settings, promise); 188 | } else { 189 | return super.writeSettings(ctx, settings, promise); 190 | } 191 | } 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/Http2SettingsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was copied from HTTP/2 client examples of the Netty repository and modified only package name. 3 | */ 4 | 5 | /* 6 | * Copyright 2014 The Netty Project 7 | * 8 | * The Netty Project licenses this file to you under the Apache License, version 2.0 (the 9 | * "License"); you may not use this file except in compliance with the License. You may obtain a 10 | * copy of the License at: 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software distributed under the License 15 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 16 | * or implied. See the License for the specific language governing permissions and limitations under 17 | * the License. 18 | */ 19 | package jmeter.plugins.http2.sampler; 20 | 21 | import io.netty.channel.ChannelHandlerContext; 22 | import io.netty.channel.ChannelPromise; 23 | import io.netty.channel.SimpleChannelInboundHandler; 24 | import io.netty.handler.codec.http2.Http2Settings; 25 | import java.util.concurrent.TimeUnit; 26 | 27 | /** 28 | * Reads the first {@link Http2Settings} object and notifies a {@link ChannelPromise} 29 | */ 30 | public class Http2SettingsHandler extends SimpleChannelInboundHandler { 31 | private ChannelPromise promise; 32 | 33 | /** 34 | * Create new instance 35 | * 36 | * @param promise Promise object used to notify when first settings are received 37 | */ 38 | public Http2SettingsHandler(ChannelPromise promise) { 39 | this.promise = promise; 40 | } 41 | 42 | /** 43 | * Wait for this handler to be added after the upgrade to HTTP/2, and for initial preface 44 | * handshake to complete. 45 | * 46 | * @param timeout Time to wait 47 | * @param unit {@link TimeUnit} for {@code timeout} 48 | * @throws Exception if timeout or other failure occurs 49 | */ 50 | public void awaitSettings(long timeout, TimeUnit unit) throws Exception { 51 | if (!promise.awaitUninterruptibly(timeout, unit)) { 52 | throw new IllegalStateException("Timed out waiting for settings"); 53 | } 54 | if (!promise.isSuccess()) { 55 | throw new RuntimeException(promise.cause()); 56 | } 57 | } 58 | 59 | @Override 60 | protected void messageReceived(ChannelHandlerContext ctx, Http2Settings msg) throws Exception { 61 | promise.setSuccess(); 62 | 63 | // Only care about the first settings message 64 | ctx.pipeline().remove(this); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/HttpResponseHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was copied from HTTP/2 client examples of the Netty repository and modified only package name. 3 | */ 4 | 5 | /* 6 | * Copyright 2014 The Netty Project 7 | * 8 | * The Netty Project licenses this file to you under the Apache License, version 2.0 (the 9 | * "License"); you may not use this file except in compliance with the License. You may obtain a 10 | * copy of the License at: 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software distributed under the License 15 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 16 | * or implied. See the License for the specific language governing permissions and limitations under 17 | * the License. 18 | */ 19 | package jmeter.plugins.http2.sampler; 20 | 21 | import io.netty.buffer.ByteBuf; 22 | import io.netty.channel.ChannelHandlerContext; 23 | import io.netty.channel.ChannelPromise; 24 | import io.netty.channel.SimpleChannelInboundHandler; 25 | import io.netty.handler.codec.http.FullHttpResponse; 26 | import io.netty.handler.codec.http2.HttpUtil; 27 | import io.netty.util.CharsetUtil; 28 | 29 | import java.util.Iterator; 30 | import java.util.Map.Entry; 31 | import java.util.SortedMap; 32 | import java.util.TreeMap; 33 | import java.util.concurrent.TimeUnit; 34 | 35 | /** 36 | * Process {@link FullHttpResponse} translated from HTTP/2 frames 37 | */ 38 | public class HttpResponseHandler extends SimpleChannelInboundHandler { 39 | 40 | private SortedMap streamidPromiseMap; 41 | private SortedMap streamidResponseMap; 42 | 43 | public HttpResponseHandler() { 44 | streamidPromiseMap = new TreeMap(); 45 | streamidResponseMap = new TreeMap(); 46 | } 47 | 48 | /** 49 | * Create an association between an anticipated response stream id and a {@link ChannelPromise} 50 | * 51 | * @param streamId The stream for which a response is expected 52 | * @param promise The promise object that will be used to wait/notify events 53 | * @return The previous object associated with {@code streamId} 54 | * @see HttpResponseHandler#awaitResponses(long, TimeUnit) 55 | */ 56 | public ChannelPromise put(int streamId, ChannelPromise promise) { 57 | return streamidPromiseMap.put(streamId, promise); 58 | } 59 | 60 | /** 61 | * Wait (sequentially) for a time duration for each anticipated response 62 | * 63 | * @param timeout Value of time to wait for each response 64 | * @param unit Units associated with {@code timeout} 65 | * @see HttpResponseHandler#put(int, ChannelPromise) 66 | */ 67 | public SortedMap awaitResponses(long timeout, TimeUnit unit) { 68 | Iterator> itr = streamidPromiseMap.entrySet().iterator(); 69 | 70 | while (itr.hasNext()) { 71 | Entry entry = itr.next(); 72 | ChannelPromise promise = entry.getValue(); 73 | if (!promise.awaitUninterruptibly(timeout, unit)) { 74 | throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey()); 75 | } 76 | if (!promise.isSuccess()) { 77 | throw new RuntimeException(promise.cause()); 78 | } 79 | System.out.println("---Stream id: " + entry.getKey() + " received---"); 80 | itr.remove(); 81 | } 82 | 83 | return streamidResponseMap; 84 | } 85 | 86 | @Override 87 | protected void messageReceived(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception { 88 | Integer streamId = msg.headers().getInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text()); 89 | if (streamId == null) { 90 | System.err.println("HttpResponseHandler unexpected message received: " + msg); 91 | return; 92 | } 93 | 94 | ChannelPromise promise = streamidPromiseMap.get(streamId); 95 | if (promise == null) { 96 | System.err.println("Message received for unknown stream id " + streamId); 97 | } else { 98 | // Do stuff with the message (for now just print it) 99 | ByteBuf content = msg.content(); 100 | if (content.isReadable()) { 101 | int contentLength = content.readableBytes(); 102 | byte[] arr = new byte[contentLength]; 103 | content.readBytes(arr); 104 | System.out.println(new String(arr, 0, contentLength, CharsetUtil.UTF_8)); 105 | } 106 | 107 | promise.setSuccess(); 108 | 109 | // Set result 110 | streamidResponseMap.put(streamId, msg); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/NettyHttp2Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Ryo Okubo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jmeter.plugins.http2.sampler; 17 | 18 | import java.net.URI; 19 | import java.net.URL; 20 | import java.net.MalformedURLException; 21 | import java.nio.charset.StandardCharsets; 22 | import java.util.concurrent.TimeUnit; 23 | import java.util.SortedMap; 24 | import java.util.Iterator; 25 | import java.util.Map.Entry; 26 | 27 | import javax.net.ssl.SSLException; 28 | 29 | import org.apache.jmeter.protocol.http.control.Header; 30 | import org.apache.jmeter.protocol.http.control.HeaderManager; 31 | import org.apache.jmeter.samplers.SampleResult; 32 | import org.apache.jmeter.testelement.property.CollectionProperty; 33 | import org.apache.jmeter.testelement.property.PropertyIterator; 34 | 35 | import io.netty.bootstrap.Bootstrap; 36 | import io.netty.buffer.Unpooled; 37 | import io.netty.channel.Channel; 38 | import io.netty.channel.ChannelOption; 39 | import io.netty.channel.EventLoopGroup; 40 | import io.netty.channel.nio.NioEventLoopGroup; 41 | import io.netty.channel.socket.nio.NioSocketChannel; 42 | import io.netty.handler.codec.http.DefaultFullHttpRequest; 43 | import io.netty.handler.codec.http.FullHttpRequest; 44 | import io.netty.handler.codec.http.FullHttpResponse; 45 | import io.netty.handler.codec.http.HttpHeaderNames; 46 | import io.netty.handler.codec.http.HttpHeaderValues; 47 | import io.netty.handler.codec.http2.Http2SecurityUtil; 48 | import io.netty.util.AsciiString; 49 | 50 | import io.netty.handler.ssl.ApplicationProtocolConfig; 51 | import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol; 52 | import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior; 53 | import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior; 54 | import io.netty.handler.ssl.ApplicationProtocolNames; 55 | import io.netty.handler.ssl.OpenSsl; 56 | import io.netty.handler.ssl.SslContext; 57 | import io.netty.handler.ssl.SslContextBuilder; 58 | import io.netty.handler.ssl.SslProvider; 59 | import io.netty.handler.ssl.SupportedCipherSuiteFilter; 60 | import io.netty.handler.ssl.util.InsecureTrustManagerFactory; 61 | 62 | import static io.netty.handler.codec.http.HttpMethod.*; 63 | import static io.netty.handler.codec.http.HttpVersion.*; 64 | 65 | public class NettyHttp2Client { 66 | private final String method; 67 | private final String host; 68 | private final int port; 69 | private final String path; 70 | private final HeaderManager headerManager; 71 | 72 | private Bootstrap b; 73 | 74 | public NettyHttp2Client(String method, String host, int port, String path, HeaderManager headerManager) { 75 | this.method = method; 76 | this.host = host; 77 | this.port = port; 78 | this.path = path; 79 | this.headerManager = headerManager; 80 | } 81 | 82 | public SampleResult request() { 83 | SampleResult sampleResult = new SampleResult(); 84 | 85 | final SslContext sslCtx = getSslContext(); 86 | if (sslCtx == null) { 87 | sampleResult.setSuccessful(false); 88 | return sampleResult; 89 | } 90 | 91 | // Configure the client. 92 | EventLoopGroup workerGroup = new NioEventLoopGroup(); 93 | Http2ClientInitializer initializer = new Http2ClientInitializer(sslCtx, Integer.MAX_VALUE); 94 | Bootstrap b = new Bootstrap(); 95 | b.group(workerGroup); 96 | b.channel(NioSocketChannel.class); 97 | b.option(ChannelOption.SO_KEEPALIVE, true); 98 | b.remoteAddress(host, port); 99 | b.handler(initializer); 100 | 101 | // Start sampling 102 | sampleResult.sampleStart(); 103 | 104 | // Start the client. 105 | Channel channel = b.connect().syncUninterruptibly().channel(); 106 | 107 | // Wait for the HTTP/2 upgrade to occur. 108 | Http2SettingsHandler http2SettingsHandler = initializer.settingsHandler(); 109 | try { 110 | http2SettingsHandler.awaitSettings(5, TimeUnit.SECONDS); 111 | } catch(Exception exception) { 112 | sampleResult.setSuccessful(false); 113 | return sampleResult; 114 | } 115 | 116 | HttpResponseHandler responseHandler = initializer.responseHandler(); 117 | final int streamId = 3; 118 | final URI hostName = URI.create("https://" + host + ':' + port); 119 | 120 | // Set attributes to SampleResult 121 | try { 122 | sampleResult.setURL(new URL(hostName.toString())); 123 | } catch (MalformedURLException exception) { 124 | sampleResult.setSuccessful(false); 125 | return sampleResult; 126 | } 127 | 128 | FullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, path); 129 | request.headers().addObject(HttpHeaderNames.HOST, hostName); 130 | 131 | // Add request headers set by HeaderManager 132 | if (headerManager != null) { 133 | CollectionProperty headers = headerManager.getHeaders(); 134 | if (headers != null) { 135 | PropertyIterator i = headers.iterator(); 136 | while (i.hasNext()) { 137 | org.apache.jmeter.protocol.http.control.Header header 138 | = (org.apache.jmeter.protocol.http.control.Header) i.next().getObjectValue(); 139 | request.headers().add(header.getName(), header.getValue()); 140 | } 141 | } 142 | } 143 | 144 | channel.writeAndFlush(request); 145 | responseHandler.put(streamId, channel.newPromise()); 146 | 147 | final SortedMap responseMap; 148 | try { 149 | responseMap = responseHandler.awaitResponses(5, TimeUnit.SECONDS); 150 | 151 | // Currently pick up only one response of a stream 152 | final FullHttpResponse response = responseMap.get(streamId); 153 | final AsciiString responseCode = response.status().codeAsText(); 154 | final AsciiString reasonPhrase = response.status().reasonPhrase(); 155 | sampleResult.setResponseCode(new StringBuilder(responseCode.length()).append(responseCode).toString()); 156 | sampleResult.setResponseMessage(new StringBuilder(reasonPhrase.length()).append(reasonPhrase).toString()); 157 | sampleResult.setResponseHeaders(getResponseHeaders(response)); 158 | } catch(Exception exception) { 159 | sampleResult.setSuccessful(false); 160 | return sampleResult; 161 | } 162 | 163 | // Wait until the connection is closed. 164 | channel.close().syncUninterruptibly(); 165 | 166 | // End sampling 167 | sampleResult.sampleEnd(); 168 | sampleResult.setSuccessful(true); 169 | 170 | return sampleResult; 171 | } 172 | 173 | private SslContext getSslContext() { 174 | SslContext sslCtx = null; 175 | 176 | final SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; 177 | 178 | try { 179 | sslCtx = SslContextBuilder.forClient() 180 | .sslProvider(provider) 181 | .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) 182 | .trustManager(InsecureTrustManagerFactory.INSTANCE) 183 | .applicationProtocolConfig(new ApplicationProtocolConfig( 184 | Protocol.ALPN, 185 | SelectorFailureBehavior.NO_ADVERTISE, 186 | SelectedListenerFailureBehavior.ACCEPT, 187 | ApplicationProtocolNames.HTTP_2)) 188 | .build(); 189 | } catch(SSLException exception) { 190 | return null; 191 | } 192 | 193 | return sslCtx; 194 | } 195 | 196 | /** 197 | * Convert Response headers set by Netty stack to one String instance 198 | */ 199 | private String getResponseHeaders(FullHttpResponse response) { 200 | StringBuilder headerBuf = new StringBuilder(); 201 | 202 | Iterator> iterator = response.headers().iteratorConverted(); 203 | while(iterator.hasNext()) { 204 | Entry entry = iterator.next(); 205 | headerBuf.append(entry.getKey()); 206 | headerBuf.append(": "); 207 | headerBuf.append(entry.getValue()); 208 | headerBuf.append("\n"); 209 | } 210 | 211 | return headerBuf.toString(); 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/main/java/jmeter/plugins/http2/sampler/gui/HTTP2SamplerGui.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Ryo Okubo 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package jmeter.plugins.http2.sampler.gui; 17 | 18 | import jmeter.plugins.http2.sampler.HTTP2Sampler; 19 | 20 | import java.awt.BorderLayout; 21 | import java.awt.Component; 22 | 23 | import javax.swing.JLabel; 24 | import javax.swing.JPanel; 25 | import javax.swing.JTextField; 26 | import javax.swing.BoxLayout; 27 | 28 | import org.apache.jmeter.gui.util.HorizontalPanel; 29 | import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 30 | import org.apache.jmeter.testelement.TestElement; 31 | import org.apache.jorphan.gui.JLabeledChoice; 32 | import org.apache.jorphan.logging.LoggingManager; 33 | import org.apache.log.Logger; 34 | 35 | public class HTTP2SamplerGui extends AbstractSamplerGui { 36 | 37 | private static final Logger log = LoggingManager.getLoggerForClass(); 38 | 39 | private JLabeledChoice method; 40 | private JTextField domain; 41 | private JTextField port; 42 | private JTextField path; 43 | 44 | public HTTP2SamplerGui(){ 45 | super(); 46 | 47 | setLayout(new BorderLayout(0, 5)); 48 | setBorder(makeBorder()); 49 | 50 | this.add(makeTitlePanel(), BorderLayout.NORTH); 51 | 52 | JPanel webRequestPanel = new JPanel(); 53 | webRequestPanel.setLayout(new BorderLayout()); 54 | 55 | webRequestPanel.add(getWebServerPanel(), BorderLayout.NORTH); 56 | webRequestPanel.add(getPathPanel(), BorderLayout.CENTER); 57 | 58 | this.add(webRequestPanel, BorderLayout.CENTER); 59 | } 60 | 61 | @Override 62 | public String getStaticLabel() { 63 | return "HTTP2 Sampler"; 64 | } 65 | 66 | @Override 67 | public String getLabelResource() { 68 | return "HTTP2 Sampler"; 69 | } 70 | 71 | @Override 72 | public TestElement createTestElement() { 73 | HTTP2Sampler sampler = new HTTP2Sampler(); 74 | 75 | modifyTestElement(sampler); 76 | 77 | return sampler; 78 | } 79 | 80 | @Override 81 | public void configure(TestElement element) { 82 | super.configure(element); 83 | 84 | HTTP2Sampler sampler = (HTTP2Sampler)element; 85 | /* method.setText(sampler.getMethod()); */ 86 | domain.setText(sampler.getDomain()); 87 | port.setText(String.valueOf(sampler.getPort())); 88 | path.setText(sampler.getPath()); 89 | } 90 | 91 | @Override 92 | public void modifyTestElement(TestElement element) { 93 | configureTestElement(element); 94 | /* element.setProperty(HTTP2Sampler.METHOD, method.getText()); */ 95 | element.setProperty(HTTP2Sampler.METHOD, HTTP2Sampler.DEFAULT_METHOD); 96 | element.setProperty(HTTP2Sampler.DOMAIN, domain.getText()); 97 | element.setProperty(HTTP2Sampler.PORT, port.getText()); 98 | element.setProperty(HTTP2Sampler.PATH, path.getText()); 99 | } 100 | 101 | private final JPanel getWebServerPanel() { 102 | JPanel webServerPanel = new HorizontalPanel(); 103 | 104 | final JPanel domainPanel = getDomainPanel(); 105 | final JPanel portPanel = getPortPanel(); 106 | 107 | webServerPanel.add(domainPanel, BorderLayout.CENTER); 108 | webServerPanel.add(portPanel, BorderLayout.EAST); 109 | 110 | return webServerPanel; 111 | } 112 | 113 | private final JPanel getDomainPanel() { 114 | domain = new JTextField(20); 115 | 116 | JLabel label = new JLabel("Domain"); 117 | label.setLabelFor(domain); 118 | 119 | JPanel panel = new JPanel(new BorderLayout(5, 0)); 120 | panel.add(label, BorderLayout.WEST); 121 | panel.add(domain, BorderLayout.CENTER); 122 | 123 | return panel; 124 | } 125 | 126 | private final JPanel getPortPanel() { 127 | port = new JTextField(10); 128 | 129 | JLabel label = new JLabel("Port"); 130 | label.setLabelFor(port); 131 | 132 | JPanel panel = new JPanel(new BorderLayout(5, 0)); 133 | panel.add(label, BorderLayout.WEST); 134 | panel.add(port, BorderLayout.CENTER); 135 | 136 | return panel; 137 | } 138 | 139 | private final JPanel getPathPanel() { 140 | path = new JTextField(15); 141 | 142 | JLabel label = new JLabel("Path"); 143 | label.setLabelFor(path); 144 | 145 | JPanel pathPanel = new HorizontalPanel(); 146 | pathPanel.add(label); 147 | pathPanel.add(path); 148 | 149 | JPanel panel = new JPanel(); 150 | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 151 | panel.add(pathPanel); 152 | 153 | return panel; 154 | } 155 | 156 | } 157 | --------------------------------------------------------------------------------