<?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: Tag basic</title>
    <link>http://geobliki.com/articles/tag/basic?tag=basic</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Sensor Web Enabled (SWE) Data Node </description>
    <item>
      <title>Accessing SOS with Basic Authentication - .Net (IronPython)</title>
      <description>&lt;p&gt;This example is provided by Kari Hoijarvi from WUSTL.&lt;/p&gt;

&lt;p&gt;Download IronPython from http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython&lt;/p&gt;

&lt;p&gt;Save the following code into a file called sos2.py&lt;/p&gt;

&lt;p&gt;to run the code:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  ipy
  &amp;gt;&amp;gt;&amp;gt;import sos2
  &amp;gt;&amp;gt;&amp;gt;sos2.test()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The sos2.py file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;import clr;
import System
clr.AddReferenceByPartialName("System.Data")
clr.AddReferenceByPartialName("System.Web")
clr.AddReferenceByPartialName("System.Xml")
from System import *
from System.IO import *
from System.Net import *
from System.Net.Sockets import *
from System.Text import *
from System.Xml import *

def test():
    query = Encoding.UTF8.GetBytes(
"""&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;GetObservation xmlns="http://www.opengeospatial.net/sos"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:ows="http://www.opengeospatial.net/ows"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.opengeospatial.net/sos 
http://mars.uni-muenster.de/swerep/trunk/sos/0.0.31/sosGetObservation.xsd"
    service="SOS" version="0.0.31"&amp;gt;
   &amp;lt;offering&amp;gt;EO1H0410342004085110PY&amp;lt;/offering&amp;gt;
&amp;lt;observedProperty&amp;gt;urn:ogc:def:phenomenon:OGC:1.0.30:hyperion_B021&amp;lt;/observedProperty&amp;gt;

&amp;lt;observedProperty&amp;gt;urn:ogc:def:phenomenon:OGC:1.0.30:hyperion_B051&amp;lt;/observedProperty&amp;gt;
   &amp;lt;resultFormat&amp;gt;application/zip&amp;lt;/resultFormat&amp;gt;
&amp;lt;/GetObservation&amp;gt;
""")
    req = HttpWebRequest.Create("http://test.geobliki.com/sos")
    req.Method = "POST"
    req.Credentials = NetworkCredential("some", "user")
    req.ContentType = "text/xml; charset=\"UTF-8\"";
    req.ContentLength = query.Length
    req.UserAgent = "IronPython"
    reqstm = req.GetRequestStream()
    reqstm.Write(query, 0, query.Length);
    rsp = req.GetResponse();
    try:
        print "============ begin headers =================="
        for h in rsp.Headers:
            print h + ": " + rsp.Headers[h]
        print "============ end headers =================="
        print "============ begin response =================="
        print ""
        print StreamReader(rsp.GetResponseStream()).ReadToEnd()
        print ""
        print "============ end of response =================="
    finally:
        print "closing response"
        rsp.Close()
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 23 Oct 2006 13:45:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4ba0331e-702b-4a8d-8314-5d24fff93036</guid>
      <author>Linda Derezinski</author>
      <link>http://geobliki.com/articles/2006/10/23/accessing-sos-with-basic-authentication-net-ironpython</link>
      <category>basic</category>
      <category>authentication</category>
      <category>.Net</category>
      <category>IronPython</category>
    </item>
    <item>
      <title>Accessing SOS with Basic Authentication - Ruby</title>
      <description>&lt;p&gt;Basic authentication in Ruby example.&lt;/p&gt;

&lt;p&gt;This is using Ruby 1.8.4 which may be installed:  &lt;/p&gt;

&lt;p&gt;Windows: http://rubyforge.org/frs/?group_id=167&lt;/p&gt;

&lt;p&gt;OSX: http://hivelogic.com/articles/2005/12/01/ruby&lt;em&gt;rails&lt;/em&gt;lighttpd&lt;em&gt;mysql&lt;/em&gt;tiger&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;post_it(xml)


 def post_it( xml, user = "bob", pass = "test")
    url = URI.parse('http://eo1.geobliki.com/sos')
    req = Net::HTTP::Post.new(url.path)
    req.basic_auth(user, pass)
    req['Content-Type'] = "text/xml"
    req.body = xml
    @response = Net::HTTP.start(url.host, url.port){|http|
      http.request(req)
    }
    puts @response.body     

  end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 23 Oct 2006 13:26:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:1718c151-e5f0-4ed9-8e45-02b8f929f8c3</guid>
      <author>Linda Derezinski</author>
      <link>http://geobliki.com/articles/2006/10/23/accessing-sos-with-basic-authentication-ruby</link>
      <category>ruby</category>
      <category>authentication</category>
      <category>basic</category>
    </item>
    <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://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>
