Interfacing Hardware with Web Services

Document Sample
Interfacing Hardware with Web Services Powered By Docstoc
					Interfacing Hardware with
       Web Services

       Jason Wambach
  2006 Harpoon Technologies
                  XFire
•   Free open-source Java SOAP framework
•   StAX based (Streaming API for XML)
•   Extremely simple
•   Still very new (1.0-RC1)
•   xfire.codehaus.org
        Exposing a Service
• POJO
• services.xml
• web.xml
                        POJO Service
• TempService
  public TempService() {
    …
  }

  public String readTemp() {
   if (tempStr != null)
   {
      return tempStr;
   }
   else
   {
      return "Error";
   }}
                     services.xml
<beans xmlns="http://xfire.codehaus.org/config/1.0">
 <service>
  <name>TempService</name>
  <namespace>http://vodkatonic.org/TempService</namespace>
  <serviceClass>org.vodkatonic.webservice.TempService</serviceClass>
 </service>
</beans>


• META-INF Folder of Classpath!
                                   web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
           http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

 <servlet>
  <servlet-name>XFireServlet</servlet-name>
  <display-name>XFire Servlet</display-name>
  <servlet-class>
     org.codehaus.xfire.transport.http.XFireConfigurableServlet
  </servlet-class>
 </servlet>

 <servlet-mapping>
  <servlet-name>XFireServlet</servlet-name>
  <url-pattern>/servlet/XFireServlet/*</url-pattern>
 </servlet-mapping>

 <servlet-mapping>
  <servlet-name>XFireServlet</servlet-name>
  <url-pattern>/services/*</url-pattern>
 </servlet-mapping>
</web-app>
                                          Client
public interface TempService {
  public String readTemp();
}


XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xfire);

Service serviceModel = new ObjectServiceFactory().create(TempService.class);

TempService service = (TempService) factory.create(serviceModel,
  “http://192.168.1.70:8080/temp/services/TempService");
System.out.println(service.readTemp());




                                 That’s all!
                    Even easier client
Client client = new Client(new URL("http://vodkatonic.org/xfire/services/TempService?wsdl"));
Object[] response = client.invoke(“readTemp", new Object[] {});
String temp = (String) response[0];




 • No interface required
 • Very much a WIP
         Glossed over details
•   Fixed bug with HTTP Proxies
•   Using RXTX libs for serial comm.
    – rxtx.org
•   Java Comm package no longer
    supported on Windows by Sun.
    – Bug introduced, EOL windows port instead
      of fixing it.
    – No longer “needed”
    – Use USB (Java 1.6?)
    Glossed over (hardware)
• AVR Atmega8 microcontroller
  – Hardware U(S)ART
  – 10 bit ADC
• Firmware written in C (AVR-GCC)
• Power stolen from serial port
Schematic
Screenshot
               Resources
•   xfire.codehaus.org
•   rxtx.org
•   atmel.com
•   avrfreaks.net
•   vps.harpoontech.com/blog