test_class.file: dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/decoder/HttpCommandDecoderTest.java
test_class.identifier: HttpCommandDecoderTest
test_case.body: @Test
      public void decodeGet() throws Exception {
          HttpRequest request = mock(HttpRequest.class);
          when(request.getUri()).thenReturn("localhost:80/test");
          when(request.getMethod()).thenReturn(HttpMethod.GET);
          CommandContext context = HttpCommandDecoder.decode(request);
          assertThat(context.getCommandName(), equalTo("test"));
          assertThat(context.isHttp(), is(true));
          when(request.getUri()).thenReturn("localhost:80/test?a=b&c=d");
          context = HttpCommandDecoder.decode(request);
          assertThat(context.getArgs(), arrayContaining("b", "d"));
      }
test_case.class_method_signature: HttpCommandDecoderTest.decodeGet()
test_case.full_signature: @Test public void decodeGet()
test_case.identifier: decodeGet
test_case.invocations: mock thenReturn when getUri thenReturn when getMethod decode assertThat getCommandName equalTo assertThat isHttp is thenReturn when getUri decode assertThat getArgs arrayContaining
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void decodeGet()
focal_class.file: dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/decoder/HttpCommandDecoder.java
focal_class.identifier: HttpCommandDecoder
focal_class.class_method_signature: HttpCommandDecoder.decode(HttpRequest request)
focal_class.full_signature: public static CommandContext decode(HttpRequest request)
focal_class.identifier: decode
focal_class.modifiers: public static
focal_class.parameters: (HttpRequest request)
focal_class.return: CommandContext
focal_class.signature: CommandContext decode(HttpRequest request)
focal_method.body: public static CommandContext decode(HttpRequest request) {
          CommandContext commandContext = null;
          if (request != null) {
              QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
              String path = queryStringDecoder.path();
              String[] array = path.split("/");
              if (array.length == 2) {
                  String name = array[1];
  
                  // process GET request and POST request separately. Check url for GET, and check body for POST
                  if (request.getMethod() == HttpMethod.GET) {
                      if (queryStringDecoder.parameters().isEmpty()) {
                          commandContext = CommandContextFactory.newInstance(name);
                          commandContext.setHttp(true);
                      } else {
                          List<String> valueList = new ArrayList<String>();
                          for (List<String> values : queryStringDecoder.parameters().values()) {
                              valueList.addAll(values);
                          }
                          commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[]{}),true);
                      }
                  } else if (request.getMethod() == HttpMethod.POST) {
                      HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(request);
                      List<String> valueList = new ArrayList<String>();
                      for (InterfaceHttpData interfaceHttpData : httpPostRequestDecoder.getBodyHttpDatas()) {
                          if (interfaceHttpData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
                              Attribute attribute = (Attribute) interfaceHttpData;
                              try {
                                  valueList.add(attribute.getValue());
                              } catch (IOException ex) {
                                  throw new RuntimeException(ex);
                              }
                          }
                      }
                      if (valueList.isEmpty()) {
                          commandContext = CommandContextFactory.newInstance(name);
                          commandContext.setHttp(true);
                      } else {
                          commandContext = CommandContextFactory.newInstance(name, valueList.toArray(new String[]{}),true);
                      }
                  }
              }
          }
  
          return commandContext;
      }
focal_method.class_method_signature: HttpCommandDecoder.decode(HttpRequest request)
focal_method.full_signature: public static CommandContext decode(HttpRequest request)
focal_method.identifier: decode
focal_method.invocations: getUri path split getMethod isEmpty parameters newInstance setHttp values parameters addAll newInstance toArray getMethod getBodyHttpDatas getHttpDataType add getValue isEmpty newInstance setHttp newInstance toArray
focal_method.modifiers: public static
focal_method.parameters: (HttpRequest request)
focal_method.return: CommandContext
focal_method.signature: CommandContext decode(HttpRequest request)