diff --git a/wicket-intro/CafeAddress/pom.xml b/wicket-intro/CafeAddress/pom.xml new file mode 100644 index 0000000000..2966105404 --- /dev/null +++ b/wicket-intro/CafeAddress/pom.xml @@ -0,0 +1,180 @@ + + + + + 4.0.0 + com.baeldung.wicket.examples.cafeaddress + CafeAddress + war + 1.0-SNAPSHOT + + quickstart + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + 7.4.0 + 9.2.13.v20150730 + 2.5 + 4.12 + UTF-8 + + none + + + + + org.apache.wicket + wicket-core + ${wicket.version} + + + + + + org.apache.logging.log4j + log4j-slf4j-impl + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j.version} + + + + + junit + junit + ${junit.version} + test + + + + + org.eclipse.jetty.aggregate + jetty-all + ${jetty9.version} + test + + + + + + false + src/main/resources + + + false + src/main/java + + ** + + + **/*.java + + + + + + false + src/test/resources + + + false + src/test/java + + ** + + + **/*.java + + + + + + true + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + UTF-8 + true + true + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty9.version} + + + + maven.project.build.directory.test-classes + ${project.build.directory}/test-classes + + + ${project.basedir}/src/test/jetty/jetty.xml,${project.basedir}/src/test/jetty/jetty-ssl.xml,${project.basedir}/src/test/jetty/jetty-http.xml,${project.basedir}/src/test/jetty/jetty-https.xml + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.9 + + true + ${wtp.version} + + + + + + + + Apache Nexus + https://repository.apache.org/content/repositories/snapshots/ + + false + + + true + + + + diff --git a/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.html b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.html new file mode 100644 index 0000000000..954ff551f1 --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.html @@ -0,0 +1,20 @@ + + + + +Apache Wicket Quickstart + + + + +
+ +

+ Address: address +

