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 /** 060 * Sample address bean used for demonstrating utility bean functionality. 061 */ 062 @Bean(p = "street,city,state,zip,isCurrent") 063 public static class Address { 064 065 /** Street address. */ 066 public String street; 067 068 /** City name. */ 069 public String city; 070 071 /** State abbreviation. */ 072 public String state; 073 074 /** ZIP code. */ 075 public int zip; 076 077 /** Whether this is the current address. */ 078 public boolean isCurrent; 079 080 /** Default constructor. */ 081 public Address() {} 082 } 083 084 @SuppressWarnings("unused") 085 private static final long serialVersionUID = 1L; 086 087 /** 088 * [HTTP GET /utilitybeans/BeanDescription] 089 * @return Example of serialized org.apache.juneau.rest.utilitybeans.ResourceDescriptions bean. 090 */ 091 @RestGet("/BeanDescription") 092 @HtmlDocConfig( 093 aside={ 094 "<div class='text'>", 095 " <p>Example of serialized ResourceDescriptions bean.</p>", 096 "</div>" 097 } 098 ) 099 public BeanDescription aBeanDescription() { 100 return BeanDescription.of(Address.class); 101 } 102 103 /** 104 * [HTTP GET /utilitybeans/Hyperlink] 105 * @return Example of serialized org.apache.juneau.rest.utilitybeans.Hyperlink bean. 106 */ 107 @RestGet("/Hyperlink") 108 @HtmlDocConfig( 109 aside={ 110 "<div class='text'>", 111 " <p>Example of serialized Hyperlink bean.</p>", 112 "</div>" 113 } 114 ) 115 public Hyperlink aHyperlink() { 116 return Hyperlink.create("/utilitybeans", "Back to /utilitybeans"); 117 } 118 119 /** 120 * [HTTP GET /utilitybeans/SeeOtherRoot] 121 * @return Example of serialized SeeOtherRoot bean. 122 * This just redirects back to the servlet root. 123 */ 124 @RestGet("/SeeOtherRoot") 125 @HtmlDocConfig( 126 aside={ 127 "<div class='text'>", 128 " <p>Example of serialized org.apache.juneau.rest.utilitybeans.SeeOtherRoot bean.</p>", 129 "</div>" 130 } 131 ) 132 public SeeOtherRoot aSeeOtherRoot() { 133 return SeeOtherRoot.INSTANCE; 134 } 135 136 /** 137 * [HTTP GET /utilitybeans] 138 * @return Descriptive links to the child endpoints. 139 */ 140 @RestGet("/") 141 public ResourceDescriptions getChildDescriptions() { 142 return ResourceDescriptions 143 .create() 144 .append("BeanDescription", "Example of BeanDescription bean") 145 .append("Hyperlink", "Example of Hyperlink bean") 146 .append("SeeOtherRoot", "Example of SeeOtherRoot bean"); 147 } 148}