0

I'm just trying to send a request and read out the answer of an ogc sos server.

sent request:

connection = new URL(url).openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset="+charset);
connection.connect();

read response:

output = connection.getOutputStream();
output.write(query.getBytes(charset));
input = new URL(url).openStream();
Reader reader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(reader);
StringBuilder response = new StringBuilder();           
String line = null;

while((line = bufferedReader.readLine()) != null)
   response.append(line+"\n");

bufferedReader.close();
output.close();

The response of the server is:

<?xml version="1.0" encoding="UTF-8"?>
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" 
   xsi:schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd">
  <ows:Exception exceptionCode="InvalidRequest" locator="REQUEST">
  <ows:ExceptionText>The GET request null is not supported by this SOS.</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

The format is a special sos type, but the main message is "The GET request null" So it seem like the server read the request by GET method.

I am not that firm in networking, but as I understood, I ensure by setDoOutput(true); to use the POST method, isn't it?

As I get any answer, I know there is a connection, but may it be that something with the head is wrong? Is it necessary in every case to sent it?

So my question is just what could be the reason what makes me or the server confusing about the http methods?

I guess I am missusing the java network handling.

Would be glad about every help.

Buhake Sindi
  • 82,658
  • 26
  • 157
  • 220
user972851
  • 186
  • 17
  • I'm not sure about this exact service but this seems like a SOAP service. If that's true, it's likely expecting all requests to be GET requests. Try without the setDoOutput(true). If that doesn't work, I find using curl on the command line a quick way to troubleshoot third party services like this. – case nelson Oct 06 '11 at 08:36
  • I am not sure about SOAP but yes sos is an xml based data exchange protokoll. Without setDoOuput(true) i get an "java.net.ProtocolException: cannot write to a URLConnection..." Exception. I was looking for cURL but without experience it seems quite lavish because win stresses me by missing dlls etc. Is there something similar integrated in win using cmd. – user972851 Oct 06 '11 at 09:31

3 Answers3

2

You can, also, explicitly, specify the POST method as follows (to see if that solved the problem):

connection.setRequestMethod("POST");
connection.connect();

Yes, URLConnection.seDoOutput(true) means that you intend to use the URLConnection for output (default, is false) and implicitly tells HttpURLConnection to use POST.

My assumption is that you're not passing request parameters to the Web Service. See this related SO post on using URLConnection.

Community
  • 1
  • 1
Buhake Sindi
  • 82,658
  • 26
  • 157
  • 220
0

If the request method really was GET and it was illegal at the HTTP level you wouldn't get all that XML back at all, just an HTTP error code. Looks more like a SOAP layer problem at the target, or a problem with the XML you are sending.

user207421
  • 289,834
  • 37
  • 266
  • 440
0

the simple answer is: add some "\n" at the end of each request line, and it works fine.

user972851
  • 186
  • 17