001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.examples.rest; 014 015import org.apache.juneau.annotation.*; 016import org.apache.juneau.html.annotation.*; 017import org.apache.juneau.rest.annotation.*; 018import org.apache.juneau.rest.beans.*; 019import org.apache.juneau.rest.servlet.*; 020import org.apache.juneau.rest.widget.*; 021 022/** 023 * Sample resource that allows images to be uploaded and retrieved. 024 * 025 * <h5 class='section'>See Also:</h5><ul> 026 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.Marshalling">REST Marshalling</a> 027 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.UtilityBeans">Utility Beans</a> 028 * </ul> 029 */ 030@Rest( 031 path="/utilitybeans", 032 title="Utility beans examples", 033 description="Examples of utility bean usage." 034) 035@HtmlDocConfig( 036 widgets={ 037 ContentTypeMenuItem.class 038 }, 039 navlinks={ 040 "up: request:/..", 041 "api: servlet:/api", 042 "stats: servlet:/stats", 043 "$W{ContentTypeMenuItem}", 044 "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/UtilityBeansResource.java" 045 }, 046 aside={ 047 "<div class='text'>", 048 " <p>Examples of serialized beans in the org.apache.juneau.rest.utilitybeans package.</p>", 049 "</div>" 050 }, 051 asideFloat="RIGHT" 052) 053@SuppressWarnings("javadoc") 054public class UtilityBeansResource extends BasicRestObject { 055 056 @SuppressWarnings("unused") 057 private static final long serialVersionUID = 1L; 058 059 /** 060 * [HTTP GET /utilitybeans] 061 * @return Descriptive links to the child endpoints. 062 */ 063 @RestGet("/") 064 public ResourceDescriptions getChildDescriptions() { 065 return ResourceDescriptions 066 .create() 067 .append("BeanDescription", "Example of BeanDescription bean") 068 .append("Hyperlink", "Example of Hyperlink bean") 069 .append("SeeOtherRoot", "Example of SeeOtherRoot bean"); 070 } 071 072 /** 073 * [HTTP GET /utilitybeans/BeanDescription] 074 * @return Example of serialized org.apache.juneau.rest.utilitybeans.ResourceDescriptions bean. 075 */ 076 @RestGet("/BeanDescription") 077 @HtmlDocConfig( 078 aside={ 079 "<div class='text'>", 080 " <p>Example of serialized ResourceDescriptions bean.</p>", 081 "</div>" 082 } 083 ) 084 public BeanDescription aBeanDescription() { 085 return BeanDescription.of(Address.class); 086 } 087 088 @Bean(p="street,city,state,zip,isCurrent") 089 public static class Address { 090 public String street; 091 public String city; 092 public String state; 093 public int zip; 094 public boolean isCurrent; 095 096 public Address() {} 097 } 098 099 /** 100 * [HTTP GET /utilitybeans/Hyperlink] 101 * @return Example of serialized org.apache.juneau.rest.utilitybeans.Hyperlink bean. 102 */ 103 @RestGet("/Hyperlink") 104 @HtmlDocConfig( 105 aside={ 106 "<div class='text'>", 107 " <p>Example of serialized Hyperlink bean.</p>", 108 "</div>" 109 } 110 ) 111 public Hyperlink aHyperlink() { 112 return Hyperlink.create("/utilitybeans", "Back to /utilitybeans"); 113 } 114 115 /** 116 * [HTTP GET /utilitybeans/SeeOtherRoot] 117 * @return Example of serialized SeeOtherRoot bean. 118 * This just redirects back to the servlet root. 119 */ 120 @RestGet("/SeeOtherRoot") 121 @HtmlDocConfig( 122 aside={ 123 "<div class='text'>", 124 " <p>Example of serialized org.apache.juneau.rest.utilitybeans.SeeOtherRoot bean.</p>", 125 "</div>" 126 } 127 ) 128 public SeeOtherRoot aSeeOtherRoot() { 129 return SeeOtherRoot.INSTANCE; 130 } 131}