sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Something wrong with String content in multiPart() #206

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. multiPart(String, String, String)
2. post()
3.

What is the expected output? What do you see instead?
On the server side, I get no content payload when a String is passed as the 
second parameter to multiPart, and I expect the contents of the String to be 
transmitted as that part's content.

What version of the product are you using? On what operating system?
rest assured 1.7.1, Windows 7 64-bit Sun Java 1.6.0_34

Please provide any additional information below.

Here's my post statement:

given()
    .auth().preemptive().basic(username, password)
    .formParam("folderName", folderName)
    .formParam("fileName", fileName)
    .formParam("lastModified", lastModified)
    .multiPart("attributes", attrFile, "application/json")
    .multiPart("content", srcFile)                        
.expect()
    .statusCode(200)
.when()
    .post(uploadUri)
.getBody().asString();

When attrFile is a String and srcFile is a java.io.File, the srcFile transmits 
successfully, but attrFile does not; empty string is what I get on the server 
side for attrFile.  If I passed a java.io.File for attrFile, then the file 
contents transmitted successfully.

I played with the various interface options for .multiPart() trying to 
understand what was going wrong.  When I passed a ByteArrayInputStream for the 
attrFile, rest-assured threw an exception that read:

java.lang.IllegalStateException: Cannot serialize object because no JSON 
serializer found in classpath. Please put either Jackson or Gson in the 
classpath.

This tells me there is some code that looks at the mimeType and tries to 
marshal/unmarshal before sending the mulitpart?  Is this done as a content type 
check?  That's a pretty costly operation to toss a marshal/unmarshal in there 
as a validation; at least give the caller a chance to opt-in to something like 
that in the .expect() clause?

When I pass a byte[], String, or InputStream for that second parameter, I think 
it is reasonable to expect rest-assured to transmit my bytes verbatim with no 
transforms irregardless of what mime type I'm setting.  

The String payload being empty was curious, and I spent many days trying to 
figure out where my code was broken until I realized it was RA silently failing 
on me.

Original issue reported on code.google.com by dwoldr...@gmail.com on 18 Nov 2012 at 7:11

GoogleCodeExporter commented 9 years ago
Seems like you've undergone a very painful investigation to reach your 
conclusion, sorry about that! 

I suspect that the problem is that you use "application/json" and RA tries to 
do some clever things to support object serialization that obviously doesn't 
work properly.

Thanks for reporting, I'll look into this a bit better when I find some time. 

Original comment by johan.ha...@gmail.com on 22 Nov 2012 at 8:56

GoogleCodeExporter commented 9 years ago
Johan, 

Sorry that my report came off as disgruntled, that last bit about spending days 
troubleshooting was useless information that I should have kept to myself.  

I find RA super useful, I use it both for testing and for automation tools.  
There are not enough HTTP client API's out there that do a good job exposing 
the underlying protocol/options -AND- keep the interface simple.  I'd love to 
see what you would do on the server side.

Cheers,
Dave Woldrich

Original comment by dwoldr...@gmail.com on 2 Dec 2012 at 5:09

GoogleCodeExporter commented 9 years ago
I ran into a similar issue with simple java beans, had to add this to the maven 
pom dependencies

      <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>${jackson.version}</version>
        <scope>test</scope>
      </dependency>

      <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>${jackson.version}</version>
        <scope>test</scope>
      </dependency>

The documentation actually talks about the magic selection 
http://code.google.com/p/rest-assured/wiki/Usage#Serialization - see "Content 
based Serialization"

Original comment by Heiko.Ru...@googlemail.com on 8 Dec 2012 at 8:56

GoogleCodeExporter commented 9 years ago
Issue 313 has been merged into this issue.

Original comment by johan.ha...@gmail.com on 21 Feb 2014 at 10:06

GoogleCodeExporter commented 9 years ago
Is this still an issue?

Original comment by johan.ha...@gmail.com on 3 Jun 2014 at 6:57

GoogleCodeExporter commented 9 years ago
Using Rest Assured 2.3.2.
I have an issue where fileName is not sent to Server (getting null to server 
side). I would appreciate if someone can update on this issue.

_response = given().
            auth().preemptive().basic(Constants.USER_NAME, Constants.PASSWORD).
            contentType("multipart/form-data").
            multiPart("file", new File(fileName), "application/json").
            formParam("info", infoValue).
        //expect().
                //body("status", 200).
        when().
            post(path);

Original comment by krao03 on 27 Aug 2014 at 5:44

GoogleCodeExporter commented 9 years ago
@Krao: This should be fixed in version 2.3.3. Are you still seeing this issue?

Original comment by johan.ha...@gmail.com on 23 Sep 2014 at 9:14