Jim_Apple
17 years agoOccasional Contributor
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
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