GH-1034 Finish merging work to support web workloads in serverless environments
Resolves #1034
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
<modules>
|
||||
<module>spring-cloud-function-adapter-aws</module>
|
||||
<module>spring-cloud-function-adapter-azure-web/sample/pet-store</module>
|
||||
<!-- <module>spring-cloud-function-adapter-azure-web/sample/pet-store</module>-->
|
||||
<module>spring-cloud-function-adapter-azure</module>
|
||||
<module>spring-cloud-function-adapter-gcp</module>
|
||||
<module>spring-cloud-function-grpc</module>
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<description>AWS Lambda Adapter for Spring Cloud Function</description>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-adapter-parent</artifactId>
|
||||
<version>3.2.10-SNAPSHOT</version>
|
||||
<artifactId>spring-cloud-function-parent</artifactId>
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -25,15 +25,17 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-serverless-web</artifactId>
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# This file is auto generated by SAM CLI build command
|
||||
|
||||
[function_build_definitions]
|
||||
[function_build_definitions.9341c1d5-9265-48ef-836e-25df000b0c59]
|
||||
[function_build_definitions.4c7d6b2d-fe8c-493a-945e-f0eaf34aaf65]
|
||||
codeuri = "/Users/ozhurakousky/Documents/dev/repo/spring-cloud-function/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/sample/pet-store"
|
||||
runtime = "java11"
|
||||
runtime = "java17"
|
||||
architecture = "x86_64"
|
||||
handler = "org.springframework.cloud.function.adapter.aws.web.WebProxyInvoker::handleRequest"
|
||||
manifest_hash = ""
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Copied from https://github.com/awslabs/aws-serverless-java-container/tree/main/samples/spring/pet-store
|
||||
Modeled after https://github.com/awslabs/aws-serverless-java-container/tree/main/samples/spring/pet-store
|
||||
|
||||
# Serverless Spring example
|
||||
A basic pet store written with the [Spring framework](https://projects.spring.io/spring-framework/). The `StreamLambdaHandler` object is the main entry point for Lambda.
|
||||
A basic pet store written with the [Spring framework](https://projects.spring.io/spring-framework/).
|
||||
|
||||
The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yml` file in the root folder contains the application definition.
|
||||
|
||||
@@ -12,6 +12,7 @@ The application can be deployed in an AWS account using the [Serverless Applicat
|
||||
|
||||
## Deployment
|
||||
In a shell, navigate to the sample's folder and use the SAM CLI to build a deployable package
|
||||
|
||||
```
|
||||
$ sam build
|
||||
```
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<spring.version>5.3.25</spring.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<spring.version>6.0.8</spring.version>
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<log4j.version>2.19.0</log4j.version>
|
||||
</properties>
|
||||
|
||||
@@ -12,7 +12,7 @@ Resources:
|
||||
Type: AWS::Serverless::Function
|
||||
Properties:
|
||||
Handler: org.springframework.cloud.function.adapter.aws.web.WebProxyInvoker::handleRequest
|
||||
Runtime: java11
|
||||
Runtime: java17
|
||||
CodeUri: .
|
||||
MemorySize: 512
|
||||
Policies: AWSLambdaBasicExecutionRole
|
||||
|
||||
@@ -24,10 +24,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.springframework.cloud.function.adapter.aws.web;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -85,36 +85,18 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework</groupId>-->
|
||||
<!-- <artifactId>spring-web</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<!-- Spring Boot autoconfiguration needs this to be able to create a Jackson
|
||||
ObjectMapper -->
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<!-- <optional>true</optional>-->
|
||||
<!-- <scope>test</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
>>>>>>> 24687a3ab (working on AWS)
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<!-- <optional>true</optional>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<!-- <version>3.1.0</version>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
>>>>>>> 24687a3ab (working on AWS)
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-web</artifactId>
|
||||
<optional>true</optional>
|
||||
<!-- <scope>test</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
<description>Azure Function Adapter for Spring Cloud Function</description>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-adapter-parent</artifactId>
|
||||
<version>3.2.10-SNAPSHOT</version>
|
||||
<artifactId>spring-cloud-function-parent</artifactId>
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -27,6 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-serverless-web</artifactId>
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure.functions</groupId>
|
||||
@@ -39,6 +40,11 @@
|
||||
<artifactId>azure-functions-java-spi</artifactId>
|
||||
<version>${azure.functions.java.spi.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@@ -48,10 +54,6 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
Copied from https://github.com/awslabs/aws-serverless-java-container/tree/main/samples/spring/pet-store
|
||||
|
||||
# Serverless Spring example
|
||||
A basic pet store written with the [Spring framework](https://projects.spring.io/spring-framework/). The `StreamLambdaHandler` object is the main entry point for Lambda.
|
||||
|
||||
The application can be deployed in an AWS account using the [Serverless Application Model](https://github.com/awslabs/serverless-application-model). The `template.yml` file in the root folder contains the application definition.
|
||||
|
||||
## Pre-requisites
|
||||
* [AWS CLI](https://aws.amazon.com/cli/)
|
||||
* [SAM CLI](https://github.com/awslabs/aws-sam-cli)
|
||||
* [Gradle](https://gradle.org/) or [Maven](https://maven.apache.org/)
|
||||
|
||||
## Deployment
|
||||
In a shell, navigate to the sample's folder and use the SAM CLI to build a deployable package
|
||||
```
|
||||
$ sam build
|
||||
```
|
||||
|
||||
This command compiles the application and prepares a deployment package in the `.aws-sam` sub-directory.
|
||||
|
||||
To deploy the application in your AWS account, you can use the SAM CLI's guided deployment process and follow the instructions on the screen
|
||||
|
||||
```
|
||||
$ sam deploy --guided
|
||||
```
|
||||
|
||||
Once the deployment is completed, the SAM CLI will print out the stack's outputs, including the new application URL. You can use `curl` or a web browser to make a call to the URL
|
||||
|
||||
```
|
||||
...
|
||||
---------------------------------------------------------------------------------------------------------
|
||||
OutputKey-Description OutputValue
|
||||
---------------------------------------------------------------------------------------------------------
|
||||
PetStoreApi - URL for application https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/pets
|
||||
---------------------------------------------------------------------------------------------------------
|
||||
|
||||
$ curl https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/pets
|
||||
```
|
||||
@@ -1,147 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>oz.spring.petstore</groupId>
|
||||
<artifactId>pet-store</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>pet-store</name>
|
||||
<description>Simple pet store written with the Spring framework</description>
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/awslabs/aws-serverless-java-container.git</url>
|
||||
</scm>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<java.version>8</java.version>
|
||||
<spring-boot-thin-layout.version>1.0.28.RELEASE</spring-boot-thin-layout.version>
|
||||
|
||||
<!-- Spring Boot start class! WARING: correct class must be set! -->
|
||||
<start-class>oz.spring.petstore.PetStoreSpringAppConfig</start-class>
|
||||
|
||||
<!-- AZURE FUNCTION CONFIG -->
|
||||
<azure.functions.maven.plugin.version>1.23.0</azure.functions.maven.plugin.version>
|
||||
<functionAppName>spring-cloud-function-samples</functionAppName>
|
||||
<functionAppRegion>westus</functionAppRegion>
|
||||
<functionResourceGroup>java-functions-group</functionResourceGroup>
|
||||
<functionAppServicePlanName>java-functions-app-service-plan</functionAppServicePlanName>
|
||||
<functionPricingTier>EP1</functionPricingTier>
|
||||
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
|
||||
<spring.version>5.3.25</spring.version>
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<log4j.version>2.19.0</log4j.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-adapter-azure-web</artifactId>
|
||||
<version>3.2.10-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!--
|
||||
the Spring Context Indexer run an annotation processor at compile time and generates
|
||||
a META-INF/spring.components file that Spring can use to speed up component scanning at boot time.
|
||||
For small applications, this doesn't make a big difference. However, for large applications with
|
||||
complex dependencies this may improve your cold start time significantly.
|
||||
-->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-indexer</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency> -->
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency> -->
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-functions-maven-plugin</artifactId>
|
||||
<version>${azure.functions.maven.plugin.version}</version>
|
||||
|
||||
<configuration>
|
||||
<localDebugConfig>transport=dt_socket,server=y,suspend=y,address=5005</localDebugConfig>
|
||||
<appName>${functionAppName}</appName>
|
||||
<resourceGroup>${functionResourceGroup}</resourceGroup>
|
||||
<region>${functionAppRegion}</region>
|
||||
<appServicePlanName>${functionAppServicePlanName}</appServicePlanName>
|
||||
<pricingTier>${functionPricingTier}</pricingTier>
|
||||
|
||||
<hostJson>${project.basedir}/src/main/resources/host.json</hostJson>
|
||||
|
||||
<runtime>
|
||||
<os>linux</os>
|
||||
<javaVersion>11</javaVersion>
|
||||
</runtime>
|
||||
|
||||
<funcPort>7072</funcPort>
|
||||
|
||||
<appSettings>
|
||||
<property>
|
||||
<name>FUNCTIONS_EXTENSION_VERSION</name>
|
||||
<value>~4</value>
|
||||
</property>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>package-functions</id>
|
||||
<goals>
|
||||
<goal>package</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot.experimental</groupId>
|
||||
<artifactId>spring-boot-thin-layout</artifactId>
|
||||
<version>${spring-boot-thin-layout.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 oz.spring.petstore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.servlet.HandlerAdapter;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
@Configuration
|
||||
@Import({ PetsController.class})
|
||||
public class PetStoreSpringAppConfig {
|
||||
/*
|
||||
* Create required HandlerMapping, to avoid several default HandlerMapping instances being created
|
||||
*/
|
||||
@Bean
|
||||
public HandlerMapping handlerMapping() {
|
||||
return new RequestMappingHandlerMapping();
|
||||
}
|
||||
|
||||
/*
|
||||
* Create required HandlerAdapter, to avoid several default HandlerAdapter instances being created
|
||||
*/
|
||||
@Bean
|
||||
public HandlerAdapter handlerAdapter() {
|
||||
return new RequestMappingHandlerAdapter();
|
||||
}
|
||||
|
||||
/*
|
||||
* optimization - avoids creating default exception resolvers; not required as the serverless container handles all
|
||||
* exceptions
|
||||
*
|
||||
* By default, an ExceptionHandlerExceptionResolver is created which creates many dependent object, including an
|
||||
* expensive ObjectMapper instance.
|
||||
*
|
||||
* To enable custom @ControllerAdvice classes remove this bean.
|
||||
*/
|
||||
@Bean
|
||||
public HandlerExceptionResolver handlerExceptionResolver() {
|
||||
return new HandlerExceptionResolver() {
|
||||
|
||||
@Override
|
||||
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 oz.spring.petstore;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import oz.spring.petstore.model.Pet;
|
||||
import oz.spring.petstore.model.PetData;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@EnableWebMvc
|
||||
public class PetsController {
|
||||
@RequestMapping(path = "/pets", method = RequestMethod.POST)
|
||||
public Pet createPet(@RequestBody Pet newPet) {
|
||||
if (newPet.getName() == null || newPet.getBreed() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Pet dbPet = newPet;
|
||||
dbPet.setId(UUID.randomUUID().toString());
|
||||
return dbPet;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/pets", method = RequestMethod.GET)
|
||||
public Pet[] listPets(@RequestParam("limit") Optional<Integer> limit, Principal principal) {
|
||||
int queryLimit = 10;
|
||||
if (limit.isPresent()) {
|
||||
queryLimit = limit.get();
|
||||
}
|
||||
|
||||
Pet[] outputPets = new Pet[queryLimit];
|
||||
|
||||
for (int i = 0; i < queryLimit; i++) {
|
||||
Pet newPet = new Pet();
|
||||
newPet.setId(UUID.randomUUID().toString());
|
||||
newPet.setName(PetData.getRandomName());
|
||||
newPet.setBreed(PetData.getRandomBreed());
|
||||
newPet.setDateOfBirth(PetData.getRandomDoB());
|
||||
outputPets[i] = newPet;
|
||||
}
|
||||
|
||||
return outputPets;
|
||||
}
|
||||
|
||||
@GetMapping("favicon.ico")
|
||||
@ResponseBody
|
||||
void returnNoFavicon() {
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/pets/{petId}", method = RequestMethod.GET)
|
||||
public Pet listPets() {
|
||||
Pet newPet = new Pet();
|
||||
newPet.setId(UUID.randomUUID().toString());
|
||||
newPet.setBreed(PetData.getRandomBreed());
|
||||
newPet.setDateOfBirth(PetData.getRandomDoB());
|
||||
newPet.setName(PetData.getRandomName());
|
||||
return newPet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 oz.spring.petstore.model;
|
||||
|
||||
public class Error {
|
||||
private String message;
|
||||
|
||||
public Error(String errorMessage) {
|
||||
message = errorMessage;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 oz.spring.petstore.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Pet {
|
||||
private String id;
|
||||
private String breed;
|
||||
private String name;
|
||||
private Date dateOfBirth;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getBreed() {
|
||||
return breed;
|
||||
}
|
||||
|
||||
public void setBreed(String breed) {
|
||||
this.breed = breed;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(Date dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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 oz.spring.petstore.model;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class PetData {
|
||||
private static List<String> breeds = new ArrayList<>();
|
||||
static {
|
||||
breeds.add("Afghan Hound");
|
||||
breeds.add("Beagle");
|
||||
breeds.add("Bernese Mountain Dog");
|
||||
breeds.add("Bloodhound");
|
||||
breeds.add("Dalmatian");
|
||||
breeds.add("Jack Russell Terrier");
|
||||
breeds.add("Norwegian Elkhound");
|
||||
}
|
||||
|
||||
private static List<String> names = new ArrayList<>();
|
||||
static {
|
||||
names.add("Bailey");
|
||||
names.add("Bella");
|
||||
names.add("Max");
|
||||
names.add("Lucy");
|
||||
names.add("Charlie");
|
||||
names.add("Molly");
|
||||
names.add("Buddy");
|
||||
names.add("Daisy");
|
||||
names.add("Rocky");
|
||||
names.add("Maggie");
|
||||
names.add("Jake");
|
||||
names.add("Sophie");
|
||||
names.add("Jack");
|
||||
names.add("Sadie");
|
||||
names.add("Toby");
|
||||
names.add("Chloe");
|
||||
names.add("Cody");
|
||||
names.add("Bailey");
|
||||
names.add("Buster");
|
||||
names.add("Lola");
|
||||
names.add("Duke");
|
||||
names.add("Zoe");
|
||||
names.add("Cooper");
|
||||
names.add("Abby");
|
||||
names.add("Riley");
|
||||
names.add("Ginger");
|
||||
names.add("Harley");
|
||||
names.add("Roxy");
|
||||
names.add("Bear");
|
||||
names.add("Gracie");
|
||||
names.add("Tucker");
|
||||
names.add("Coco");
|
||||
names.add("Murphy");
|
||||
names.add("Sasha");
|
||||
names.add("Lucky");
|
||||
names.add("Lily");
|
||||
names.add("Oliver");
|
||||
names.add("Angel");
|
||||
names.add("Sam");
|
||||
names.add("Princess");
|
||||
names.add("Oscar");
|
||||
names.add("Emma");
|
||||
names.add("Teddy");
|
||||
names.add("Annie");
|
||||
names.add("Winston");
|
||||
names.add("Rosie");
|
||||
}
|
||||
|
||||
public static List<String> getBreeds() {
|
||||
return breeds;
|
||||
}
|
||||
|
||||
public static List<String> getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public static String getRandomBreed() {
|
||||
return breeds.get(ThreadLocalRandom.current().nextInt(0, breeds.size() - 1));
|
||||
}
|
||||
|
||||
public static String getRandomName() {
|
||||
return names.get(ThreadLocalRandom.current().nextInt(0, names.size() - 1));
|
||||
}
|
||||
|
||||
public static Date getRandomDoB() {
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
|
||||
int year = ThreadLocalRandom.current().nextInt(
|
||||
Calendar.getInstance().get(Calendar.YEAR) - 15,
|
||||
Calendar.getInstance().get(Calendar.YEAR)
|
||||
);
|
||||
|
||||
gc.set(Calendar.YEAR, year);
|
||||
|
||||
int dayOfYear = ThreadLocalRandom.current().nextInt(1, gc.getActualMaximum(Calendar.DAY_OF_YEAR));
|
||||
|
||||
gc.set(Calendar.DAY_OF_YEAR, dayOfYear);
|
||||
return gc.getTime();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"version": "2.0",
|
||||
"extensionBundle": {
|
||||
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
||||
"version": "[3.*, 4.0.0)"
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,6 @@ package org.springframework.cloud.function.adapter.azure.web;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
import com.microsoft.azure.functions.HttpMethod;
|
||||
import com.microsoft.azure.functions.HttpRequestMessage;
|
||||
@@ -33,6 +29,9 @@ import com.microsoft.azure.functions.annotation.AuthorizationLevel;
|
||||
import com.microsoft.azure.functions.annotation.FunctionName;
|
||||
import com.microsoft.azure.functions.annotation.HttpTrigger;
|
||||
import com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.springframework.cloud.function.adapter.azure.web;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,7 +32,6 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import({ PetsController.class })
|
||||
public class PetStoreSpringAppConfig {
|
||||
|
||||
@@ -9,13 +9,12 @@
|
||||
<description>Base serverless web adapter</description>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-adapter-parent</artifactId>
|
||||
<version>3.2.10-SNAPSHOT</version>
|
||||
<artifactId>spring-cloud-function-parent</artifactId>
|
||||
<version>4.0.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -25,12 +24,12 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<!-- <version>6.0.8</version> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<!-- <version>6.0.0</version>-->
|
||||
<!-- <scope>provided</scope>-->
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.cloud.function.serverless.web;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -5,10 +21,16 @@ import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterRegistration;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterRegistration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 4.x
|
||||
*
|
||||
*/
|
||||
public class ProxyFilterRegistration implements FilterRegistration, FilterRegistration.Dynamic {
|
||||
|
||||
public Filter getFilter() {
|
||||
|
||||
@@ -42,21 +42,22 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpUpgradeHandler;
|
||||
import javax.servlet.http.Part;
|
||||
import jakarta.servlet.AsyncContext;
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.ReadListener;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletConnection;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletInputStream;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.servlet.http.HttpUpgradeHandler;
|
||||
import jakarta.servlet.http.Part;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -589,12 +590,6 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String getRealPath(String path) {
|
||||
return this.servletContext.getRealPath(path);
|
||||
}
|
||||
|
||||
public void setRemotePort(int remotePort) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@@ -674,7 +669,7 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.DispatcherType getDispatcherType() {
|
||||
public DispatcherType getDispatcherType() {
|
||||
return this.dispatcherType;
|
||||
}
|
||||
|
||||
@@ -814,7 +809,8 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPathTranslated() {
|
||||
return (this.pathInfo != null ? getRealPath(this.pathInfo) : null);
|
||||
//return (this.pathInfo != null ? getRealPath(this.pathInfo) : null);
|
||||
return this.pathInfo;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
@@ -947,12 +943,6 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
return this.requestedSessionIdFromURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isRequestedSessionIdFromUrl() {
|
||||
return isRequestedSessionIdFromURL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -981,7 +971,7 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<javax.servlet.http.Part> getParts() throws IOException, ServletException {
|
||||
public Collection<Part> getParts() throws IOException, ServletException {
|
||||
List<Part> result = new LinkedList<>();
|
||||
for (List<Part> list : this.parts.values()) {
|
||||
result.addAll(list);
|
||||
@@ -993,4 +983,22 @@ public class ProxyHttpServletRequest implements HttpServletRequest {
|
||||
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestId() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProtocolRequestId() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletConnection getServletConnection() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.WriteListener;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.WriteListener;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -42,6 +42,7 @@ import org.springframework.web.util.WebUtils;
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 4.x
|
||||
*
|
||||
*/
|
||||
public class ProxyHttpServletResponse implements HttpServletResponse {
|
||||
@@ -295,18 +296,6 @@ public class ProxyHttpServletResponse implements HttpServletResponse {
|
||||
return encodeURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String encodeUrl(String url) {
|
||||
return encodeURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public String encodeRedirectUrl(String url) {
|
||||
return encodeRedirectURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendError(int status, String errorMessage) throws IOException {
|
||||
Assert.state(!isCommitted(), "Cannot set error status - response is already committed");
|
||||
@@ -379,11 +368,6 @@ public class ProxyHttpServletResponse implements HttpServletResponse {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setStatus(int status, String errorMessage) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatus() {
|
||||
|
||||
@@ -25,22 +25,22 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.FilterConfig;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.Servlet;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -169,7 +169,7 @@ public class ProxyMvc {
|
||||
*/
|
||||
ProxyFilterChain(DispatcherServlet servlet) {
|
||||
List<Filter> filters = new ArrayList<>();
|
||||
servlet.getServletContext().getFilterRegistrations().values().forEach(fr -> filters.add(((ProxyFilterRegistration)fr).getFilter()));
|
||||
servlet.getServletContext().getFilterRegistrations().values().forEach(fr -> filters.add(((ProxyFilterRegistration) fr).getFilter()));
|
||||
Assert.notNull(filters, "filters cannot be null");
|
||||
Assert.noNullElements(filters, "filters cannot contain null values");
|
||||
this.filters = initFilterList(servlet, filters.toArray(new Filter[] {}));
|
||||
|
||||
@@ -20,29 +20,25 @@ import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Enumeration;
|
||||
import java.util.EventListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterRegistration;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.ServletRegistration.Dynamic;
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
import javax.servlet.descriptor.JspConfigDescriptor;
|
||||
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterRegistration;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.Servlet;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import jakarta.servlet.ServletRegistration.Dynamic;
|
||||
import jakarta.servlet.SessionCookieConfig;
|
||||
import jakarta.servlet.SessionTrackingMode;
|
||||
import jakarta.servlet.descriptor.JspConfigDescriptor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -130,31 +126,11 @@ public class ProxyServletContext implements ServletContext {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Servlet getServlet(String name) throws ServletException {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<Servlet> getServlets() {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getServletNames() {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String msg) {
|
||||
this.logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Exception exception, String msg) {
|
||||
this.logger.error(msg, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Throwable throwable) {
|
||||
this.logger.error(message, throwable);
|
||||
@@ -241,25 +217,26 @@ public class ProxyServletContext implements ServletContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className) {
|
||||
public FilterRegistration.Dynamic addFilter(String filterName, String className) {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
|
||||
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
Map<String, FilterRegistration> filterRegistrations = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
|
||||
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
|
||||
try {
|
||||
Filter filter = filterClass.getDeclaredConstructor().newInstance();
|
||||
ProxyFilterRegistration registration = new ProxyFilterRegistration(filterName, filter);
|
||||
filterRegistrations.put(filterName, registration);
|
||||
return registration;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
@@ -290,12 +267,12 @@ public class ProxyServletContext implements ServletContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes() {
|
||||
public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes() {
|
||||
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
|
||||
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
/*
|
||||
* Copyright 2023-2023 the original author or authors.
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* https://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.springframework.cloud.function.serverless.web;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.ServletSecurityElement;
|
||||
import jakarta.servlet.MultipartConfigElement;
|
||||
import jakarta.servlet.Servlet;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.ServletRegistration;
|
||||
import jakarta.servlet.ServletSecurityElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 4.x
|
||||
*
|
||||
*/
|
||||
public class ProxyServletRegistration implements ServletRegistration, ServletRegistration.Dynamic, Comparable<ProxyServletRegistration> {
|
||||
|
||||
private final String servletName;
|
||||
|
||||
@@ -18,10 +18,9 @@ package org.springframework.cloud.function.serverless.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.springframework.cloud.function.test.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -32,7 +32,6 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
//@SpringBootApplication
|
||||
@Configuration
|
||||
@Import({ PetsController.class })
|
||||
public class PetStoreSpringAppConfig {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@RestController
|
||||
@EnableWebMvc
|
||||
public class PetsController {
|
||||
@RequestMapping(path = "/pets", method = RequestMethod.POST)
|
||||
@RequestMapping(path = "/pets/", method = RequestMethod.POST)
|
||||
public Pet createPet(@RequestBody Pet newPet) {
|
||||
if (newPet.getName() == null || newPet.getBreed() == null) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user