Forum Discussion

Appconomy_Suppo's avatar
Appconomy_Suppo
Occasional Contributor
14 years ago

Issue when posting an image to our REST service using SoapUI

We are running into issues posting an image to our REST services thru SoapUI. No matter what we try, our REST service rejects the SoapUI call, throwing a nullPointerException. Right now, we are not sure if it is our application or SoapUI.

I would very much appreciate it if you could give our SoapUI request a quick look to see if there is something obvious we are doing wrong - see attached screenshot. We have looked at various posts on the forum but could not find anything that would address this specific issue.

In addition, here is the unit test code for the REST service that handles image uploads:

ClientResponse response =
createImage("v1/merchants/"+merchant.getId().toString()+"/images",
"/test/com/appconomy/matrix/restclient/coupon/logo.jpg",
"image/jpeg");

protected ClientResponse createImage(String resourcePath, String
filename, String contentType) throws Exception {
byte[] bytes = getFileBytes(filename);

FormDataMultiPart form = new FormDataMultiPart()
.field("name", filename)
.field("contentType", contentType);
FormDataBodyPart fdp = new FormDataBodyPart("file", bytes,
MediaType.APPLICATION_OCTET_STREAM_TYPE);
form.bodyPart(fdp);
ClientResponse response = regularUserResource.path(resourcePath)
.header("Authorization", authentication)
.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, form);
return response;
}


Any help is very much appreciated
  • Hi,

    hmm.. could you attach a screenshot of the raw request tab after you have submitted the request?

    Thanks!

    /Ole
    SmartBear Software
  • Appconomy_Suppo's avatar
    Appconomy_Suppo
    Occasional Contributor
    Here is the raw:

    POST http://chatty.appconomy.com:8080/matrix ... f14/images HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: multipart/form-data; boundary="----=_Part_2_32949203.1328808999766"
    MIME-Version: 1.0
    Authorization: Basic TWVyY2hhbnRPd25lcjU4NTEwLjptZXJjaGFudA==
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: chatty.appconomy.com:8080
    Content-Length: 4033


    ------=_Part_2_32949203.1328808999766
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: form-data; name="xid"

    00000000QH7FM00000004
    ------=_Part_2_32949203.1328808999766
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: form-data; name="contentType"

    image/gif
    ------=_Part_2_32949203.1328808999766
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: form-data; name="Name"

    chflag.gif
    ------=_Part_2_32949203.1328808999766
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Content-Disposition: form-data; name="file"

    chflag.gif
    ------=_Part_2_32949203.1328808999766
    Content-Type: application/octet-stream; name=chflag.GIF
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="chflag.GIF"; filename="chflag.GIF"

    GIF89a„ ÷ followed by a lot of garbled characters
  • Hi

    please try the following:

    - rename the "Name" parameter to "name" (small caps as in your unit-test)
    - change the value of the file parameter to "file:chflag.gif"

    Does that make any difference?

    regards!

    /Ole
    SmartBear Software
  • Appconomy_Suppo's avatar
    Appconomy_Suppo
    Occasional Contributor
    Hi
    I tried as your suggestions. I tried to post a new image "icon.png". But the result is the same : Null Pointer returned.
  • Hi!

    hmm.. judging from the error you might need to add some authentication credentials in the AUT tab? Also enable preemptive authentication in the global HTTP settings might be needed!?

    regards!

    /Ole
    SmartBear Software
  • Hello!

    Did you check (enable) Preferences->HTTP Settings->Authenticate Preemptively option ?

    Does it make any difference ?

    Regards,
    Vladimir
    SmartBear Software