--- /dev/null
+notifications:
+ commits: commits@juneau.apache.org
+ issues: dev@juneau.apache.org
+ pullrequests: dev@juneau.apache.org
+ jira_options: link label worklog
+ jobs: dev@juneau.apache.org
+ discussions: dev@juneau.apache.org
+
+github:
+ description: "Apache Juneau"
+ homepage: https://juneau.apache.org/
+ labels:
+ - json
+ - juneau
+ - http
+ - rest
+ - apache
+ features:
+ wiki: true
+ issues: true
+ projects: true
\ No newline at end of file
// ***************************************************************************************************************************
package org.apache.juneau.petstore;
-import static org.apache.juneau.http.HttpMethod.*;
-
import java.util.*;
-import org.apache.juneau.jsonschema.annotation.Items;
import org.apache.juneau.petstore.dto.*;
import org.apache.juneau.*;
import org.apache.juneau.http.annotation.*;
import org.apache.juneau.http.remote.*;
-import org.apache.juneau.http.exception.*;
import org.apache.juneau.http.response.*;
/**
* @return All pets in the database.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/pet")
+ @RemoteGet("/pet")
public Collection<Pet> getPets() throws NotAcceptable;
/**
* @throws IdNotFound Pet was not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(path="/pet/{petId}") /* method inferred from method name */
+ @RemoteGet("/pet/{petId}") /* method inferred from method name */
public Pet getPet(
@Path(
name="petId",
- description="ID of pet to return",
- example="123"
+ schema=@Schema(description="ID of pet to return")
)
long petId
) throws IdNotFound, NotAcceptable;
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=POST, path="/pet")
+ @RemotePost("/pet")
public long createPet(
- @Body(
- description="Pet object to add to the store"
- ) CreatePet pet
+ @Content(
+ schema=@Schema(description="Pet object to add to the store")
+ )
+ CreatePet pet
) throws IdConflict, NotAcceptable, UnsupportedMediaType;
/**
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=PUT, path="/pet/{petId}")
+ @RemotePut("/pet/{petId}")
public Ok updatePet(
- @Body(
- description="Pet object that needs to be added to the store"
- ) UpdatePet pet
+ @Content(
+ schema=@Schema(description="Pet object that needs to be added to the store")
+ )
+ UpdatePet pet
) throws IdNotFound, NotAcceptable, UnsupportedMediaType;
/**
* @return The pets that match the specified statuses.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/pet/findByStatus")
+ @RemoteGet("/pet/findByStatus")
public Collection<Pet> findPetsByStatus(
@Query(
name="status",
- description="Status values that need to be considered for filter.",
- required=true,
- type="array",
- collectionFormat="csv",
- items=@Items(
- type="string",
- _enum="AVAILABLE,PENDING,SOLD",
- _default="AVAILABLE"
- ),
- example="AVALIABLE,PENDING"
+ schema=@Schema(
+ description="Status values that need to be considered for filter.",
+ required=true,
+ type="array",
+ collectionFormat="csv",
+ items=@Items(
+ type="string",
+ _enum="AVAILABLE,PENDING,SOLD",
+ _default="AVAILABLE"
+ )
+ )
)
PetStatus[] status
) throws NotAcceptable;
* @throws IdNotFound Pet not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=DELETE, path="/pet/{petId}")
+ @RemoteDelete("/pet/{petId}")
public Ok deletePet(
@Header(
name="api_key",
- description="Security API key",
- required=true,
- example="foobar"
+ schema=@Schema(
+ description="Security API key",
+ required=true
+ )
)
String apiKey,
@Path(
name="petId",
- description="Pet id to delete",
- example="123"
+ schema=@Schema(description="Pet id to delete")
)
long petId
) throws IdNotFound, NotAcceptable;
*
* @return {@link Ok} if successful.
*/
- @RemoteMethod(method=DELETE, path="/pet")
+ @RemoteDelete("/pet")
public Ok deleteAllPets();
//------------------------------------------------------------------------------------------------------------------
* @return All orders in the database.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/store/order")
+ @RemoteGet("/store/order")
public Collection<Order> getOrders() throws NotAcceptable;
/**
* @throws IdNotFound Order was not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/store/order/{orderId}")
+ @RemoteGet("/store/order/{orderId}")
public Order getOrder(
@Path(
name="orderId",
- description="ID of order to fetch",
- maximum="1000",
- minimum="1",
- example="123"
+ schema=@Schema(
+ description="ID of order to fetch",
+ maximum="1000",
+ minimum="1"
+ )
)
long orderId
) throws InvalidId, IdNotFound, NotAcceptable;
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=POST, path="/store/order")
+ @RemotePost("/store/order")
public long placeOrder(
@FormData(
name="petId",
- description="Pet ID"
+ schema=@Schema(description="Pet ID")
)
long petId,
@FormData(
name="username",
- description="The username of the user creating the order"
+ schema=@Schema(description="The username of the user creating the order")
)
String username
) throws IdConflict, NotAcceptable, UnsupportedMediaType;
* @throws IdNotFound Order not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=DELETE, path="/store/order/{orderId}")
+ @RemoteDelete("/store/order/{orderId}")
public Ok deleteOrder(
@Path(
name="orderId",
- description="ID of the order that needs to be deleted",
- minimum="1",
- example="5"
+ schema=@Schema(
+ description="ID of the order that needs to be deleted",
+ minimum="1"
+ )
)
long orderId
) throws InvalidId, IdNotFound, NotAcceptable;
*
* @return {@link Ok} if successful.
*/
- @RemoteMethod(method=DELETE, path="/store/order")
+ @RemoteDelete("/store/order")
public Ok deleteAllOrders();
/**
* @return An inventory of pet statuses and counts.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/store/inventory")
+ @RemoteGet("/store/inventory")
public Map<PetStatus,Integer> getStoreInventory() throws NotAcceptable;
//------------------------------------------------------------------------------------------------------------------
* @return All users in the database.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/user")
+ @RemoteGet("/user")
public Collection<User> getUsers() throws NotAcceptable;
/**
* @throws IdNotFound username not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/user/{username}")
+ @RemoteGet("/user/{username}")
public User getUser(
@Path(
name="username",
- description="The name that needs to be fetched. Use user1 for testing."
+ schema=@Schema(description="The name that needs to be fetched. Use user1 for testing.")
)
String username
) throws InvalidUsername, IdNotFound, NotAcceptable;
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=POST, path="/user")
+ @RemotePost("/user")
public Ok createUser(
- @Body(
- description="Created user object"
+ @Content(
+ schema=@Schema(description="Created user object")
)
User user
) throws InvalidUsername, IdConflict, NotAcceptable, UnsupportedMediaType;
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=POST, path="/user/createWithArray")
+ @RemotePost("/user/createWithArray")
public Ok createUsers(
- @Body(
- description="List of user objects"
+ @Content(
+ schema=@Schema(description="List of user objects")
)
User[] users
) throws InvalidUsername, IdConflict, NotAcceptable, UnsupportedMediaType;
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
* @throws UnsupportedMediaType Unsupported <c>Content-Type</c> header specified.
*/
- @RemoteMethod(method=PUT, path="/user/{username}")
+ @RemotePut("/user/{username}")
public Ok updateUser(
@Path(
name="username",
- description="Name that need to be updated"
+ schema=@Schema(description="Name that need to be updated")
)
String username,
- @Body(
- description="Updated user object"
+ @Content(
+ schema=@Schema(description="Updated user object")
)
User user
) throws InvalidUsername, IdNotFound, NotAcceptable, UnsupportedMediaType;
* @throws IdNotFound User was not found.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=DELETE, path="/user/{username}")
+ @RemoteDelete("/user/{username}")
public Ok deleteUser(
@Path(
name="username",
- description="The name that needs to be deleted"
+ schema=@Schema(description="The name that needs to be deleted")
)
String username
) throws InvalidUsername, IdNotFound, NotAcceptable;
*
* @return {@link Ok} if successful.
*/
- @RemoteMethod(method=DELETE, path="/user")
+ @RemoteDelete("/user")
public Ok deleteAllUsers();
/**
*
* @param username The username for login.
* @param password The password for login in clear text.
- * @param rateLimit Calls per hour allowed by the user.
* @param expiresAfter The <bc>Expires-After</bc> response header.
* @return {@link Ok} if successful.
* @throws InvalidLogin Login was unsuccessful.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/user/login")
+ @RemoteGet("/user/login")
public Ok login(
@Query(
name="username",
- description="The username for login.",
- required=true,
- example="myuser"
+ schema=@Schema(
+ description="The username for login.",
+ required=true
+ )
)
String username,
@Query(
name="password",
- description="The password for login in clear text.",
- required=true,
- example="abc123"
+ schema=@Schema(
+ description="The password for login in clear text.",
+ required=true
+ )
)
String password,
- @ResponseHeader(
- name="X-Rate-Limit",
- type="integer",
- format="int32",
- description="Calls per hour allowed by the user.",
- example="123"
- )
- Value<Integer> rateLimit,
Value<ExpiresAfter> expiresAfter
) throws InvalidLogin, NotAcceptable;
* @return {@link Ok} if successful.
* @throws NotAcceptable Unsupported <c>Accept</c> header specified.
*/
- @RemoteMethod(method=GET, path="/user/logout")
+ @RemoteGet("/user/logout")
public Ok logout() throws NotAcceptable;
}
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(fluentSetters=true, properties="petId,username")
+@Bean(findFluentSetters=true, properties="petId,username")
public class CreateOrder {
private long petId;
package org.apache.juneau.petstore.dto;
import org.apache.juneau.annotation.*;
-import org.apache.juneau.jsonschema.annotation.*;
+import org.apache.juneau.http.annotation.Schema;
/**
* Bean for creating {@link Pet} objects.
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(fluentSetters=true, properties="name,price,species,tags")
+@Bean(findFluentSetters=true, properties="name,price,species,tags")
public class CreatePet {
@Schema(description="Pet name.", minLength=3, maxLength=50)
@Schema(description="Pet species.")
private Species species;
- @Schema(description="Pet attributes.", example="friendly,smart")
+ @Schema(description="Pet attributes.")
private String[] tags;
/**
* <li class='extlink'>{@source}
* </ul>
*/
-@ResponseHeader(
+@Header(
name="X-Expires-After",
- type="string",
- format="date-time",
- description="Date in UTC when token expires",
- example="2012-10-21"
+ schema=@Schema(
+ type="string",
+ format="date-time",
+ description="Date in UTC when token expires"
+ )
)
public class ExpiresAfter {
private final Calendar c;
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.Conflict;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="ID already in use")
+@Response(schema=@Schema(description="ID already in use"))
public class IdConflict extends Conflict {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.NotFound;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="ID not found")
+@Response
public class IdNotFound extends NotFound {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.BadRequest;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="Invalid ID provided")
+@Response(schema=@Schema(description="Invalid ID provided"))
public class InvalidId extends BadRequest {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.Unauthorized;
/**
* Exception thrown when an invalid username or password is provided.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="Invalid username or password provided")
+@Response(schema=@Schema(description="Invalid username or password provided"))
public class InvalidLogin extends Unauthorized {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.BadRequest;
/**
* Exception thrown when an invalid species is looked up.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="Invalid species provided")
+@Response(schema=@Schema(description="Invalid species provided"))
public class InvalidSpecies extends BadRequest {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.BadRequest;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="Invalid tag provided")
+@Response(schema=@Schema(description="Invalid tag provided"))
public class InvalidTag extends BadRequest {
/**
package org.apache.juneau.petstore.dto;
import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.exception.*;
+import org.apache.juneau.http.response.BadRequest;
/**
* Exception thrown when trying to add an entry where the ID is already in use.
* </ul>
*/
@SuppressWarnings("serial")
-@Response(description="Invalid username provided")
+@Response(schema=@Schema(description="Invalid username provided"))
public class InvalidUsername extends BadRequest {
/**
import org.apache.juneau.annotation.*;
import org.apache.juneau.html.annotation.*;
+import org.apache.juneau.http.annotation.Schema;
import org.apache.juneau.internal.*;
-import org.apache.juneau.jsonschema.annotation.*;
-import org.apache.juneau.transforms.*;
+import org.apache.juneau.swaps.TemporalDateSwap;
/**
* Order bean.
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(fluentSetters=true, properties="id,petId,username,status,shipDate")
+@Bean(findFluentSetters=true, properties="id,petId,username,status,shipDate")
@Example("{id:123,petId:456,shipDate:'2012-12-21',status:'APPROVED'}")
@Entity(name="PetstoreOrder")
public class Order {
.username("sampleuser")
.petId(456)
.status(OrderStatus.APPROVED)
- .shipDate(DateUtils.parseISO8601("2020-10-10"))
+ .shipDate(DateUtils.parseISO8601Calendar("2020-10-10").getTime())
;
}
}
import org.apache.juneau.annotation.*;
import org.apache.juneau.html.*;
import org.apache.juneau.html.annotation.*;
-import org.apache.juneau.jsonschema.annotation.*;
+import org.apache.juneau.http.annotation.Schema;
import org.apache.juneau.serializer.*;
/**
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(typeName="Pet", fluentSetters=true, properties="id,species,name,tags,price,status")
+@Bean(typeName="Pet", findFluentSetters=true, properties="id,species,name,tags,price,status")
@Entity(name="PetstorePet")
public class Pet {
private Species species;
@ElementCollection(fetch=FetchType.EAGER) @OrderColumn
- @Schema(description="Pet attributes.", example="friendly,smart")
+ @Schema(description="Pet attributes.")
private List<String> tags;
@Column @Enumerated(STRING)
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(typeName="Tag", fluentSetters=true)
+@Bean(typeName="Tag", findFluentSetters=true)
@Swap(PetTagNameSwap.class)
public class PetTag {
private long id;
package org.apache.juneau.petstore.dto;
import org.apache.juneau.*;
-import org.apache.juneau.http.*;
-import org.apache.juneau.transform.*;
+import org.apache.juneau.http.header.MediaType;
+import org.apache.juneau.swap.StringSwap;
/**
* Swap for {@link PetTag} beans.
* <li class='extlink'>{@source}
* </ul>
*/
-public class PetTagNameSwap extends PojoSwap<PetTag,String> {
+public class PetTagNameSwap extends StringSwap<PetTag> {
/**
* Swap PetTag with name.
package org.apache.juneau.petstore.dto;
import org.apache.juneau.annotation.*;
-import org.apache.juneau.jsonschema.annotation.*;
+import org.apache.juneau.http.annotation.Schema;
/**
* Bean for updating {@link Pet} objects.
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(fluentSetters=true, properties="id,name,price,species,tags,status")
+@Bean(findFluentSetters=true, properties="id,name,price,species,tags,status")
public class UpdatePet extends CreatePet {
@Schema(description="Pet identifier.", minimum="1")
import org.apache.juneau.annotation.*;
import org.apache.juneau.html.annotation.*;
-import org.apache.juneau.jsonschema.annotation.*;
+import org.apache.juneau.http.annotation.Schema;
/**
* User bean.
* <li class='extlink'>{@source}
* </ul>
*/
-@Bean(typeName="User", fluentSetters=true, properties="username,firstName,lastName,email,password,phone,userStatus")
+@Bean(typeName="User", findFluentSetters=true, properties="username,firstName,lastName,email,password,phone,userStatus")
@Entity(name="PetstoreUser")
public class User {
import org.apache.juneau.marshall.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.petstore.dto.*;
-import org.apache.juneau.rest.client2.*;
+import org.apache.juneau.rest.client.*;
/**
* Example code showing how to connect to the PetStore application using a remote proxy.
<maven.javadoc.skip>true</maven.javadoc.skip>
- <juneau.version>8.2.0</juneau.version>
+ <juneau.version>9.0.0-SNAPSHOT</juneau.version>
</properties>
<packaging>war</packaging>
import java.io.*;
+import javax.servlet.*;
+
+import org.apache.juneau.petstore.rest.*;
import org.apache.juneau.petstore.service.*;
-import org.apache.juneau.rest.springboot.JuneauRestInitializer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.*;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.*;
+import org.springframework.context.annotation.*;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.stereotype.*;
/**
* Entry point for PetStore application.
@EnableJpaRepositories(basePackages = "org.apache.juneau.petstore")
@EnableCaching
@SuppressWarnings("javadoc")
+@Controller
public class App {
- public static void main(String[] args) {
- new App().start(args);
- }
-
- protected void start(String[] args) {
- ConfigurableApplicationContext ctx = new SpringApplicationBuilder(App.class)
- .initializers(new JuneauRestInitializer(App.class)) // Needed for Juneau resources as injectible Spring beans.
- .run(args);
+ //-----------------------------------------------------------------------------------------------------------------
+ // Beans
+ //-----------------------------------------------------------------------------------------------------------------
+ public static void main(String[] args) {
try {
+ ConfigurableApplicationContext ctx = new SpringApplicationBuilder(App.class).run(args);
ctx.getBean(PetStoreService.class).initDirect(new PrintWriter(System.out));
} catch (Exception e) {
e.printStackTrace();
}
}
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Beans
+ //-----------------------------------------------------------------------------------------------------------------
+
+ @Bean
+ public PetStoreService petStoreService() {
+ return new PetStoreService();
+ }
+
+ @Bean
+ public RootResources rootResources() {
+ return new RootResources();
+ }
+
+ @Bean
+ public PetStoreResource petStoreResource() {
+ return new PetStoreResource();
+ }
+
+ @Bean
+ public ServletRegistrationBean<Servlet> getRootServlet(RootResources rootResources) {
+ return new ServletRegistrationBean<>(rootResources, "/*");
+ }
}
+++ /dev/null
-// ***************************************************************************************************************************
-// * 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.petstore;
-
-
-import org.apache.juneau.petstore.rest.*;
-import org.apache.juneau.petstore.service.*;
-import org.apache.juneau.rest.springboot.annotation.JuneauRestRoot;
-import org.springframework.context.annotation.*;
-
-@SuppressWarnings("javadoc")
-@Configuration
-public class AppConfiguration {
-
- //-----------------------------------------------------------------------------------------------------------------
- // Services
- //-----------------------------------------------------------------------------------------------------------------
-
- @Bean
- public PetStoreService petStoreService() {
- return new PetStoreService();
- }
-
- //-----------------------------------------------------------------------------------------------------------------
- // REST
- //-----------------------------------------------------------------------------------------------------------------
-
- @Bean
- @JuneauRestRoot
- public RootResources rootResources2() {
- return new RootResources();
- }
-
- @Bean
- public PetStoreResource petStoreResource() {
- return new PetStoreResource();
- }
-}
// ***************************************************************************************************************************\r
package org.apache.juneau.petstore.rest;\r
\r
-import static org.apache.juneau.dto.swagger.ui.SwaggerUI.*;\r
-import static org.apache.juneau.http.HttpMethod.*;\r
import static org.apache.juneau.http.response.Ok.*;\r
\r
import java.util.*;\r
import java.util.Map;\r
\r
-import org.apache.juneau.jsonschema.annotation.*;\r
import org.apache.juneau.petstore.*;\r
import org.apache.juneau.petstore.dto.*;\r
import org.apache.juneau.petstore.service.*;\r
import org.apache.juneau.http.annotation.*;\r
import org.apache.juneau.rest.*;\r
import org.apache.juneau.rest.annotation.*;\r
-import org.apache.juneau.http.exception.*;\r
-import org.apache.juneau.rest.helper.*;\r
+import org.apache.juneau.rest.beans.*;\r
+import org.apache.juneau.rest.config.*;\r
+import org.apache.juneau.rest.converter.*;\r
+import org.apache.juneau.rest.servlet.*;\r
import org.apache.juneau.http.response.*;\r
import org.apache.juneau.rest.widget.*;\r
-import org.apache.juneau.transforms.*;\r
+import org.apache.juneau.swaps.*;\r
import org.springframework.beans.factory.annotation.*;\r
-import org.springframework.web.bind.annotation.CrossOrigin;\r
-import org.apache.juneau.rest.converters.*;\r
\r
/**\r
* Sample Petstore application.\r
"This is a sample server Petstore server based on the Petstore sample at Swagger.io.",\r
"You can find out more about Swagger at http://swagger.io.",\r
},\r
- properties= {\r
- // Resolve recursive references when showing schema info in the swagger.\r
- @Property(name=SWAGGERUI_resolveRefsMaxDepth, value="99")\r
- },\r
- swagger=@ResourceSwagger(\r
+ swagger=@Swagger(\r
version="1.0.0",\r
title="Swagger Petstore",\r
termsOfService="You are on your own.",\r
)\r
)\r
}\r
- ),\r
- staticFiles={"htdocs:/htdocs"} // Expose static files in htdocs subpackage.\r
+ )\r
)\r
@HtmlDocConfig(\r
widgets={\r
},\r
navlinks={\r
"up: request:/..",\r
- "options: servlet:/?method=OPTIONS",\r
+ "api: servlet:/api",\r
+ "stats: servlet:/stats",\r
"$W{ContentTypeMenuItem}",\r
"source: $C{Source/gitHub}/org/apache/juneau/petstore/rest/$R{servletClassSimple}.java"\r
},\r
"<link rel='icon' href='$U{servlet:/htdocs/cat.png}'/>" // Add a cat icon to the page.\r
},\r
header={\r
- "<h1>$R{resourceTitle}</h1>",\r
- "<h2>$R{methodSummary}</h2>",\r
+ "<h1>$RS{title}</h1>", // Use @Rest(title)\r
+ "<h2>$RS{operationSummary,description}</h2>", // Use either @RestOp(summary) or @Rest(description)\r
"$C{PetStore/headerImage}"\r
},\r
aside={\r
},\r
stylesheet="servlet:/htdocs/themes/dark.css" // Use dark theme by default.\r
)\r
-public class PetStoreResource extends BasicRest implements PetStore {\r
+public class PetStoreResource extends BasicRestObject implements BasicUniversalConfig, PetStore {\r
\r
@Autowired\r
private PetStoreService store;\r
*\r
* @return Navigation page contents.\r
*/\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/",\r
summary="Navigation page"\r
)\r
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/pet",\r
summary="All pets in the store",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet",\r
parameters={\r
Queryable.SWAGGER_PARAMS // Documents searching.\r
),\r
converters={Queryable.class} // Searching support.\r
)\r
- @BeanConfig(\r
- bpx="Pet: tags,photo" // In this view, don't serialize tags/photos properties.\r
- )\r
+ @Bean(on="Pet", excludeProperties="tags,photo")\r
public Collection<Pet> getPets() throws NotAcceptable {\r
return store.getPets();\r
}\r
\r
@Override /* PetStore */\r
- @CrossOrigin(origins = "http://localhost:3000", maxAge = 3600)\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/pet/{petId}",\r
summary="Find pet by ID",\r
description="Returns a single pet",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=POST,\r
+ @RestPost(\r
path="/pet",\r
summary="Add a new pet to the store",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet"\r
)\r
//roleGuard="ROLE_ADMIN || (ROLE_USER && ROLE_WRITABLE)" // Restrict access to this method.\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=PUT,\r
+ @RestPut(\r
path="/pet/{petId}",\r
summary="Update an existing pet",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/pet/findByStatus",\r
summary="Finds Pets by status",\r
description="Multiple status values can be provided with comma separated strings.",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/pet/{petId}",\r
summary="Deletes a pet",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="pet"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/pets",\r
summary="Delete all pets",\r
description="This can be done only by the logged in user."\r
*\r
* @return Store navigation page contents.\r
*/\r
- @RestMethod(\r
+ @RestGet(\r
summary="Store navigation page",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/store/order",\r
summary="Petstore orders",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/store/order/{orderId}",\r
summary="Find purchase order by ID",\r
description="Returns a purchase order by ID.",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=POST,\r
+ @RestPost(\r
path="/store/order",\r
summary="Place an order for a pet",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store"\r
- ),\r
- pojoSwaps={\r
- TemporalDateSwap.IsoLocalDate.class\r
- }\r
+ )\r
+ )\r
+ @BeanConfig(\r
+ swaps = TemporalDateSwap.IsoLocalDate.class\r
)\r
public long placeOrder(long petId, String username) throws IdConflict, NotAcceptable, UnsupportedMediaType {\r
CreateOrder co = new CreateOrder(petId, username);\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/store/order/{orderId}",\r
summary="Delete purchase order by ID",\r
description= {\r
"For valid response try integer IDs with positive integer value.",\r
"Negative or non-integer values will generate API errors."\r
},\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/orders",\r
summary="Delete all orders",\r
description="This can be done only by the logged in user."\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/store/inventory",\r
summary="Returns pet inventories by status",\r
description="Returns a map of status codes to quantities",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="store",\r
responses={\r
"200:{ 'x-example':{AVAILABLE:123} }",\r
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/user",\r
summary="Petstore users",\r
- bpx="User: email,password,phone",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
+ @Bean(on="User", excludeProperties="email,password,phone")\r
public Collection<User> getUsers() throws NotAcceptable {\r
return store.getUsers();\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/user/{username}",\r
summary="Get user by user name",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=POST,\r
+ @RestPost(\r
path="/user",\r
summary="Create user",\r
description="This can only be done by the logged in user.",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=POST,\r
+ @RestPost(\r
path="/user/createWithArray",\r
summary="Creates list of users with given input array",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=PUT,\r
+ @RestPut(\r
path="/user/{username}",\r
summary="Update user",\r
description="This can only be done by the logged in user.",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/user/{username}",\r
summary="Delete user",\r
description="This can only be done by the logged in user.",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=DELETE,\r
+ @RestDelete(\r
path="/users",\r
summary="Delete all users",\r
description="This can be done only by the admin."\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/user/login",\r
summary="Logs user into the system",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
public Ok login(\r
String username,\r
String password,\r
- Value<Integer> rateLimit,\r
Value<ExpiresAfter> expiresAfter\r
) throws InvalidLogin, NotAcceptable {\r
\r
\r
Date d = new Date(System.currentTimeMillis() + 30 * 60 * 1000);\r
req.getSession().setAttribute("login-expires", d);\r
- rateLimit.set(1000);\r
expiresAfter.set(new ExpiresAfter(d));\r
return OK;\r
}\r
\r
@Override /* PetStore */\r
- @RestMethod(\r
- name=GET,\r
+ @RestGet(\r
path="/user/logout",\r
summary="Logs out current logged in user session",\r
- swagger=@MethodSwagger(\r
+ swagger=@OpSwagger(\r
tags="user"\r
)\r
)\r
package org.apache.juneau.petstore.rest;\r
\r
import org.apache.juneau.html.annotation.*;\r
-import org.apache.juneau.rest.*;\r
import org.apache.juneau.rest.annotation.*;\r
+import org.apache.juneau.rest.config.*;\r
+import org.apache.juneau.rest.servlet.*;\r
import org.apache.juneau.rest.widget.*;\r
\r
/**\r
ContentTypeMenuItem.class\r
},\r
navlinks={\r
- "options: ?method=OPTIONS",\r
+ "api: servlet:/api",\r
+ "stats: servlet:/stats",\r
"$W{ContentTypeMenuItem}",\r
"source: $C{Source/gitHub}/org/apache/juneau/petstore/rest/$R{servletClassSimple}.java"\r
},\r
"</div>"\r
}\r
)\r
-public class RootResources extends BasicRestServletGroup {\r
+public class RootResources extends BasicRestServletGroup implements BasicUniversalConfig {\r
private static final long serialVersionUID = 1L;\r
}\r
import org.apache.juneau.petstore.App;
import org.apache.juneau.petstore.dto.*;
import org.apache.juneau.petstore.rest.PetStoreResource;
-import org.apache.juneau.rest.client2.*;
-import org.apache.juneau.rest.mock2.*;
+import org.apache.juneau.rest.client.*;
+import org.apache.juneau.rest.mock.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
int petId = petStoreRest
.post("/pet", new CreatePet().name("Sunshine").price(100f).species(Species.BIRD).tags("nice"))
.run()
- .assertStatus().code().is(200)
- .getBody().as(int.class);
+ .assertStatus().asCode().is(200)
+ .getContent().as(int.class);
return petId;
}
petStoreRest
.delete("/pets")
.complete() // Use complete() because we're not consuming response.
- .assertStatus().code().is(200);
+ .assertStatus().asCode().is(200);
}
// Delete pet by Id
petStoreRest
.delete("/pet/" + petId)
.complete()
- .assertStatus().code().is(200);
+ .assertStatus().asCode().is(200);
}
// Getting all pets
petStoreRest
.get("/pet")
.run()
- .assertStatus().code().is(200)
- .assertBody().is("[{id:" + petId + ",species:'BIRD',name:'Sunshine',price:100.0,status:'AVAILABLE'}]");
+ .assertStatus().asCode().is(200)
+ .assertContent().is("[{id:" + petId + ",species:'BIRD',name:'Sunshine',price:100.0,status:'AVAILABLE'}]");
deleteTestPets();
}
petStoreRest
.post("/pet", new CreatePet().name("Sunshine").price(100f).species(Species.BIRD).tags("nice"))
.complete()
- .assertStatus().code().is(200);
+ .assertStatus().asCode().is(200);
deleteTestPets();
}
.get("/pet/" + petId)
.run()
.assertCode().is(200)
- .assertBody().is("{id:" + petId + ",species:'BIRD',name:'Sunshine',tags:['nice'],price:100.0,status:'AVAILABLE'}");
+ .assertContent().is("{id:" + petId + ",species:'BIRD',name:'Sunshine',tags:['nice'],price:100.0,status:'AVAILABLE'}");
deleteTestPets();
.get("/pet/findByStatus?status=AVAILABLE")
.run()
.assertCode().is(200)
- .assertBody().is("[{id:" + petId + ",species:'BIRD',name:'Sunshine',tags:['nice'],price:100.0,status:'AVAILABLE'}]");
+ .assertContent().is("[{id:" + petId + ",species:'BIRD',name:'Sunshine',tags:['nice'],price:100.0,status:'AVAILABLE'}]");
deleteTestPets();
}
.get("/user")
.run()
.assertCode().is(200)
- .assertBody().is("[{username:'doglover',firstName:'Tom',lastName:'Simon',userStatus:'ACTIVE'}]");
+ .assertContent().is("[{username:'doglover',firstName:'Tom',lastName:'Simon',userStatus:'ACTIVE'}]");
deleteTestUsers();
}
.get("/user/garfield")
.run()
.assertCode().is(200)
- .assertBody().is("{username:'garfield',firstName:'Tom',lastName:'Simon',userStatus:'ACTIVE'}");
+ .assertContent().is("{username:'garfield',firstName:'Tom',lastName:'Simon',userStatus:'ACTIVE'}");
deleteTestUsers();
}
)
.run()
.assertCode().is(200)
- .getBody().as(int.class);
+ .getContent().as(int.class);
return orderId;
}
.get("/store/order")
.run()
.assertCode().is(200)
- .assertBody().is("[{id:" + orderId + ",petId:0,status:'PLACED'}]");
+ .assertContent().is("[{id:" + orderId + ",petId:0,status:'PLACED'}]");
deleteTestOrders();
.get("/store/order/" + orderId)
.run()
.assertCode().is(200)
- .assertBody().is("{id:" + orderId + ",petId:0,status:'PLACED'}");
+ .assertContent().is("{id:" + orderId + ",petId:0,status:'PLACED'}");
deleteTestOrders();
}
<maven.compiler.target>18</maven.compiler.target>
<httpclient.version>4.5.6</httpclient.version>
- <juneau.version>8.2.0</juneau.version>
+ <juneau.version>9.0-B1-SNAPSHOT</juneau.version>
<derby.version>10.10.2.0</derby.version>
<hibernate.version>5.0.9.Final</hibernate.version>
</properties>