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 static org.apache.juneau.serializer.Serializer.*; 016 017import javax.servlet.*; 018import javax.servlet.http.*; 019 020import org.apache.juneau.jsonschema.annotation.ExternalDocs; 021import org.apache.juneau.http.annotation.*; 022import org.apache.juneau.rest.*; 023import org.apache.juneau.rest.annotation.*; 024import org.apache.juneau.rest.converters.*; 025import org.apache.juneau.rest.widget.*; 026import org.apache.juneau.transforms.*; 027 028/** 029 * Sample REST resource for echoing HttpServletRequests back to the browser. 030 */ 031@RestResource( 032 path="/echo", 033 title="Request echo service", 034 description="Echos the current HttpServletRequest object back to the browser.", 035 htmldoc=@HtmlDoc( 036 widgets={ 037 ContentTypeMenuItem.class, 038 ThemeMenuItem.class 039 }, 040 navlinks={ 041 "up: request:/..", 042 "options: servlet:/?method=OPTIONS", 043 "$W{ContentTypeMenuItem}", 044 "$W{ThemeMenuItem}", 045 "source: $C{Source/gitHub}/org/apache/juneau/examples/rest/$R{servletClassSimple}.java" 046 }, 047 aside={ 048 "<div style='max-width:400px;min-width:200px' class='text'>", 049 " <p>Shows how even arbitrary POJOs such as <code>HttpServletRequest</code> can be serialized by the framework.</p>", 050 " <p>Also shows how to specify serializer properties, filters, and swaps at the servlet level to control how POJOs are serialized.</p>", 051 " <p>Also provides an example of how to use the Traversable and Queryable APIs.</p>", 052 "</div>" 053 }, 054 nowrap="false" 055 ), 056 properties={ 057 @Property(name=BEANTRAVERSE_maxDepth, value="5"), 058 @Property(name=BEANTRAVERSE_detectRecursions, value="true") 059 }, 060 beanFilters={ 061 // Interpret these as their parent classes, not subclasses 062 HttpServletRequest.class, HttpSession.class, ServletContext.class, 063 }, 064 pojoSwaps={ 065 // Add a special filter for Enumerations 066 EnumerationSwap.class 067 }, 068 swagger=@ResourceSwagger( 069 contact=@Contact(name="Juneau Developer",email="dev@juneau.apache.org"), 070 license=@License(name="Apache 2.0",url="http://www.apache.org/licenses/LICENSE-2.0.html"), 071 version="2.0", 072 termsOfService="You are on your own.", 073 externalDocs=@ExternalDocs(description="Apache Juneau",url="http://juneau.apache.org") 074 ) 075) 076public class RequestEchoResource extends BasicRestServlet { 077 private static final long serialVersionUID = 1L; 078 079 /** GET request handler */ 080 @RestMethod(name="*", path="/*", converters={Traversable.class,Queryable.class}, summary="Serializes the incoming HttpServletRequest object.") 081 public HttpServletRequest doGet(RestRequest req, RestResponse res, RequestProperties properties) { 082 // Just echo the request back as the response. 083 return req; 084 } 085}