Forum Discussion

Jim_Apple's avatar
Jim_Apple
Occasional Contributor
17 years ago

Problems testing REST service on Glassfish

We have a very simple REST service that takes 2 params, I have a commons http client that can successfully send a request, but I have not been able to get SoapUI to work.  Mostly I get "HTTP/1.1 415 Unsupported Media Type", this messages seems to be coming from Jersey/Glassfish.  I don't think our code is even getting called.  I have tried all the default content types (text/xml,application/xml etc), still no luck.  A tcpdump of the request looks ok.  This is the java code that works (attached is the soapui.xml)

package mcjavascanclient;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class ScanTest {

    public static void main(String args[]) {

        HttpClient client = new HttpClient();
        String uri = "http://qaaejb03:13080/ScannerWebService/actions/store";

        PostMethod post = new PostMethod(uri);
        post.addParameter(new NameValuePair("scannerId", "19621962"));
        post.addParameter(new NameValuePair("data","testdata"));
        try {
            client.executeMethod(post);
            System.out.println(post.getResponseBodyAsString());
            System.out.println(post.getStatusCode());
        } catch (HttpException e) {
            e.printStackTrace();
        } catch ( IOException e ) {
                e.printStackTrace();
           
        } finally {
            post.releaseConnection();
        }
  }

}

Any help would be great
TIA

1 Reply

  • Jim_Apple's avatar
    Jim_Apple
    Occasional Contributor
    Selecting "Post query string" fixed this for me.  Here is a before and after of the posts if anyone is having the same problem.  Not sure I understand whats going on here but it's working.

    This was a "bad" request

    POST /ScannerWebService/actions/store?scannerId=12341231&data=testdataHTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: localhost:8080
    Content-Length: 0

    And this was a "good" request

    POST /ScannerWebService/actions/store HTTP/1.1
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Jakarta Commons-HttpClient/3.1
    Host: localhost:8080
    Content-Length: 390

    scannerId=12341231&data=testdata