ServiceStack.Java throws an exception when doing a post

Hello,

I’m trying to consume my ServiceStack web services from Eclipse using the ‘Add ServiceStack Reference’ plugin and I’m getting an exception telling me that doOutput needs to be set to true when trying to post a DTO to my server. Here are the steps I did:

  • Create a new .Net project using ServiceStackVS as explained in Creating your first project
  • I left the generated code as-is except that I changed the Hello request to be a POST
  • Download Eclipse 4.4 (luna) and install Maven and the ServiceStack plugin
  • Create a new Maven project and use the ‘Add ServiceStack Reference’ consume the service created above
  • Add a Java class with a main method that does the following:
    • Create an instance dto.Hello with a name
    • Create an instance of JsonServiceClient
    • POST the Hello request using the instance of JsonServiceClient (e.g.: client.post(helloRequest))

I’m getting an exception telling me that I need to set doOutput to true on HttpUrlConnection. I tried the above steps inside Android Studio and it works so I’m wondering what I did wrong in Eclipse. Can you tell me what I did wrong?

Side note: do you have any sample code/project (Java) where a webservice has been consumed? I would like to compare my Eclipse project to a working project.

Thanks!

Hi we’ve been able to repro this with a POST request which looks like it has different behavior when running on the JVM. We’ve resolved the issue and working on creating a new release, in the mean time you should be able to resolve this with a global Request Filter:

JsonServiceClient.GlobalRequestFilter = new ConnectionFilter() {
    @Override public void exec(HttpURLConnection conn) {
        String verb = conn.getRequestMethod();
        if (verb == HttpMethods.Post || verb == HttpMethods.Put) {
            conn.setDoOutput(true);
        }
    }
};

Hi, we’ve updated the ServiceStackEclipse plugin so you shouldn’t need the temporary workaround above. You’ll need to update the ServiceStackEclipse plugin and remove the servicestack.client 1.0.13 dependencies from Maven so when you add a new ServiceStack reference it will add the latest servicestack.client 1.0.17 dependency.

I’ve also added a new Eclipse Luna project with some JUnit tests you can run at:

Hi,

thanks for the updated plugin, it solved my issue.