http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java new file mode 100644 index 0000000..214fc8b --- /dev/null +++ b/juneau-examples-rest/src/test/java/org/apache/juneau/examples/rest/_TestSuite.java @@ -0,0 +1,57 @@ +// *************************************************************************************************************************** +// * 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.juneau.examples.rest; + +import java.util.*; + +import org.apache.juneau.microservice.*; +import org.junit.*; +import org.junit.runner.*; +import org.junit.runners.*; +import org.junit.runners.Suite.*; + +/** + * Runs all the testcases in this project. + * Starts a REST service running org.apache.juneau.examples.rest.RootResources on port 10000. + * Stops the REST service after running the tests. + */ +@RunWith(Suite.class) +@SuiteClasses({ + AddressBookResourceTest.class, + RootResourcesTest.class, + SampleRemoteableServicesResourceTest.class, + TestMultiPartFormPostsTest.class +}) +public class _TestSuite { + static Microservice microservice; + + @BeforeClass + public static void setUp() { + try { + Locale.setDefault(Locale.US); + microservice = new RestMicroservice().setConfig("examples.cfg", false); + microservice.start(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @AfterClass + public static void tearDown() { + try { + microservice.stop(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-examples-rest/war/web.xml ---------------------------------------------------------------------- diff --git a/juneau-examples-rest/war/web.xml b/juneau-examples-rest/war/web.xml new file mode 100755 index 0000000..8387154 --- /dev/null +++ b/juneau-examples-rest/war/web.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + *************************************************************************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations under the License. * + *************************************************************************************************************************** +--> +<web-app + version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + + <servlet> + <servlet-name>examples</servlet-name> + <servlet-class>org.apache.juneau.examples.rest.RootResources</servlet-class> + </servlet> + <servlet> + <servlet-name>test</servlet-name> + <servlet-class>org.apache.juneau.examples.rest.test.Root</servlet-class> + </servlet> + <servlet> + <servlet-name>testuris</servlet-name> + <servlet-class>org.apache.juneau.examples.rest.test.TestUris</servlet-class> + </servlet> + + <servlet-mapping> + <servlet-name>sample</servlet-name> + <url-pattern>/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>test</servlet-name> + <url-pattern>/test/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>testuris</servlet-name> + <url-pattern>/testuris/*</url-pattern> + </servlet-mapping> +</web-app> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-releng/launches/Package Juneau.launch ---------------------------------------------------------------------- diff --git a/juneau-releng/launches/Package Juneau.launch b/juneau-releng/launches/Package Juneau.launch index 89cdd9e..214729c 100644 --- a/juneau-releng/launches/Package Juneau.launch +++ b/juneau-releng/launches/Package Juneau.launch @@ -26,7 +26,7 @@ <booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false"/> <stringAttribute key="M2_USER_SETTINGS" value=""/> <booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false"/> -<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/juneau-core/target" type="2"/> <item path="/juneau-rest-client/target" type="2"/> <item path="/juneau-distrib/target" type="2"/> <item path="/juneau-microservice/target" type="2"/> <item path="/juneau-releng/target" type="2"/> <item path="/juneau-samples/target" type="2"/> <item path="/juneau-rest/target" type="2"/> <item path="/juneau-rest-test/target" type="2"/> </resources>}"/> +<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources> <item path="/juneau-core/target" type="2"/> <item path="/juneau-rest-client/target" type="2"/> <item path="/juneau-distrib/target" type="2"/> <item path="/juneau-microservice/target" type="2"/> <item path="/juneau-releng/target" type="2"/> <item path="/juneau-examples-rest/target" type="2"/> <item path="/juneau-rest/target" type="2"/> <item path="/juneau-rest-test/target" type="2"/> </resources>}"/> <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> <stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/juneau-root}"/> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html index 8db644e..100d17b 100644 --- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html +++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/package.html @@ -765,7 +765,7 @@ Proxy interfaces are retrieved using the {@link org.apache.juneau.rest.client.RestClient#getRemoteableProxy(Class)} method. The {@link org.apache.juneau.rest.client.RestClient#setRemoteableServletUri(String)} method is used to specify the location of the remoteable services servlet running on the server. - The remoteable servlet is a specialized subclass of {@link org.apache.juneau.server.RestServlet} that provides a full-blown + The remoteable servlet is a specialized subclass of {@link org.apache.juneau.rest.RestServlet} that provides a full-blown REST interface for calling interfaces remotely. </p> <p> @@ -809,7 +809,7 @@ can be called directly from a browser with no code involved. </p> <p> - See {@link org.apache.juneau.server.remoteable} for more information. + See {@link org.apache.juneau.rest.remoteable} for more information. </p> </div> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-rest-test/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-rest-test/pom.xml b/juneau-rest-test/pom.xml index 4ad6f98..2d7c070 100644 --- a/juneau-rest-test/pom.xml +++ b/juneau-rest-test/pom.xml @@ -35,7 +35,7 @@ <dependencies> <dependency> <groupId>org.apache.juneau</groupId> - <artifactId>juneau-samples</artifactId> + <artifactId>juneau-examples-rest</artifactId> <version>${project.version}</version> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java ---------------------------------------------------------------------- diff --git a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java index b76899b..e65c00a 100644 --- a/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java +++ b/juneau-rest-test/src/main/java/org/apache/juneau/rest/test/ParamsResource.java @@ -20,11 +20,11 @@ import java.util.*; import javax.servlet.http.*; import org.apache.juneau.*; +import org.apache.juneau.examples.addressbook.*; import org.apache.juneau.json.*; import org.apache.juneau.plaintext.*; import org.apache.juneau.rest.*; import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.samples.addressbook.*; import org.apache.juneau.transforms.*; import org.apache.juneau.urlencoding.*; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-rest/src/main/java/org/apache/juneau/rest/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html index 3300f53..3bedee1 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/package.html +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/package.html @@ -3101,7 +3101,7 @@ The following code shows how to register your REST servlets in an OSGi <l>Activator</l>: </p> <p class='bcode'> - <jk>package</jk> org.apache.juneau.samples; + <jk>package</jk> org.apache.juneau.examples.rest; <jk>import</jk> org.osgi.framework.*; <jk>import</jk> org.osgi.service.http.*; @@ -3219,7 +3219,7 @@ <ja>@Property</ja>(name=<jsf>SERIALIZER_quoteChar</jsf>, value=<js>"'"</js>), <ja>@Property</ja>(name=<jsf>RDF_rdfxml_tab</jsf>, value=<js>"5"</js>), <ja>@Property</ja>(name=<jsf>RDF_addRootProperty</jsf>, value=<js>"true"</js>), - <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.addressbook.AddressBookResource,org.apache.juneau.samples.addressbook.Address,org.apache.juneau.samples.addressbook.AddressBook,org.apache.juneau.samples.addressbook.CreateAddress,org.apache.juneau.samples.addressbook.CreatePerson,org.apache.juneau.samples.addressbook.IAddressBook,org.apache.juneau.samples.addressbook.Person)'}"</js>), + <ja>@Property</ja>(name=<jsf>HTMLDOC_links</jsf>, value=<js>"{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.addressbook.AddressBookResource,org.apache.juneau.examples.addressbook.Address,org.apache.juneau.examples.addressbook.AddressBook,org.apache.juneau.examples.addressbook.CreateAddress,org.apache.juneau.examples.addressbook.CreatePerson,org.apache.juneau.examples.addressbook.IAddressBook,org.apache.juneau.examples.addressbook.Person)'}"</js>), <jc>// Resolve all relative URIs so that they're relative to this servlet!</jc> <ja>@Property</ja>(name=<jsf>SERIALIZER_relativeUriBase</jsf>, value=<js>"$R{servletURI}"</js>), }, http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/package.html ---------------------------------------------------------------------- diff --git a/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/package.html b/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/package.html index fbc7c41..b6a9d7f 100644 --- a/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/package.html +++ b/juneau-rest/src/main/java/org/apache/juneau/rest/remoteable/package.html @@ -77,8 +77,8 @@ calling methods on POJOs on the server side. </p> <p> - Proxy interfaces are retrieved using the {@link org.apache.juneau.client.RestClient#getRemoteableProxy(Class)} method. - The {@link org.apache.juneau.client.RestClient#setRemoteableServletUri(String)} method is used to specify the location + Proxy interfaces are retrieved using the {@link org.apache.juneau.rest.client.RestClient#getRemoteableProxy(Class)} method. + The {@link org.apache.juneau.rest.client.RestClient#setRemoteableServletUri(String)} method is used to specify the location of the remoteable services servlet running on the server. The remoteable servlet is a specialized subclass of {@link org.apache.juneau.rest.RestServlet} that provides a full-blown REST interface for calling remoteable services (e.g. POJOs) remotely. @@ -126,7 +126,7 @@ <h2 class='topic' onclick='toggle(this)'>2 - Client Side</h2> <div class='topic'> <p> - Remoteable interface proxies are retrieved through the existing {@link org.apache.juneau.client.RestClient} class. + Remoteable interface proxies are retrieved through the existing {@link org.apache.juneau.rest.client.RestClient} class. </p> <p> It may seem that the client-side code would need to be complex. @@ -263,7 +263,7 @@ <p> Next, we can use a tool such as Poster to make the REST call. Methods are invoked by POSTing the serialized object array to the URI of the interface method. - In this case, we want to POST our JSON to <code>/juneau/sample/remoteable/org.apache.juneau.samples.addressbook.IAddressBook/createPerson(org.apache.juneau.samples.addressbook.CreatePerson)</code>. + In this case, we want to POST our JSON to <code>/juneau/sample/remoteable/org.apache.juneau.examples.addressbook.IAddressBook/createPerson(org.apache.juneau.examples.addressbook.CreatePerson)</code>. Make sure that we specify the <code>Content-Type</code> of the body as <code>text/json</code>. We also want the results to be returned as JSON, so we set the <code>Accept</code> header to <code>text/json</code> as well. </p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/.gitignore ---------------------------------------------------------------------- diff --git a/juneau-samples/.gitignore b/juneau-samples/.gitignore deleted file mode 100644 index 8ca27ce..0000000 --- a/juneau-samples/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/logs/ -/.DS_Store -/derby.log -/target/ -/.settings/ -/.classpath http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/.project ---------------------------------------------------------------------- diff --git a/juneau-samples/.project b/juneau-samples/.project deleted file mode 100644 index 46ad2c7..0000000 --- a/juneau-samples/.project +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<projectDescription> - <name>juneau-samples</name> - <comment>Sample code packaged as a microservice. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> - <projects> - <project>juneau-microservice</project> - <project>juneau-rest</project> - <project>juneau-core</project> - <project>juneau-rest-client</project> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/pom.xml ---------------------------------------------------------------------- diff --git a/juneau-samples/pom.xml b/juneau-samples/pom.xml deleted file mode 100644 index 01a4402..0000000 --- a/juneau-samples/pom.xml +++ /dev/null @@ -1,152 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - *************************************************************************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations under the License. * - *************************************************************************************************************************** ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <artifactId>juneau-samples</artifactId> - <name>Apache Juneau Samples</name> - <description>Sample code packaged as a microservice.</description> - - <parent> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau</artifactId> - <version>6.0.2-incubating-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <properties> - <encoding>UTF-8</encoding> - <maven.javadoc.skip>true</maven.javadoc.skip> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.juneau</groupId> - <artifactId>juneau-microservice</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpmime</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <version>3.0.1</version> - <executions> - <execution> - <id>attach-sources</id> - <phase>verify</phase> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- - This runs the _TestSuite class. - You must run within the testsuite so the REST microservice is started for the tests. - --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.19.1</version> - <configuration> - <includes> - <include> - **/_TestSuite.java - </include> - </includes> - </configuration> - </plugin> - - <!-- - This packages the samples into an executable jar. - Use: java -jar juneau-samples-uber.jar - Needs the samples.cfg copied below in the same directory. - --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.4.3</version> - <configuration> - <createDependencyReducedPom>false</createDependencyReducedPom> - <minimizeJar>false</minimizeJar> - <transformers> - <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <manifestEntries> - <Main-Class>org.apache.juneau.microservice.RestMicroservice</Main-Class> - <Rest-Resources>org.apache.juneau.rest.samples.RootResources</Rest-Resources> - <Main-ConfigFile>samples.cfg</Main-ConfigFile> - </manifestEntries> - </transformer> - </transformers> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- Attaches the samples.cfg to this artifact --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.12</version> - <executions> - <execution> - <id>attach-artifacts</id> - <phase>package</phase> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>samples.cfg</file> - <type>cfg</type> - <classifier>samples</classifier> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/samples.cfg ---------------------------------------------------------------------- diff --git a/juneau-samples/samples.cfg b/juneau-samples/samples.cfg deleted file mode 100755 index 54b6c32..0000000 --- a/juneau-samples/samples.cfg +++ /dev/null @@ -1,145 +0,0 @@ -# *************************************************************************************************************************** -# * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -# * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -# * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -# * with the License. You may obtain a copy of the License at * -# * * -# * http://www.apache.org/licenses/LICENSE-2.0 * -# * * -# * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -# * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -# * specific language governing permissions and limitations under the License. * -# *************************************************************************************************************************** - -#================================================================================ -# Basic configuration file for SaaS microservices -# Subprojects can use this as a starting point. -#================================================================================ - -#================================================================================ -# REST settings -#================================================================================ -[REST] - -resources = org.apache.juneau.rest.samples.RootResources - -port = 10000 - -# Authentication: NONE, BASIC. -authType = NONE - -# The BASIC auth username, password, and realm -loginUser = -loginPassword = -authRealm = - -# Stylesheet to use for HTML views. -# The default options are: -# - styles/juneau.css -# - styles/devops.css -# Other stylesheets can be referenced relative to the servlet package or working -# directory. -stylesheet = styles/devops.css - -# What to do when the config file is saved. -# Possible values: -# NOTHING - Don't do anything. -# RESTART_SERVER - Restart the Jetty server. -# RESTART_SERVICE - Shutdown and exit with code '3'. -saveConfigAction = RESTART_SERVER - -# Enable SSL support. -useSsl = false - -#================================================================================ -# Bean properties on the org.eclipse.jetty.util.ssl.SslSocketFactory class -#-------------------------------------------------------------------------------- -# Ignored if REST/useSsl is false. -# Specify any of the following fields: -# allowRenegotiate (boolean) -# certAlias (String) -# crlPath (String) -# enableCRLDP (boolean) -# enableOCSP (boolean) -# excludeCipherSuites (String[]) -# excludeProtocols (String[]) -# includeCipherSuites (String[]) -# includeProtocols (String...) -# keyManagerPassword (String) -# keyStore (String) -# keyStorePassword (String) -# keyStorePath (String) -# keyStoreProvider (String) -# keyStoreType (String) -# maxCertPathLength (int) -# needClientAuth (boolean) -# ocspResponderURL (String) -# protocol (String) -# provider (String) -# secureRandomAlgorithm (String) -# sessionCachingEnabled (boolean) -# sslKeyManagerFactoryAlgorithm (String) -# sslSessionCacheSize (int) -# sslSessionTimeout (int) -# trustAll (boolean) -# trustManagerFactoryAlgorithm (String) -# trustStore (String) -# trustStorePassword (String) -# trustStoreProvider (String) -# trustStoreType (String) -# validateCerts (boolean) -# validatePeerCerts (boolean) -# wantClientAuth (boolean) -#================================================================================ -[REST-SslContextFactory] -keyStorePath = client_keystore.jks -keyStorePassword* = {HRAaRQoT} -excludeCipherSuites = TLS_DHE.*, TLS_EDH.* -excludeProtocols = SSLv3 -allowRenegotiate = false - -#================================================================================ -# Logger settings -# See FileHandler Java class for details. -#================================================================================ -[Logging] -logDir = logs -logFile = sample.%g.log -dateFormat = yyyy.MM.dd hh:mm:ss -format = [{date} {level}] {msg}%n -append = false -limit = 10M -count = 5 -levels = { org.apache.juneau:'INFO' } -useStackTraceHashes = true -consoleLevel = WARNING - -#================================================================================ -# System properties -#-------------------------------------------------------------------------------- -# These are arbitrary system properties that can be set during startup. -#================================================================================ -[SystemProperties] - -# Configure Jetty for StdErrLog Logging -org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog - -# Jetty logging level -org.eclipse.jetty.LEVEL = WARN - -#================================================================================ -# DockerRegistryResource properties -#================================================================================ -[DockerRegistry] -url = http://docker.apache.org:5000/v1 - -#================================================================================ -# SqlQueryResource properties -#================================================================================ -[SqlQueryResource] -driver = org.apache.derby.jdbc.EmbeddedDriver -connectionUrl = jdbc:derby:C:/testDB;create=true -allowTempUpdates = true -includeRowNums = true - - http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AdminGuard.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AdminGuard.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AdminGuard.java deleted file mode 100644 index 85da7b1..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AdminGuard.java +++ /dev/null @@ -1,26 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import org.apache.juneau.rest.*; - -/** - * Sample guard that only lets administrators through. - */ -public class AdminGuard extends RestGuard { - - @Override /* RestGuard */ - public boolean isRequestAllowed(RestRequest req) { - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AtomFeedResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AtomFeedResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AtomFeedResource.java deleted file mode 100644 index e423a63..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/AtomFeedResource.java +++ /dev/null @@ -1,103 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.dto.atom.AtomBuilder.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.jena.RdfCommonContext.*; -import static org.apache.juneau.jena.RdfSerializerContext.*; - -import java.net.*; - -import org.apache.juneau.dto.atom.*; -import org.apache.juneau.encoders.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Sample resource that shows how to generate ATOM feeds. - */ -@RestResource( - path="/atom", - messages="nls/AtomFeedResource", - properties={ - @Property(name=SERIALIZER_quoteChar, value="'"), - @Property(name=RDF_rdfxml_tab, value="5"), - @Property(name=RDF_addRootProperty, value="true"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.AtomFeedResource)'}") - }, - encoders=GzipEncoder.class -) -public class AtomFeedResource extends ResourceJena { - private static final long serialVersionUID = 1L; - - private Feed feed; // The root resource object - - @Override /* Servlet */ - public void init() { - - try { - feed = - feed("tag:juneau.sample.com,2013:1", "Juneau ATOM specification", "2013-05-08T12:29:29Z") - .subtitle(text("html").text("A <em>lot</em> of effort went into making this effortless")) - .links( - link("alternate", "text/html", "http://www.sample.com/").hreflang("en"), - link("self", "application/atom+xml", "http://www.sample.com/feed.atom") - ) - .rights("Copyright (c) 2016, Apache Foundation") - .generator( - generator("Juneau").uri("http://juneau.apache.org/").version("1.0") - ) - .entries( - entry("tag:juneau.sample.com,2013:1.2345", "Juneau ATOM specification snapshot", "2013-05-08T12:29:29Z") - .links( - link("alternate", "text/html", "http://www.sample.com/2012/05/08/juneau.atom"), - link("enclosure", "audio/mpeg", "http://www.sample.com/audio/juneau_podcast.mp3").length(1337) - ) - .published("2013-05-08T12:29:29Z") - .authors( - person("James Bognar").uri(new URI("http://www.sample.com/")).email("[email protected]") - ) - .contributors( - person("Barry M. Caceres") - ) - .content( - content("xhtml") - .lang("en") - .base("http://www.apache.org/") - .text("<div><p>[Update: Juneau supports ATOM.]</p></div>") - ) - ); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * GET request handler - */ - @RestMethod(name="GET", path="/") - public Feed getFeed() throws Exception { - return feed; - } - - /** - * PUT request handler. - * Replaces the feed with the specified content, and then mirrors it as the response. - */ - @RestMethod(name="PUT", path="/") - public Feed setFeed(@Body Feed feed) throws Exception { - this.feed = feed; - return feed; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/CodeFormatterResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/CodeFormatterResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/CodeFormatterResource.java deleted file mode 100644 index 1ab9daa..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/CodeFormatterResource.java +++ /dev/null @@ -1,50 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.io.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Service at <code>/codeFormatter</code>. - * Used for executing SQL queries against the repository database. - */ -@RestResource( - path="/codeFormatter", - messages="nls/CodeFormatterResource", - properties={ - @Property(name=HTMLDOC_title, value="Code Formatter"), - @Property(name=HTMLDOC_description, value="Add syntax highlighting tags to source code"), - @Property(name=HTMLDOC_links, value="{options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.CodeFormatterResource)'}"), - } -) -@SuppressWarnings("serial") -public class CodeFormatterResource extends Resource { - - /** [GET /] - Display query entry page. */ - @RestMethod(name="GET", path="/") - public ReaderResource getQueryEntryPage(RestRequest req) throws IOException { - return req.getReaderResource("CodeFormatterResource.html", true); - } - - /** [POST /] - Execute SQL query. */ - @RestMethod(name="POST", path="/") - public String executeQuery(@FormData("code") String code, @FormData("lang") String lang) throws Exception { - return SourceResource.highlight(code, lang); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/Constants.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/Constants.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/Constants.java deleted file mode 100644 index d355efb..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/Constants.java +++ /dev/null @@ -1,28 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -public class Constants { - - private static String juneauSampleUrl = System.getProperty("JUNO_SAMPLE_URL"); - - /** - * Returns the value of the "JUNO_SAMPLE_URL" system property, or throws a {@link RuntimeException} - * if it's not set. - */ - public static String getSampleUrl() { - if (juneauSampleUrl == null) - return "http://localhost:10000"; - return juneauSampleUrl; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DirectoryResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DirectoryResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DirectoryResource.java deleted file mode 100644 index 5741a00..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DirectoryResource.java +++ /dev/null @@ -1,234 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static java.util.logging.Level.*; -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.rest.RestServletContext.*; - -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.logging.*; - -import javax.servlet.*; - -import org.apache.juneau.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.annotation.Properties; -import org.apache.juneau.rest.converters.*; -import org.apache.juneau.utils.*; - -/** - * Sample REST resource for exploring local file systems. - */ -@RestResource( - messages="nls/DirectoryResource", - properties={ - @Property(name=HTML_uriAnchorText, value=PROPERTY_NAME), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.DirectoryResource)'}"), - @Property(name=REST_allowMethodParam, value="*"), - @Property(name="rootDir", value="$S{java.io.tmpdir}"), - @Property(name="allowViews", value="false"), - @Property(name="allowDeletes", value="false"), - @Property(name="allowPuts", value="false") - } -) -public class DirectoryResource extends Resource { - private static final long serialVersionUID = 1L; - - protected File rootDir; // The root directory - - // Settings enabled through servlet init parameters - protected boolean allowDeletes, allowPuts, allowViews; - - private static Logger logger = Logger.getLogger(DirectoryResource.class.getName()); - - @Override /* Servlet */ - public void init() throws ServletException { - ObjectMap p = getProperties(); - rootDir = new File(p.getString("rootDir")); - allowViews = p.getBoolean("allowViews", false); - allowDeletes = p.getBoolean("allowDeletes", false); - allowPuts = p.getBoolean("allowPuts", false); - } - - /** Returns the root directory defined by the 'rootDir' init parameter */ - protected File getRootDir() { - if (rootDir == null) { - rootDir = new File(getProperties().getString("rootDir")); - if (! rootDir.exists()) - if (! rootDir.mkdirs()) - throw new RuntimeException("Could not create root dir"); - } - return rootDir; - } - - /** GET request handler */ - @RestMethod(name="GET", path="/*", converters={Queryable.class}) - public Object doGet(RestRequest req, @Properties ObjectMap properties) throws Exception { - - String pathInfo = req.getPathInfo(); - File f = pathInfo == null ? rootDir : new File(rootDir.getAbsolutePath() + pathInfo); - - if (!f.exists()) - throw new RestException(SC_NOT_FOUND, "File not found"); - - properties.put("path", f.getAbsolutePath()); - - if (f.isDirectory()) { - List<FileResource> l = new LinkedList<FileResource>(); - for (File fc : f.listFiles()) { - URL fUrl = new URL(req.getRequestURL().append("/").append(fc.getName()).toString()); - l.add(new FileResource(fc, fUrl)); - } - return l; - } - - return new FileResource(f, new URL(req.getRequestURL().toString())); - } - - /** DELETE request handler */ - @RestMethod(name="DELETE", path="/*", guards=AdminGuard.class) - public Object doDelete(RestRequest req) throws Exception { - - if (! allowDeletes) - throw new RestException(SC_METHOD_NOT_ALLOWED, "DELETE not enabled"); - - File f = new File(rootDir.getAbsolutePath() + req.getPathInfo()); - deleteFile(f); - - if (req.getHeader("Accept").contains("text/html")) - return new Redirect(); - return "File deleted"; - } - - /** PUT request handler */ - @RestMethod(name="PUT", path="/*", guards=AdminGuard.class) - public Object doPut(RestRequest req) throws Exception { - - if (! allowPuts) - throw new RestException(SC_METHOD_NOT_ALLOWED, "PUT not enabled"); - - File f = new File(rootDir.getAbsolutePath() + req.getPathInfo()); - String parentSubPath = f.getParentFile().getAbsolutePath().substring(rootDir.getAbsolutePath().length()); - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); - IOPipe.create(req.getInputStream(), bos).closeOut().run(); - if (req.getContentType().contains("html")) - return new Redirect(parentSubPath); - return "File added"; - } - - /** VIEW request handler (overloaded GET for viewing file contents) */ - @RestMethod(name="VIEW", path="/*") - public void doView(RestRequest req, RestResponse res) throws Exception { - - if (! allowViews) - throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not enabled"); - - File f = new File(rootDir.getAbsolutePath() + req.getPathInfo()); - - if (!f.exists()) - throw new RestException(SC_NOT_FOUND, "File not found"); - - if (f.isDirectory()) - throw new RestException(SC_METHOD_NOT_ALLOWED, "VIEW not available on directories"); - - res.setOutput(new FileReader(f)).setContentType("text/plain"); - } - - /** DOWNLOAD request handler (overloaded GET for downloading file contents) */ - @RestMethod(name="DOWNLOAD") - public void doDownload(RestRequest req, RestResponse res) throws Exception { - - if (! allowViews) - throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not enabled"); - - File f = new File(rootDir.getAbsolutePath() + req.getPathInfo()); - - if (!f.exists()) - throw new RestException(SC_NOT_FOUND, "File not found"); - - if (f.isDirectory()) - throw new RestException(SC_METHOD_NOT_ALLOWED, "DOWNLOAD not available on directories"); - - res.setOutput(new FileReader(f)).setContentType("application"); - } - - /** File POJO */ - public class FileResource { - private File f; - private URL url; - - /** Constructor */ - public FileResource(File f, URL url) { - this.f = f; - this.url = url; - } - - // Bean property getters - - public URL getUrl() { - return url; - } - - public String getType() { - return (f.isDirectory() ? "dir" : "file"); - } - - public String getName() { - return f.getName(); - } - - public long getSize() { - return f.length(); - } - - public Date getLastModified() { - return new Date(f.lastModified()); - } - - public URL getView() throws Exception { - if (allowViews && f.canRead() && ! f.isDirectory()) - return new URL(url + "?method=VIEW"); - return null; - } - - public URL getDownload() throws Exception { - if (allowViews && f.canRead() && ! f.isDirectory()) - return new URL(url + "?method=DOWNLOAD"); - return null; - } - - public URL getDelete() throws Exception { - if (allowDeletes && f.canWrite()) - return new URL(url + "?method=DELETE"); - return null; - } - } - - /** Utility method */ - private void deleteFile(File f) { - try { - if (f.isDirectory()) - for (File fc : f.listFiles()) - deleteFile(fc); - f.delete(); - } catch (Exception e) { - logger.log(WARNING, "Cannot delete file '" + f.getAbsolutePath() + "'", e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DockerRegistryResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DockerRegistryResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DockerRegistryResource.java deleted file mode 100644 index 80f59a0..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/DockerRegistryResource.java +++ /dev/null @@ -1,88 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.util.*; - -import javax.servlet.*; - -import org.apache.juneau.json.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.client.*; -import org.apache.juneau.rest.labels.*; - -/** - * Sample resource that shows how to mirror query results from a Docker registry. - */ -@RestResource( - path="/docker", - title="Sample Docker resource", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.AtomFeedResource)'}") - } -) -public class DockerRegistryResource extends Resource { - private static final long serialVersionUID = 1L; - - // Get registry URL from samples.cfg file. - private String registryUrl = getConfig().getString("DockerRegistry/url"); - - RestClient rc; - - @Override /* Servlet */ - public void init() throws ServletException { - super.init(); - rc = new RestClient(JsonSerializer.DEFAULT, JsonParser.DEFAULT); - } - - @Override /* Servlet */ - public void destroy() { - rc.closeQuietly(); - super.destroy(); - } - - /** [GET /] - Show child resources. */ - @SuppressWarnings("nls") - @RestMethod(name="GET", path="/") - public ResourceDescription[] getChildren(RestRequest req) { - return new ResourceDescription[] { - new ResourceDescription(req, "search", "Search Registry") - }; - } - - /** - * PUT request handler. - * Replaces the feed with the specified content, and then mirrors it as the response. - */ - @RestMethod(name="GET", path="/search") - public QueryResults query(@Query("q") String q) throws Exception { - String url = registryUrl + "/search" + (q == null ? "" : "?q=" + q); - synchronized(rc) { - return rc.doGet(url).getResponse(QueryResults.class); - } - } - - public static class QueryResults { - public int num_results; - public String query; - public List<DockerImage> results; - } - - public static class DockerImage { - public String name, description; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/HelloWorldResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/HelloWorldResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/HelloWorldResource.java deleted file mode 100644 index d89830f..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/HelloWorldResource.java +++ /dev/null @@ -1,38 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Sample REST resource that prints out a simple "Hello world!" message. - */ -@RestResource( - messages="nls/HelloWorldResource", - path="/helloWorld", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS'}") - } -) -public class HelloWorldResource extends Resource { - private static final long serialVersionUID = 1L; - - /** GET request handler */ - @RestMethod(name="GET", path="/*") - public String sayHello() { - return "Hello world!"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/JsonSchemaResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/JsonSchemaResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/JsonSchemaResource.java deleted file mode 100644 index 12a9de3..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/JsonSchemaResource.java +++ /dev/null @@ -1,74 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import org.apache.juneau.dto.jsonschema.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Sample resource that shows how to serialize JSON-Schema documents. - */ -@RestResource( - path="/jsonSchema", - messages="nls/JsonSchemaResource", - properties={ - @Property(name=HTMLDOC_title, value="Sample JSON-Schema document"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.JsonSchemaResource)'}") - } -) -public class JsonSchemaResource extends ResourceJena { - private static final long serialVersionUID = 1L; - - private Schema schema; // The schema document - - @Override /* Servlet */ - public void init() { - - try { - schema = new Schema() - .setId("http://example.com/sample-schema#") - .setSchemaVersionUri("http://json-schema.org/draft-04/schema#") - .setTitle("Example Schema") - .setType(JsonType.OBJECT) - .addProperties( - new SchemaProperty("firstName", JsonType.STRING), - new SchemaProperty("lastName", JsonType.STRING), - new SchemaProperty("age", JsonType.INTEGER) - .setDescription("Age in years") - .setMinimum(0) - ) - .addRequired("firstName", "lastName"); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** GET request handler */ - @RestMethod(name="GET", path="/") - public Schema getSchema() throws Exception { - return schema; - } - - /** - * PUT request handler. - * Replaces the schema document with the specified content, and then mirrors it as the response. - */ - @RestMethod(name="PUT", path="/") - public Schema setSchema(@Body Schema schema) throws Exception { - this.schema = schema; - return schema; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/MethodExampleResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/MethodExampleResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/MethodExampleResource.java deleted file mode 100644 index de7741c..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/MethodExampleResource.java +++ /dev/null @@ -1,91 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.util.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; - -/** - * Sample REST resource that shows how to define REST methods and OPTIONS pages - */ -@RestResource( - path="/methodExample", - messages="nls/MethodExampleResource", - properties={ - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.MethodExampleResource)'}") - } -) -public class MethodExampleResource extends Resource { - private static final long serialVersionUID = 1L; - - /** Example GET request that redirects to our example method */ - @RestMethod(name="GET", path="/") - public Redirect doGetExample() throws Exception { - return new Redirect("example1/xxx/123/{0}/xRemainder?p1=123&p2=yyy", UUID.randomUUID()); - } - - /** Example GET request using annotated attributes */ - @RestMethod(name="GET", path="/example1/{a1}/{a2}/{a3}/*", responses={@Response(200)}) - public String doGetExample1( - @Method String method, - @Path String a1, - @Path int a2, - @Path UUID a3, - @Query("p1") int p1, - @Query("p2") String p2, - @Query("p3") UUID p3, - @PathRemainder String remainder, - @Header("Accept-Language") String lang, - @Header("Accept") String accept, - @Header("DNT") int doNotTrack - ) { - String output = String.format( - "method=%s, a1=%s, a2=%d, a3=%s, remainder=%s, p1=%d, p2=%s, p3=%s, lang=%s, accept=%s, dnt=%d", - method, a1, a2, a3, remainder, p1, p2, p3, lang, accept, doNotTrack); - return output; - } - - /** Example GET request using methods on RestRequest and RestResponse */ - @RestMethod(name="GET", path="/example2/{a1}/{a2}/{a3}/*", responses={@Response(200)}) - public void doGetExample2(RestRequest req, RestResponse res) throws Exception { - String method = req.getMethod(); - - // Attributes (from URL pattern variables) - String a1 = req.getPathParameter("a1", String.class); - int a2 = req.getPathParameter("a2", int.class); - UUID a3 = req.getPathParameter("a3", UUID.class); - - // Optional GET parameters - int p1 = req.getQueryParameter("p1", int.class, 0); - String p2 = req.getQueryParameter("p2", String.class); - UUID p3 = req.getQueryParameter("p3", UUID.class); - - // URL pattern post-match - String remainder = req.getPathRemainder(); - - // Headers - String lang = req.getHeader("Accept-Language"); - int doNotTrack = req.getHeader("DNT", int.class); - - // Send back a simple String response - String output = String.format( - "method=%s, a1=%s, a2=%d, a3=%s, remainder=%s, p1=%d, p2=%s, p3=%s, lang=%s, dnt=%d", - method, a1, a2, a3, remainder, p1, p2, p3, lang, doNotTrack); - res.setOutput(output); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/PhotosResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/PhotosResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/PhotosResource.java deleted file mode 100644 index d98af30..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/PhotosResource.java +++ /dev/null @@ -1,142 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static javax.servlet.http.HttpServletResponse.*; -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import java.awt.image.*; -import java.io.*; -import java.net.*; -import java.net.URI; -import java.util.*; - -import javax.imageio.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.serializer.*; - -/** - * Sample resource that allows images to be uploaded and retrieved. - */ -@RestResource( - path="/photos", - messages="nls/PhotosResource", - properties={ - @Property(name=HTMLDOC_title, value="Photo REST service"), - @Property(name=HTMLDOC_description, value="Use a tool like Poster to upload and retrieve jpeg and png images."), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.PhotosResource)'}"), - // Resolve all relative URIs so that they're relative to this servlet! - @Property(name=SERIALIZER_relativeUriBase, value="$R{servletURI}"), - } -) -public class PhotosResource extends Resource { - private static final long serialVersionUID = 1L; - - // Our cache of photos - private Map<Integer,Photo> photos = new TreeMap<Integer,Photo>(); - - @Override /* Servlet */ - public void init() { - try { - // Preload an image. - InputStream is = getClass().getResourceAsStream("averycutecat.jpg"); - BufferedImage image = ImageIO.read(is); - Photo photo = new Photo(0, image); - photos.put(photo.id, photo); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** Our bean class for storing photos */ - public static class Photo { - int id; - BufferedImage image; - - Photo(int id, BufferedImage image) { - this.id = id; - this.image = image; - } - - public URI getURI() throws URISyntaxException { - return new URI(""+id); - } - } - - /** GET request handler for list of all photos */ - @RestMethod(name="GET", path="/") - public Collection<Photo> getAllPhotos() throws Exception { - return photos.values(); - } - - /** GET request handler for single photo */ - @RestMethod(name="GET", path="/{id}", serializers=ImageSerializer.class) - public BufferedImage getPhoto(@Path int id) throws Exception { - Photo p = photos.get(id); - if (p == null) - throw new RestException(SC_NOT_FOUND, "Photo not found"); - return p.image; - } - - /** PUT request handler */ - @RestMethod(name="PUT", path="/{id}", parsers=ImageParser.class) - public String addPhoto(@Path int id, @Body BufferedImage image) throws Exception { - photos.put(id, new Photo(id, image)); - return "OK"; - } - - /** POST request handler */ - @RestMethod(name="POST", path="/", parsers=ImageParser.class) - public Photo setPhoto(@Body BufferedImage image) throws Exception { - int id = photos.size(); - Photo p = new Photo(id, image); - photos.put(id, p); - return p; - } - - /** DELETE request handler */ - @RestMethod(name="DELETE", path="/{id}") - public String deletePhoto(@Path int id) throws Exception { - Photo p = photos.remove(id); - if (p == null) - throw new RestException(SC_NOT_FOUND, "Photo not found"); - return "OK"; - } - - /** Serializer for converting images to byte streams */ - @Produces("image/png,image/jpeg") - public static class ImageSerializer extends OutputStreamSerializer { - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - RenderedImage image = (RenderedImage)o; - String mediaType = session.getProperties().getString("mediaType"); - ImageIO.write(image, mediaType.substring(mediaType.indexOf('/')+1), session.getOutputStream()); - } - } - - /** Parser for converting byte streams to images */ - @Consumes("image/png,image/jpeg") - public static class ImageParser extends InputStreamParser { - @Override /* Parser */ - @SuppressWarnings("unchecked") - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - return (T)ImageIO.read(session.getInputStream()); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RequestEchoResource.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RequestEchoResource.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RequestEchoResource.java deleted file mode 100644 index be15567..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RequestEchoResource.java +++ /dev/null @@ -1,60 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import javax.servlet.*; -import javax.servlet.http.*; - -import org.apache.juneau.*; -import org.apache.juneau.microservice.*; -import org.apache.juneau.rest.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.converters.*; -import org.apache.juneau.transforms.*; - -/** - * Sample REST resource for echoing HttpServletRequests back to the browser. - */ -@RestResource( - path="/echo", - messages="nls/RequestEchoResource", - properties={ - @Property(name=SERIALIZER_maxDepth, value="5"), - @Property(name=SERIALIZER_detectRecursions, value="true"), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.RequestEchoResource)'}") - }, - beanFilters={ - // Interpret these as their parent classes, not subclasses - HttpServletRequest.class, HttpSession.class, ServletContext.class, - }, - pojoSwaps={ - // Add a special filter for Enumerations - EnumerationSwap.class - } -) -public class RequestEchoResource extends Resource { - private static final long serialVersionUID = 1L; - - /** GET request handler */ - @RestMethod(name="GET", path="/*", converters={Traversable.class,Queryable.class}) - public HttpServletRequest doGet(RestRequest req, @Properties ObjectMap properties) { - // Set the HtmlDocSerializer title programmatically. - // This sets the value for this request only. - properties.put(HTMLDOC_title, "Contents of HttpServletRequest object"); - - // Just echo the request back as the response. - return req; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RootResources.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RootResources.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RootResources.java deleted file mode 100644 index d75a426..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/RootResources.java +++ /dev/null @@ -1,55 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; - -import org.apache.juneau.microservice.*; -import org.apache.juneau.microservice.resources.*; -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.samples.addressbook.*; - -/** - * Sample REST resource showing how to implement a "router" resource page. - */ -@RestResource( - path="/", - messages="nls/RootResources", - properties={ - @Property(name=HTMLDOC_links, value="{options:'$R{servletURI}?method=OPTIONS',source:'$R{servletURI}/source?classes=(org.apache.juneau.rest.samples.RootResources)'}") - }, - children={ - HelloWorldResource.class, - SystemPropertiesResource.class, - MethodExampleResource.class, - RequestEchoResource.class, - TempDirResource.class, - AddressBookResource.class, - SampleRemoteableServlet.class, - PhotosResource.class, - AtomFeedResource.class, - JsonSchemaResource.class, - SqlQueryResource.class, - TumblrParserResource.class, - CodeFormatterResource.class, - UrlEncodedFormResource.class, - SourceResource.class, - ConfigResource.class, - LogsResource.class, - DockerRegistryResource.class, - ShutdownResource.class - } -) -public class RootResources extends ResourceGroup { - private static final long serialVersionUID = 1L; -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/e3d95284/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SampleRemoteableServlet.java ---------------------------------------------------------------------- diff --git a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SampleRemoteableServlet.java b/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SampleRemoteableServlet.java deleted file mode 100644 index 19e0259..0000000 --- a/juneau-samples/src/main/java/org/apache/juneau/rest/samples/SampleRemoteableServlet.java +++ /dev/null @@ -1,55 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.rest.samples; - -import static org.apache.juneau.html.HtmlDocSerializerContext.*; -import static org.apache.juneau.rest.RestServletContext.*; - -import java.util.*; - -import org.apache.juneau.rest.annotation.*; -import org.apache.juneau.rest.remoteable.*; -import org.apache.juneau.samples.addressbook.*; - -/** - * Class showing the functionality of the RemoteableServlet class. - */ -@SuppressWarnings("serial") -@RestResource( - path="/remoteable", - messages="nls/SampleRemoteableServlet", - properties={ - @Property(name=HTMLDOC_title, value="Remoteable Service Proxy API"), - @Property(name=HTMLDOC_description, value="Sample class showing how to use remoteable proxies. The list below are exposed services that can be retrieved using RestClient.getProxyInterface(Class)."), - @Property(name=HTMLDOC_links, value="{up:'$R{requestParentURI}',options:'$R{servletURI}?method=OPTIONS',source:'$R{servletParentURI}/source?classes=(org.apache.juneau.rest.samples.SampleRemoteableServlet)'}"), - // Allow us to use method=POST from a browser. - @Property(name=REST_allowMethodParam, value="*") - }, - stylesheet="styles/devops.css" -) -public class SampleRemoteableServlet extends RemoteableServlet { - - AddressBook addressBook = new AddressBook(); - - @Override /* RemoteableServlet */ - protected Map<Class<?>,Object> getServiceMap() throws Exception { - Map<Class<?>,Object> m = new LinkedHashMap<Class<?>,Object>(); - - // In this simplified example, we expose the same POJO service under two different interfaces. - // One is IAddressBook which only exposes methods defined on that interface, and - // the other is AddressBook itself which exposes all methods defined on the class itself. - m.put(IAddressBook.class, addressBook); - m.put(AddressBook.class, addressBook); - return m; - } -}
