Rest AWS EC2 HTTP Post内容大小限制

Rest AWS EC2 HTTP Post内容大小限制,rest,post,amazon-ec2,amazon-web-services,restlet,Rest,Post,Amazon Ec2,Amazon Web Services,Restlet,我正在通过REST与EC2实例上的一个程序通信,在通过POST请求发送的JSON大小达到20KB之前,一切都正常运行。我在本地机器Web服务器上运行代码时没有这些问题,但是当我将代码上载到EC2时,数据包永远不会到达服务器 amazon是否阻止超过20KB的数据包以防止DoS攻击?如果是,如何删除此功能。我需要能够发布至少500KB的JSON到我的实例 我正在运行并使用so来运行下面的代码,您需要前面链接中的org.restlet.jar和gson.jar 此代码在EC2实例上启动restlet

我正在通过REST与EC2实例上的一个程序通信,在通过POST请求发送的JSON大小达到20KB之前,一切都正常运行。我在本地机器Web服务器上运行代码时没有这些问题,但是当我将代码上载到EC2时,数据包永远不会到达服务器

amazon是否阻止超过20KB的数据包以防止DoS攻击?如果是,如何删除此功能。我需要能够发布至少500KB的JSON到我的实例

我正在运行并使用so来运行下面的代码,您需要前面链接中的org.restlet.jar和gson.jar

此代码在EC2实例上启动restlet服务器:

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.routing.Router;
import org.restlet.service.LogService;

public class StringApplication extends Application {
    public static final int PORT = 8005;
    public static void main(String[] args) throws Exception {

        Component component = new Component();
        component.setLogService(new LogService(false));

        component.getDefaultHost().attach(new StringApplication());

        component.getServers().add(Protocol.HTTP, PORT);
        component.start();
    }

    @Override
    public synchronized Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attachDefault(StringResource.class);
        return router;
    }
}    
这是我的restlet资源的代码

import java.lang.reflect.Type;
import java.util.ArrayList;

import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class StringResource extends ServerResource {
    private static ArrayList<String> strings = new ArrayList<String>();

    @Get
    public String getStrings() {
    Gson gson = new Gson();
    String output = gson.toJson(strings);
    return output;
    }

    @Post
    public void postStrings(String input) {
        Gson gson = new Gson();
        Type collectionType = new TypeToken<ArrayList<String>>() {
        }.getType();
        strings = gson.fromJson(input, collectionType);
    }
}
import java.lang.reflect.Type;
导入java.util.ArrayList;
导入org.restlet.resource.Get;
导入org.restlet.resource.Post;
导入org.restlet.resource.ServerResource;
导入com.google.gson.gson;
导入com.google.gson.reflect.TypeToken;
公共类StringResource扩展了ServerResource{
私有静态ArrayList字符串=新ArrayList();
@得到
公共字符串getStrings(){
Gson Gson=新的Gson();
字符串输出=gson.toJson(字符串);
返回输出;
}
@职位
公共void postStrings(字符串输入){
Gson Gson=新的Gson();
Type collectionType=new-TypeToken(){
}.getType();
strings=gson.fromJson(输入,collectionType);
}
}
最后,这里是我为测试不同数据包大小而创建的代码。计数=100(10KB)时,它工作,计数=1000(100KB)时,它超时。

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;

import org.restlet.Client;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Protocol;
import org.restlet.representation.Representation;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class StringDemo {

    private static final int COUNT = 1000;
    private static final String STRING = "THIS IS MY VERY LONG STRING AND IT IS FUN TO READ";
    private static final String SERVER_ADDRESS = "http://localhost:" + StringApplication.PORT;

    public static void main(String[] args) throws IOException {
        Gson gson = new Gson();
        Client client = new Client(Protocol.HTTP);
        Request request = new Request();
        request.setResourceRef(SERVER_ADDRESS);
        request.setMethod(Method.POST);
        ArrayList<String> strings = generateStrings();
        String json = gson.toJson(strings);
        request.setEntity(json, MediaType.APPLICATION_JSON);

        System.out.println("JSON bytesize " + json.length() * Character.SIZE / Byte.SIZE);
        Response handle = client.handle(request);
        Representation entity = handle.getEntity();

        if (handle.getStatus().isSuccess()) {
            System.out.println("Successfully uploaded strings");
        } else {
            System.out.println(entity != null ? entity.getText() : "no response from server");
        }

        request = new Request();
        request.setResourceRef(SERVER_ADDRESS);
        request.setMethod(Method.GET);

        handle = client.handle(request);
        entity = handle.getEntity();

        if (handle.getStatus().isSuccess()) {
            Type collectionType = new TypeToken<ArrayList<String>>() {
            }.getType();
            strings = gson.fromJson(entity.getReader(), collectionType);
            System.out.println("Received " + strings.size() + " strings");
        } else {

            System.out.println(entity != null ? entity.getText() : "no response from server");
        }

    }

    private static ArrayList<String> generateStrings() {
        ArrayList<String> strings = new ArrayList<String>(COUNT);
        for (int i = 0; i < COUNT; i++) {
            strings.add(STRING);
        }
        return strings;
    }

}
import java.io.IOException;
导入java.lang.reflect.Type;
导入java.util.ArrayList;
导入org.restlet.Client;
导入org.restlet.Request;
导入org.restlet.Response;
导入org.restlet.data.MediaType;
导入org.restlet.data.Method;
导入org.restlet.data.Protocol;
导入org.restlet.representation.representation;
导入com.google.gson.gson;
导入com.google.gson.reflect.TypeToken;
公共类StringDemo{
私有静态最终整数计数=1000;
private static final String=“这是我的很长的字符串,读起来很有趣”;
专用静态最终字符串服务器\u地址=”http://localhost:“+StringApplication.PORT;
公共静态void main(字符串[]args)引发IOException{
Gson Gson=新的Gson();
客户端=新客户端(Protocol.HTTP);
请求=新请求();
setResourceRef(服务器地址);
request.setMethod(Method.POST);
ArrayList字符串=generateStrings();
String json=gson.toJson(字符串);
setEntity(json、MediaType.APPLICATION_json);
System.out.println(“JSON字节大小”+JSON.length()*Character.SIZE/Byte.SIZE);
响应句柄=client.handle(请求);
表示实体=handle.getEntity();
if(handle.getStatus().issucess()){
System.out.println(“成功上传字符串”);
}否则{
System.out.println(entity!=null?entity.getText():“服务器没有响应”);
}
请求=新请求();
setResourceRef(服务器地址);
request.setMethod(Method.GET);
handle=client.handle(请求);
entity=handle.getEntity();
if(handle.getStatus().issucess()){
Type collectionType=new-TypeToken(){
}.getType();
strings=gson.fromJson(entity.getReader(),collectionType);
System.out.println(“接收的”+strings.size()+strings”);
}否则{
System.out.println(entity!=null?entity.getText():“服务器没有响应”);
}
}
私有静态数组列表生成器(){
ArrayList字符串=新的ArrayList(计数);
for(int i=0;i

您必须将服务器地址更改为运行代码的EC2实例

当您使用一个较大的实例时,问题就会消失。这些问题似乎与amazon提供的免费层机器的默认配置有关。

您对该帖子使用的API调用是什么?curl-i-X POST-H“Content-Type:application/json”-d'{“key”:“value”},但用我的ec2实例替换localhost。在使用GSON转换数据之后,我使用Java和Restlet发送数据。我将发布一些示例代码。所以这不是对EC2 API的调用。。。我认为这就是问题所在。