2017-06-29 5 views
1

Spring-MVCで書かれたWebアプリケーションのストレステストに取り組んでいます。そのために、オブジェクトPersonをアプリケーションに送信したいと思います。電子メールを取得するためにシステムを追加しましたが、オブジェクトを送信するたびにnullです。私は間違って何をしていますか?ありがとうございました。Apache Jmeter:ModelAttributeで動作しないオブジェクトを投稿する

Serverコード:ボディデータで送られ

@RequestMapping(value = "/person/add", method = RequestMethod.POST) 
    public String addPerson(@ModelAttribute("person") Person person, BindingResult bindingResult) { 
     try { 
      ObjectMapper mapper = new ObjectMapper(); 

      String json = mapper.writeValueAsString(person); 
      System.out.println("String is "+json); 
     }catch (Exception e){ 
      e.printStackTrace(); 
     } 


     System.out.println("Person add called"+person.getUsername()); 
     person.setUsername(this.stripHTML(person.getUsername())); 
     int personId = this.personService.addPerson(person); 
     if (!(personId == 0)) { 
      Person person1 = this.personService.getPersonById(personId); 
      Collection<GrantedAuthority> authorities = new ArrayList<>(); 
      authorities.add(new SimpleGrantedAuthority("ROLE_USER")); 
      Authentication authentication = new UsernamePasswordAuthenticationToken(person1, null, authorities); 
      SecurityContextHolder.getContext().setAuthentication(authentication); 
      return "redirect:/canvaslisting"; 
     } else { 
      return "redirect:/"; 
     } 
    } 

オブジェクト:

{"person":{"id":0,"username":"[email protected]","firstName":"test","cleanCacheFlag":false,"googleDrive":false,"dropbox":false,"evernoteConsumed":false,"statusChangeTimeStamp":null,"useCalendar":false,"newsletterFlag":false,"tourSteps":null,"profession":null,"notiz":null,"telePhone":null,"lastVisitedBoards":null,"leftGroup":null,"optionalEmail":null,"facebookLink":null,"xingLink":null,"linkedinLink":null,"lastOnlineTimestamp":null,"userRole":null,"homePage":null,"excelImportQuota":0,"toEmail":null,"code":null,"authorities":null,"role":null,"newpassword":null,"token":null,"profilePhotoString":null,"accountNonExpired":true,"credentialsNonExpired":true,"accountNonLocked":true,"active":true,"enabled":false} 
} 

出力:

Person add callednull 

スクリーンショット:

enter image description hereはありがとうございます。

サンプル結果

Thread Name: Thread Group 2-5 
Sample Start: 2017-06-29 15:17:11 IST 
Load time: 6 
Connect Time: 0 
Latency: 6 
Size in bytes: 237 
Sent bytes:0 
Headers size in bytes: 205 
Body size in bytes: 32 
Sample Count: 1 
Error Count: 1 
Data type ("text"|"bin"|""): text 
Response code: 415 
Response message: Unsupported Media Type 

Response headers: 
HTTP/1.1 415 Unsupported Media Type 
Server: Apache-Coyote/1.1 
Content-Type: text/html;charset=utf-8 
Content-Language: en 
Content-Length: 1048 
Date: Thu, 29 Jun 2017 09:47:11 GMT 
Connection: close 


HTTPSampleResult fields: 
ContentType: text/html;charset=utf-8 
DataEncoding: utf-8 

要求:

POST http://127.0.0.1:8080/person/add/ 

POST data: 
{"person":{"id":0,"username":"[email protected]","firstName":"test","cleanCacheFlag":false,"googleDrive":false,"dropbox":false,"evernoteConsumed":false,"statusChangeTimeStamp":null,"useCalendar":false,"newsletterFlag":false,"tourSteps":null,"profession":null,"notiz":null,"telePhone":null,"lastVisitedBoards":null,"leftGroup":null,"optionalEmail":null,"facebookLink":null,"xingLink":null,"linkedinLink":null,"lastOnlineTimestamp":null,"userRole":null,"homePage":null,"excelImportQuota":0,"toEmail":null,"code":null,"authorities":null,"role":null,"newpassword":null,"token":null,"profilePhotoString":null,"accountNonExpired":true,"credentialsNonExpired":true,"accountNonLocked":true,"active":true,"enabled":false} 
} 

[no cookies] 

Request Headers: 
Connection: close 
Content-Length: 717 
Content-Type: application/x-www-form-urlencoded 

答えて

1

ヘッダーを変更Content-Type in HTTPヘッダーマネージャー

Content-Type: application/x-www-form-urlencoded 

へ:

Content-Type: application/json 
+0

どこにこれを追加しますか? Jmeterのhttpヘッダーマネージャーでは? –

+0

この仕事をした男..ありがとう... Jmeterに追加されました.. –

1

は、あなただけの人に@RequestBody注釈を持っていないでしょうか?

public String addPerson(@RequestBody Person person); 
+0

まだ運。 HTTP/1.1 415サポートされていないメディアタイプ –

0

まあ、application/json

の値で Content-Typeヘッダを送信するように設定

JMeter request issue

はまた、あなたのJMeter設定が HTTP Header Managerを欠落している可能性がありますあなたのJMeterの要求にタイプミスやコピー&ペースト問題があります
+0

試した人、人、それらのすべて –

関連する問題