+
+ + diff --git a/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.java b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.java new file mode 100644 index 0000000000..ce26c5a1ad --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddress.java @@ -0,0 +1,72 @@ +package com.baeldung.wicket.examples.cafeaddress; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +public class CafeAddress extends WebPage { + + private static final long serialVersionUID = 1L; + + String selectedCafe; + Address address; + Map cafeNamesAndAddresses = new HashMap<>(); + + public CafeAddress(final PageParameters parameters) { + super(parameters); + initCafes(); + + ArrayList cafeNames = new ArrayList<>(this.cafeNamesAndAddresses.keySet()); + this.selectedCafe = cafeNames.get(0); + this.address = new Address(this.cafeNamesAndAddresses.get(this.selectedCafe).getAddress()); + + final Label addressLabel = new Label("address", new PropertyModel(this.address, "address")); + addressLabel.setOutputMarkupId(true); + + final DropDownChoice cafeDropdown = new DropDownChoice<>("cafes", new PropertyModel(this, "selectedCafe"), cafeNames); + cafeDropdown.add(new AjaxFormComponentUpdatingBehavior("onchange") { + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + String name = (String) cafeDropdown.getDefaultModel().getObject(); + address.setAddress(cafeNamesAndAddresses.get(name).getAddress()); + target.add(addressLabel); + } + }); + + add(addressLabel); + add(cafeDropdown); + + } + + private void initCafes() { + this.cafeNamesAndAddresses.put("Linda's Cafe", new Address("35 Bower St.")); + this.cafeNamesAndAddresses.put("Old Tree", new Address("2 Edgware Rd.")); + } + + class Address implements Serializable { + private String sAddress = ""; + + public Address(String address) { + this.sAddress = address; + } + + public String getAddress() { + return this.sAddress; + } + + public void setAddress(String address) { + this.sAddress = address; + } + } +} diff --git a/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddressApplication.java b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddressApplication.java new file mode 100644 index 0000000000..189ef14558 --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/java/com/baeldung/wicket/examples/cafeaddress/CafeAddressApplication.java @@ -0,0 +1,33 @@ +package com.baeldung.wicket.examples.cafeaddress; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.protocol.http.WebApplication; + +/** + * Application object for your web application. + * If you want to run this application without deploying, run the Start class. + * + * @see com.baeldung.wicket.examples.Start#main(String[]) + */ +public class CafeAddressApplication extends WebApplication +{ + /** + * @see org.apache.wicket.Application#getHomePage() + */ + @Override + public Class getHomePage() + { + return CafeAddress.class; + } + + /** + * @see org.apache.wicket.Application#init() + */ + @Override + public void init() + { + super.init(); + + // add your configuration here + } +} diff --git a/wicket-intro/CafeAddress/src/main/resources/log4j2.xml b/wicket-intro/CafeAddress/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..5596dd5f40 --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/resources/log4j2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/main/webapp/WEB-INF/web.xml b/wicket-intro/CafeAddress/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..03e600188b --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + CafeAddress + + + + + wicket.CafeAddress + org.apache.wicket.protocol.http.WicketFilter + + applicationClassName + com.baeldung.wicket.examples.cafeaddress.CafeAddressApplication + + + + + wicket.CafeAddress + /* + + diff --git a/wicket-intro/CafeAddress/src/main/webapp/logo.png b/wicket-intro/CafeAddress/src/main/webapp/logo.png new file mode 100644 index 0000000000..39ec54854b Binary files /dev/null and b/wicket-intro/CafeAddress/src/main/webapp/logo.png differ diff --git a/wicket-intro/CafeAddress/src/main/webapp/style.css b/wicket-intro/CafeAddress/src/main/webapp/style.css new file mode 100644 index 0000000000..fc137cadb0 --- /dev/null +++ b/wicket-intro/CafeAddress/src/main/webapp/style.css @@ -0,0 +1,68 @@ +body, p, li, a { font-family: georgia, times, serif;font-size:13pt;} +h1, h2, h3 { font-family: 'Yanone Kaffeesatz', arial, serif; } +body { margin:0;padding:0;} +#hd { + width : 100%; + height : 87px; + background-color : #092E67; + margin-top : 0; + padding-top : 10px; + border-bottom : 1px solid #888; + z-index : 0; +} +#ft { + position : absolute; + bottom : 0; + width : 100%; + height : 99px; + background-color : #6493D2; + border-top : 1px solid #888; + z-index : 0; +} +#logo,#bd { + width : 650px; + margin: 0 auto; + padding: 25px 50px 0 50px; +} +#logo h1 { + color : white; + font-size:36pt; + display: inline; +} +#logo img { + display:inline; + vertical-align: bottom; + margin-left : 50px; + margin-right : 5px; +} +body { margin-top : 0; padding-top : 0;} +#logo, #logo h1 { margin-top : 0; padding-top : 0;} +#bd { + position : absolute; + top : 75px; + bottom : 75px; + left : 50%; + margin-left : -325px; + z-index : 1; + overflow: auto; + background-color : #fff; + -webkit-border-radius: 10px; + -moz-border-radius: 10px; + border-radius: 10px; + -moz-box-shadow: 0px 0px 10px #888; + -webkit-box-shadow: 0px 0px 10px #888; + box-shadow: 0px 0px 10px #888; +} +a, a:visited, a:hover, a:active { + color : #6493D2; +} +h2 { + padding : 0; margin:0; + font-size:36pt; + color:#FF5500; +} +h3 { + padding : 0; margin:0; + font-size:24pt; + color:#092E67; +} \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/Start.java b/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/Start.java new file mode 100644 index 0000000000..b2be405124 --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/Start.java @@ -0,0 +1,108 @@ +package com.baeldung.wicket.examples.cafeaddress; + +import java.lang.management.ManagementFactory; + +import javax.management.MBeanServer; + +import org.eclipse.jetty.jmx.MBeanContainer; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.webapp.WebAppContext; + +/** + * Separate startup class for people that want to run the examples directly. Use parameter + * -Dcom.sun.management.jmxremote to startup JMX (and e.g. connect with jconsole). + */ +public class Start +{ + /** + * Main function, starts the jetty server. + * + * @param args + */ + public static void main(String[] args) + { + System.setProperty("wicket.configuration", "development"); + + Server server = new Server(); + + HttpConfiguration http_config = new HttpConfiguration(); + http_config.setSecureScheme("https"); + http_config.setSecurePort(8443); + http_config.setOutputBufferSize(32768); + + ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); + http.setPort(8080); + http.setIdleTimeout(1000 * 60 * 60); + + server.addConnector(http); + + Resource keystore = Resource.newClassPathResource("/keystore"); + if (keystore != null && keystore.exists()) + { + // if a keystore for a SSL certificate is available, start a SSL + // connector on port 8443. + // By default, the quickstart comes with a Apache Wicket Quickstart + // Certificate that expires about half way september 2021. Do not + // use this certificate anywhere important as the passwords are + // available in the source. + + SslContextFactory sslContextFactory = new SslContextFactory(); + sslContextFactory.setKeyStoreResource(keystore); + sslContextFactory.setKeyStorePassword("wicket"); + sslContextFactory.setKeyManagerPassword("wicket"); + + HttpConfiguration https_config = new HttpConfiguration(http_config); + https_config.addCustomizer(new SecureRequestCustomizer()); + + ServerConnector https = new ServerConnector(server, new SslConnectionFactory( + sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config)); + https.setPort(8443); + https.setIdleTimeout(500000); + + server.addConnector(https); + System.out.println("SSL access to the examples has been enabled on port 8443"); + System.out + .println("You can access the application using SSL on https://localhost:8443"); + System.out.println(); + } + + WebAppContext bb = new WebAppContext(); + bb.setServer(server); + bb.setContextPath("/"); + bb.setWar("src/main/webapp"); + + // uncomment the next two lines if you want to start Jetty with WebSocket (JSR-356) support + // you need org.apache.wicket:wicket-native-websocket-javax in the classpath! + // ServerContainer serverContainer = WebSocketServerContainerInitializer.configureContext(bb); + // serverContainer.addEndpoint(new WicketServerEndpointConfig()); + + // uncomment next line if you want to test with JSESSIONID encoded in the urls + // ((AbstractSessionManager) + // bb.getSessionHandler().getSessionManager()).setUsingCookies(false); + + server.setHandler(bb); + + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); + server.addEventListener(mBeanContainer); + server.addBean(mBeanContainer); + + try + { + server.start(); + server.join(); + } + catch (Exception e) + { + e.printStackTrace(); + System.exit(100); + } + } +} diff --git a/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/TestHomePage.java b/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/TestHomePage.java new file mode 100644 index 0000000000..9b186ce52b --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/java/com/baeldung/wicket/examples/cafeaddress/TestHomePage.java @@ -0,0 +1,29 @@ +package com.baeldung.wicket.examples.cafeaddress; + +import org.apache.wicket.util.tester.WicketTester; +import org.junit.Before; +import org.junit.Test; + +/** + * Simple test using the WicketTester + */ +public class TestHomePage +{ + private WicketTester tester; + + @Before + public void setUp() + { + tester = new WicketTester(new CafeAddressApplication()); + } + + @Test + public void homepageRendersSuccessfully() + { + //start and render the test page + tester.startPage(CafeAddress.class); + + //assert rendered page class + tester.assertRenderedPage(CafeAddress.class); + } +} diff --git a/wicket-intro/CafeAddress/src/test/jetty/jetty-http.xml b/wicket-intro/CafeAddress/src/test/jetty/jetty-http.xml new file mode 100644 index 0000000000..9f3256b15c --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/jetty/jetty-http.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/test/jetty/jetty-https.xml b/wicket-intro/CafeAddress/src/test/jetty/jetty-https.xml new file mode 100644 index 0000000000..58f7d53d2d --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/jetty/jetty-https.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + http/1.1 + + + + + + + + + + + + + 30000 + + + + \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/test/jetty/jetty-ssl.xml b/wicket-intro/CafeAddress/src/test/jetty/jetty-ssl.xml new file mode 100644 index 0000000000..49e558bb47 --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/jetty/jetty-ssl.xml @@ -0,0 +1,36 @@ + + + + + + + + + / + + + + + + SSL_RSA_WITH_DES_CBC_SHA + SSL_DHE_RSA_WITH_DES_CBC_SHA + SSL_DHE_DSS_WITH_DES_CBC_SHA + SSL_RSA_EXPORT_WITH_RC4_40_MD5 + SSL_RSA_EXPORT_WITH_DES40_CBC_SHA + SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA + SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/test/jetty/jetty.xml b/wicket-intro/CafeAddress/src/test/jetty/jetty.xml new file mode 100644 index 0000000000..1a6293b405 --- /dev/null +++ b/wicket-intro/CafeAddress/src/test/jetty/jetty.xml @@ -0,0 +1,23 @@ + + + + + + + + https + + + + 32768 + 8192 + 8192 + true + false + 512 + + + + + + \ No newline at end of file diff --git a/wicket-intro/CafeAddress/src/test/resources/keystore b/wicket-intro/CafeAddress/src/test/resources/keystore new file mode 100644 index 0000000000..30bbc90ccf Binary files /dev/null and b/wicket-intro/CafeAddress/src/test/resources/keystore differ diff --git a/wicket-intro/HelloWorld/pom.xml b/wicket-intro/HelloWorld/pom.xml new file mode 100644 index 0000000000..08586375ce --- /dev/null +++ b/wicket-intro/HelloWorld/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + com.baeldung.wicket.examples.helloworld + HelloWorld + war + 1.0-SNAPSHOT + HelloWorld Maven Webapp + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + org.apache.wicket + wicket-core + 8.0.0-M1 + + + + HelloWorld + + diff --git a/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.html b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.html new file mode 100644 index 0000000000..c56d07fc10 --- /dev/null +++ b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.html @@ -0,0 +1,5 @@ + + + + + diff --git a/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.java b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.java new file mode 100644 index 0000000000..6dc7295798 --- /dev/null +++ b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorld.java @@ -0,0 +1,10 @@ +package com.baeldung.wicket.examples.helloworld; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; + +public class HelloWorld extends WebPage { + public HelloWorld() { + add(new Label("hello", "Hello World!")); + } +} diff --git a/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorldApplication.java b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorldApplication.java new file mode 100644 index 0000000000..618496e5f7 --- /dev/null +++ b/wicket-intro/HelloWorld/src/main/java/com/baeldung/wicket/examples/helloworld/HelloWorldApplication.java @@ -0,0 +1,12 @@ + +package com.baeldung.wicket.examples.helloworld; + +import org.apache.wicket.Page; +import org.apache.wicket.protocol.http.WebApplication; + +public class HelloWorldApplication extends WebApplication { + @Override + public Class getHomePage() { + return HelloWorld.class; + } +} diff --git a/wicket-intro/HelloWorld/src/main/webapp/WEB-INF/web.xml b/wicket-intro/HelloWorld/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c68ca09241 --- /dev/null +++ b/wicket-intro/HelloWorld/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + Hello World + + HelloWorldApplication + org.apache.wicket.protocol.http.WicketFilter + + applicationClassName + com.baeldung.wicket.examples.helloworld.HelloWorldApplication + + + + HelloWorldApplication + /* + +