Arduino + Adafruit CC3000 WIFI shield to Consume Tomcat+Netbeans WebServices

Dear All,

I am not posting here to ask for help, but to give my 2 cents to the community of Arduino, whatever little that may be. My goal is to widen the support available to Arduino, to the WIFI shield from Adafruit CC3000, and how to use those to connect to a WebServer made in your computer: Netbeans 8 + Tomcat 8.0.8. With this, I want others NOT to have the time consuming learning curve I had :slight_smile:

Conceptually speaking, I am using a webserver in my own laptop (MacOS), with WebServices deployed in Java+Tomcat. Then, I use Arduino as a CLIENT, to consume SOAP Web Services. The Idea is not to put the Arduino as a Server, as some tried with the Yun project, but to create an autonomous Agent (with the arduino as Brain, like a car, whatever…), and having the Arduino asking questions to the server via WebServices.

1st) The first step was to make the webservices available NOT ONLY in Localhost. While developing to Arduino, I constantly made the stupid error of considering that Localhost from Arduino and my PC was the same! DUUUUHHHH. Make sure your tomcat can receive requests from outside localhost, as without this, communication is dead.

2nd) Go To http://localhost:8080/ (or the url you use to manage Tomcat or your application server), Manager App, and make sure your app is deployed. Go to Netbeans, select your webservice, mouse right click and select “Test Web Service”. In my case, I got:

Address:	http://localhost:8080/CloudTest/Xav13ruaPRO
WSDL:	http://localhost:8080/CloudTest/Xav13ruaPRO?wsdl
Implementation class:	WSHandler.Xav13ruaPRO

You need this information (Address and WSDL) to do the Job.

3rd) Go To, and download The SoapUI Pro Trial. You have a 15 days trial, so don’t worry. Why do you need it? Well… you don’t NEEEEED it, but you need a way to know exactly how to manually formulate the SOAP request in Arduino. This app is for that. See the video in that page, create a project, and paste the WSDL link of your webservices (in my case, http://localhost:8080/CloudTest/Xav13ruaPRO?wsdl). Then, choose the tabs “RAW” and “XML”, and you will have (in my case) the following:

“RAW” (The header for the HTTP request):

POST http://localhost:8080/CloudTest/Xav13ruaPRO HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 208
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

The “Content-Length: 208” is reaaaaalllllllly important, to the point that if you miss this length, you will get an error answer from your server. So, I like this software because of this feedback.


<soapenv:Envelope xmlns:soapenv="" xmlns:wsh="http://WSHandler/">

You can also use netbeans to generate a sample SOAP request, for the same purpose. My case, in netbeans, it gave me:

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="">
        <ns0:ServerName xmlns:ns0="http://WSHandler/"/>

So, really similar, but you need the HTTP part PLUS the SOAP Envelope part.

4th) The Arduino Code.

#define WEBPAGE      "/CloudTest/Xav13ruaPRO"
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 8080);
  if (www.connected()) {
    Serial.println("TCP Connection   OK!\n\n");   
    www.fastrprint(F("POST "));
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Accept-Encoding: gzip,deflate\r\n")); 
    www.fastrprint(F("Content-Type: text/xml;charset=UTF-8\r\n"));
    www.fastrprint(F("Content-Length: 208\r\n"));
    www.fastrprint(F("Connection: Keep-Alive\r\n"));
    www.fastrprint(F("User-Agent: Apache-HttpClient/4.1.1 (java 1.5)\r\n"));
    www.fastrprint(F("SOAPAction: \"\"\r\n")); www.fastrprint(F("\r\n"));
    www.fastrprint(F("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"\">\r\n"));
        www.fastrprint(F("<ns0:ServerName xmlns:ns0=\"http://WSHandler/\"/>\r\n"));

Attached, you have the full code, for the shield mentioned.

5th: The result, Which is the most important part:

Hello, Xavier!
Free RAM: 1151
Attempting to connect to OpenFCT … Connected!
Requesting address from DHCP server… OK

IP Addr:
10-22-240-187.un… →

TCP Connection OK!

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Wed, 28 May 2014 11:04:25 GMT


<?xml version='1.0' encoding='UTF-8'?>

<ns2:ServerNameResponse xmlns:ns2=“http://WSHandler/”>
Server Name: Xav13rua PRO


In here, my webservice gives the return string “Server Name: Xav13rua PRO”. This is a webservice to retrieve the host name of the server :slight_smile:

WebClient.ino (7.56 KB)

Hello from El Salvador!!

My friend, i just want to say that your post help me a lot.... I was having the learning curve you said before, until i found your post.

So, thanks for the help, cause i'm using arduino for a project in my work and i was getting a little estressed with the connection to the WS.

PD: Sorry if i have mistakes: English isn´t my native language. :slight_smile: