小编Sac*_*ade的帖子

如何使用Spring/Servlet支持批量Web api请求处理

我们使用RESTEasy编写了Web API .我们希望为处理Google Batch请求处理工作方式的批处理请求提供支持.

以下是目前使用的方法,

我们有一个过滤器,接受传入的多部分请求.然后,此过滤器创建多个模拟请求和响应对象,然后使用这些模拟请求调用chain.doFilter.

public class BatchRequestProcessingFilter extends GenericFilterBean {

  @Override
  public void doFilter(ServletRequest req, ServletResponse res,
      FilterChain chain) throws IOException, ServletException {
            HttpServletRequest request = (HttpServletRequest)req;
            MockHttpServletRequest[] mockRequests = BatchRequestProcessorUtils.parseRequest(request);
            MockHttpServletResponse[] mockResponses = new MockHttpServletResponse[mockRequests.length];
            for(int i=0 ; i <= mockRequests.length ; i++  ) {
                chain.doFilter(mockRequests[i], mockResponses[i], chain);
            }
            BatchRequestProcessingUtils.populateResponseFromMockResponses(res, mockResponses);
      }

}
Run Code Online (Sandbox Code Playgroud)

MockHttpServletResponseclass返回一个OutputStream包装的虚拟对象ByteArrayOutputStream.

BatchRequestProcessorUtils 解析multipart请求并返回包装实际请求的mock请求,但返回实际请求主体的split body中指定的头.

我找不到任何支持批量请求处理的现有库.所以我的问题是,这是支持批量请求的正确方法还是应该使用哪种标准方法?

请注意,我们使用的是Tomcat 8.

java spring web-services servlet-filters

18
推荐指数
1
解决办法
944
查看次数

为什么使用String实习方法?

正如在本文中所解释的那样,我们应该在字符串常量上使用字符串的实际方法发布字符串文字是自动合并但是对于使用new构造的对象不是,因此使用该实习方法.但即使我们使用实习方法,也会创建一个新对象,那么实习方法的用途是什么?

String s = "Example";

String s1 = new String("Example"); // will create new object

String s2 = new String("Example").intern(); // this will create new object
 // but as we are calling intern we will get reference of pooled string "Example"
Run Code Online (Sandbox Code Playgroud)

现在

System.out.println(s == s1); // will return false
System.out.println(s == s2); // will return true
System.out.println(s1 == s2); // will return false
Run Code Online (Sandbox Code Playgroud)

那么实习方法的用途是什么?

编辑

我理解实习生方法的工作,但我的问题是为什么有实习方法?因为要调用intern方法我们必须使用new创建字符串对象,这将创建新的字符串实例!

String s3 = new String("Example"); // again new …
Run Code Online (Sandbox Code Playgroud)

java

12
推荐指数
1
解决办法
6076
查看次数

如何在 CloudWatch 控制面板模板中使用参数

我正在尝试创建一个CloudFormation模板来创建CloudWatch仪表板。以下是模板代码 -

Parameters:
    MyEnvironment:
        Type: String
        Default: "do"
        Description: "Specifies the environment of the platform."
Resources:
    MyServiceDashboard:
        Type: AWS::CloudWatch::Dashboard
        Properties:
            DashboardName: "Test-My-Dashboard"
            DashboardBody: >
                {
                    "widgets": [
                        {
                            "type": "metric",
                            "x": 15,
                            "y": 18,
                            "width": 6,
                            "height": 6,
                            "properties": {
                                "view": "timeSeries",
                                "stacked": false,
                                "metrics": [
                                    [ "AWS/Kinesis", "GetRecords.IteratorAgeMilliseconds", "StreamName", 
"${MyEnvironment}-my-data-out"
                                    ]...
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用MyEnvironment当我实际使用此模板创建堆栈时将提供的参数。

问题是 stack/dashbaord 是使用它创建的,但参数值没有在仪表板指标中使用,而是使用值 as"${MyEnvironment}-my-data-out"而不是"Dev-my-data-out"假设我提供了"MyEnvironment"值 as"Dev"

我尝试了此链接中指定的方法 - Use Pseudo Variables in Cloudwatch Dashboard Template …

yaml amazon-web-services aws-cloudformation amazon-cloudwatch

4
推荐指数
1
解决办法
4458
查看次数