<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>GeoBliki's Blog: Accessing SOS with Basic Authentication - Java</title>
    <link>http://wwww.geobliki.com/articles/2006/10/23/accessing-sos-with-basic-authentication-java</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Sensor Web Enabled (SWE) Data Node </description>
    <item>
      <title>Accessing SOS with Basic Authentication - Java</title>
      <description>&lt;p&gt;Basic authentication in Java example.   &lt;/p&gt;

&lt;p&gt;This uses JDK 5.0 and Apache jakarta commons libraries.  &lt;/p&gt;

&lt;p&gt;JDK download: http://java.sun.com/javase/downloads/index.jsp&lt;/p&gt;

&lt;p&gt;Apache download: http://jakarta.apache.org/commons/index.html&lt;/p&gt;

&lt;p&gt;Example XML to pass to the SOS is found http://eo1.geobliki.com/sosdemo&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;testPost(XML, "user", "password", false, "http://eo1.geobliki.com/sos");
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you are having issues with firewalls try changing the preempt to true to see if will work.  This always sends the username/password with the request.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;public static void testPost(String xml, String userName, String password, boolean preempt, String URL){
    HttpClient client = new HttpClient();
    HttpState state = client.getState();
    HttpClientParams params = client.getParams();
    params.setAuthenticationPreemptive(preempt);
    Credentials credentials = new UsernamePasswordCredentials(userName, password);
    state.setCredentials(null, null, credentials);
    PostMethod method = new PostMethod(URL);
    method.setRequestBody(xml);
    try {
        client.executeMethod(method);       
        Header[] headers = method.getResponseHeaders();
        for (Header header:headers){
            System.out.println(header.getName() + ":"+header.getValue());
        }
        String response = method.getResponseBodyAsString();
        System.out.println(response);
        method.releaseConnection();
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
}
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 23 Oct 2006 13:06:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:7005c86f-09ad-40fc-b385-dccf212d6fab</guid>
      <author>Linda Derezinski</author>
      <link>http://wwww.geobliki.com/articles/2006/10/23/accessing-sos-with-basic-authentication-java</link>
      <category>java</category>
      <category>authentication</category>
      <category>basic</category>
    </item>
  </channel>
</rss>
