feat: init sample
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
java-fc-sample.iml
|
||||||
|
target/
|
||||||
|
.idea/
|
||||||
# ---> Java
|
# ---> Java
|
||||||
# Compiled class file
|
# Compiled class file
|
||||||
*.class
|
*.class
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
# aliyun-java-fc-sample
|
# aliyun-java-fc-sample
|
||||||
|
|
||||||
|
Official documents: https://help.aliyun.com/document_detail/113519.html
|
||||||
|
|||||||
12
build.json
Normal file
12
build.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"java": "1.8",
|
||||||
|
"builder": {
|
||||||
|
"name": "maven",
|
||||||
|
"version": "3.5.2"
|
||||||
|
},
|
||||||
|
"repo": {
|
||||||
|
"dependencies": [
|
||||||
|
"me.hatter:commons:3.40"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
60
pom.xml
Normal file
60
pom.xml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>me.hatter.sample</groupId>
|
||||||
|
<artifactId>java-fc-sample</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>java-fc-sample</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.fc.runtime</groupId>
|
||||||
|
<artifactId>fc-java-core</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>2.6.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.test.skip>true</maven.test.skip>
|
||||||
|
</properties>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId> <!-- this is used for not append id to the jar name -->
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||||
|
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
17
src/main/java/me/hatter/example/HelloFC.java
Normal file
17
src/main/java/me/hatter/example/HelloFC.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package me.hatter.example;
|
||||||
|
|
||||||
|
import com.aliyun.fc.runtime.Context;
|
||||||
|
import com.aliyun.fc.runtime.PojoRequestHandler;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class HelloFC implements PojoRequestHandler<HelloRequestObject, HelloResponseObject> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HelloResponseObject handleRequest(HelloRequestObject helloRequestObject, Context context) {
|
||||||
|
HelloResponseObject helloResponseObject = new HelloResponseObject();
|
||||||
|
helloResponseObject.setTime(new Date());
|
||||||
|
helloResponseObject.setMessage("Hello: " + helloRequestObject.getMessage());
|
||||||
|
return helloResponseObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/me/hatter/example/HelloHttp.java
Normal file
29
src/main/java/me/hatter/example/HelloHttp.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package me.hatter.example;
|
||||||
|
|
||||||
|
import com.aliyun.fc.runtime.Context;
|
||||||
|
import com.aliyun.fc.runtime.HttpRequestHandler;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
public class HelloHttp implements HttpRequestHandler {
|
||||||
|
@Override
|
||||||
|
public void handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) throws IOException, ServletException {
|
||||||
|
String requestPath = (String) request.getAttribute("FC_REQUEST_PATH");
|
||||||
|
String requestURI = (String) request.getAttribute("FC_REQUEST_URI");
|
||||||
|
String requestClientIP = (String) request.getAttribute("FC_REQUEST_CLIENT_IP");
|
||||||
|
|
||||||
|
response.setStatus(200);
|
||||||
|
response.setHeader("header1", "value1");
|
||||||
|
response.setHeader("header2", "value2");
|
||||||
|
|
||||||
|
String body = String.format("Path: %s\n Uri: %s\n IP: %s\n", requestPath, requestURI, requestClientIP);
|
||||||
|
OutputStream out = response.getOutputStream();
|
||||||
|
out.write((body).getBytes());
|
||||||
|
out.flush();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/main/java/me/hatter/example/HelloRequestObject.java
Normal file
13
src/main/java/me/hatter/example/HelloRequestObject.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package me.hatter.example;
|
||||||
|
|
||||||
|
public class HelloRequestObject {
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/main/java/me/hatter/example/HelloResponseObject.java
Normal file
24
src/main/java/me/hatter/example/HelloResponseObject.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package me.hatter.example;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class HelloResponseObject {
|
||||||
|
private Date time;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public Date getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(Date time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user