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