Title: Interfacing Hardware with Web Services
1Interfacing Hardware with Web Services
- Jason Wambach
- 2006 Harpoon Technologies
2XFire
- Free open-source Java SOAP framework
- StAX based (Streaming API for XML)
- Extremely simple
- Still very new (1.0-RC1)
- xfire.codehaus.org
3Exposing a Service
- POJO
- services.xml
- web.xml
4POJO Service
public TempService() public String
readTemp() if (tempStr ! null)
return tempStr else return
"Error"
5services.xml
- META-INF Folder of Classpath!
ltbeans xmlns"http//xfire.codehaus.org/config/1.0
"gt ltservicegt ltnamegtTempServicelt/namegt
ltnamespacegthttp//vodkatonic.org/TempServicelt/name
spacegt ltserviceClassgtorg.vodkatonic.webservice
.TempServicelt/serviceClassgt lt/servicegt lt/beansgt
6web.xml
lt?xml version"1.0" encoding"UTF-8"?gt ltweb-app
version"2.4" xmlns"http//java.sun.com/xml/ns/j2
ee" xmlnsxsi"http//www.w3.org/2001/XMLSchema-
instance" xsischemaLocation"http//java.sun.co
m/xml/ns/j2ee http//java.sun.com/xml/ns/j2ee/we
b-app_2_4.xsd"gt ltservletgt
ltservlet-namegtXFireServletlt/servlet-namegt
ltdisplay-namegtXFire Servletlt/display-namegt
ltservlet-classgt org.codehaus.xfire.transpo
rt.http.XFireConfigurableServlet
lt/servlet-classgt lt/servletgt
ltservlet-mappinggt ltservlet-namegtXFireServletlt/
servlet-namegt lturl-patterngt/servlet/XFireServl
et/lt/url-patterngt lt/servlet-mappinggt
ltservlet-mappinggt ltservlet-namegtXFireServletlt/
servlet-namegt lturl-patterngt/services/lt/url-pa
tterngt lt/servlet-mappinggt lt/web-appgt
7Client
public interface TempService public String
readTemp()
XFire xfire XFireFactory.newInstance().getXFire(
) XFireProxyFactory factory new
XFireProxyFactory(xfire) Service serviceModel
new ObjectServiceFactory().create(TempService.cl
ass) TempService service (TempService)
factory.create(serviceModel,
http//192.168.1.708080/temp/services/TempServic
e") System.out.println(service.readTemp())
Thats all!
8Even easier client
Client client new Client(new URL("http//vodkato
nic.org/xfire/services/TempService?wsdl")) Object
response client.invoke(readTemp", new
Object ) String temp (String) response0
- No interface required
- Very much a WIP
9Glossed 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?)
10Glossed over (hardware)
- AVR Atmega8 microcontroller
- Hardware U(S)ART
- 10 bit ADC
- Firmware written in C (AVR-GCC)
- Power stolen from serial port
11Schematic
12Screenshot
13Resources
- xfire.codehaus.org
- rxtx.org
- atmel.com
- avrfreaks.net
- vps.harpoontech.com/blog