A Techno Blog, mainly about Java

Soap Client Homemade implementation

The Soap request:

<?xml version=”1.0″ encoding=”utf-8″?>

<soap:Envelope xmlns:xsi=”; xmlns:xsd=”; xmlns:soap=””&gt;
<GetInfoByZIP xmlns=”http://www.webserviceX.NET”&gt;

The java program:

try {
// Set up the Web Service URL and SOAP Message file name
// src/exercise1/test.xml

String WebServiceUrl = args[0];
String SOAPFile = args[1];

//Create the connection where we’re going to send the file.
URL url = new URL(WebServiceUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

//Get the SOAP document ready to send

File f1 = new File(SOAPFile);
String path = f1.getAbsolutePath();
FileInputStream FileIn = new FileInputStream(path);
ByteArrayOutputStream ByteOut = new ByteArrayOutputStream();
byte[] buffer = new byte[256];
while (true) {
int bytesRead =;
if (bytesRead == -1)
ByteOut.write(buffer, 0, bytesRead);

byte[] b = ByteOut.toByteArray();

//Set the HTTP parameters.
httpConn.setRequestProperty(“Content-Length”, String.valueOf(b.length));
httpConn.setRequestProperty(“Content-Type”, “text/xml; charset=utf-8”);
“application/soap+xml, application/dime, multipart/related, text/*”);
httpConn.setRequestProperty(“User-Agent”, “WSAD”);
httpConn.setRequestProperty(“Host”, “localhost”);
httpConn.setRequestProperty(“Cache-Control”, “no-chache”);
httpConn.setRequestProperty(“Pragma”, “no-chache”);
httpConn.setRequestProperty(“SOAPAction”, “http://www.webserviceX.NET/GetInfoByZIP&#8221;);

//Send XML File
OutputStream out = httpConn.getOutputStream();

//Get the response
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine;
while ((inputLine = in.readLine()) != null)

} catch (Exception e) {
System.out.println(“FaultString: ” + e.toString());
} //end exception


<?xml version=”1.0″ encoding=”utf-8″?><soap:Envelope xmlns:soap=”; xmlns:xsi=”; xmlns:xsd=””><soap:Body><GetInfoByZIPResponse xmlns=”http://www.webserviceX.NET”><GetInfoByZIPResult><NewDataSet xmlns=””><Table><CITY>Raleigh</CITY><STATE>NC</STATE><ZIP>27615</ZIP><AREA_CODE>919</AREA_CODE><TIME_ZONE>E</TIME_ZONE></Table></NewDataSet></GetInfoByZIPResult></GetInfoByZIPResponse></soap:Body></soap:Envelope>

October 21, 2012 Posted by | Uncategorized | Leave a comment

Soap Web Services Begin To End Part 3

Using the WSDL in Part 2, right click on it in the sidebar:

WebService -> Generate Java Bean Skeleton

Again move the notch up to  Test Service  and click Next until it completes

Then, you will see in src folder all the generated files.

This completes the Producer  side of the web service.

Now, to generate a client side, you generate a new dynamic project (i.e. Call it MyClientProject).  After the dynamic project is complete, you can go into the Producer project, and get the wsdl and place it in the new Client project. Right click on the WSDL, click WebService -> Generate Client.




October 21, 2012 Posted by | Uncategorized | Leave a comment

Soap Web Services Begin To End Part 2

Create a Dynamic Web project in eclipse. In my case I called it NumbersService.

Create a new class :
learn.webservices.numbers.ElectricCompanyService :

public class ElectricCompanyService {

public int multiply(int number1, int number2)
return number1 * number2;

public int add(int number1, int number2)
return number1 – number2;


Right click in the siderbar on ElectricCompanyService

WebService-> Create Web Service

On the screen that comes up, move the selector up one notch where it shows Test Service

In Web Content you can find a folder named WSDL with the WSDL file

<?xml version=”1.0″ encoding=”UTF-8″?>
<wsdl:definitions targetNamespace=”http://numbers.webservices.learn&#8221; xmlns:apachesoap=”; xmlns:impl=”http://numbers.webservices.learn&#8221; xmlns:intf=”http://numbers.webservices.learn&#8221; xmlns:wsdl=”; xmlns:wsdlsoap=”; xmlns:xsd=””&gt;
<!–WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)–>
<schema elementFormDefault=”qualified” targetNamespace=”http://numbers.webservices.learn&#8221; xmlns=””&gt;
<element name=”add”>
<element name=”number1″ type=”xsd:int”/>
<element name=”number2″ type=”xsd:int”/>
<element name=”addResponse”>
<element name=”addReturn” type=”xsd:int”/>
<element name=”multiply”>
<element name=”number1″ type=”xsd:int”/>
<element name=”number2″ type=”xsd:int”/>
<element name=”multiplyResponse”>
<element name=”multiplyReturn” type=”xsd:int”/>

<wsdl:message name=”multiplyResponse”>

<wsdl:part element=”impl:multiplyResponse” name=”parameters”>



<wsdl:message name=”multiplyRequest”>

<wsdl:part element=”impl:multiply” name=”parameters”>



<wsdl:message name=”addResponse”>

<wsdl:part element=”impl:addResponse” name=”parameters”>



<wsdl:message name=”addRequest”>

<wsdl:part element=”impl:add” name=”parameters”>



<wsdl:portType name=”ElectricCompanyService”>

<wsdl:operation name=”add”>

<wsdl:input message=”impl:addRequest” name=”addRequest”>


<wsdl:output message=”impl:addResponse” name=”addResponse”>



<wsdl:operation name=”multiply”>

<wsdl:input message=”impl:multiplyRequest” name=”multiplyRequest”>


<wsdl:output message=”impl:multiplyResponse” name=”multiplyResponse”>




<wsdl:binding name=”ElectricCompanyServiceSoapBinding” type=”impl:ElectricCompanyService”>

<wsdlsoap:binding style=”document” transport=””/&gt;

<wsdl:operation name=”add”>

<wsdlsoap:operation soapAction=””/>

<wsdl:input name=”addRequest”>

<wsdlsoap:body use=”literal”/>


<wsdl:output name=”addResponse”>

<wsdlsoap:body use=”literal”/>



<wsdl:operation name=”multiply”>

<wsdlsoap:operation soapAction=””/>

<wsdl:input name=”multiplyRequest”>

<wsdlsoap:body use=”literal”/>


<wsdl:output name=”multiplyResponse”>

<wsdlsoap:body use=”literal”/>




<wsdl:service name=”ElectricCompanyServiceService”>

<wsdl:port binding=”impl:ElectricCompanyServiceSoapBinding” name=”ElectricCompanyService”>

<wsdlsoap:address location=”http://localhost:8080/NumbersService/services/ElectricCompanyService”/&gt;





October 21, 2012 Posted by | Uncategorized | Leave a comment

Soap Web Services Begin To End Part I

Step 1 : Open Web Perspective -> Web Services Explorer

Launch Web services explorer:

Select WSDL page (next to star on right):

Enter the SDL URL :

Choose Soap enter stock quote and Go!

<soapenv:Envelope xmlns:soapenv=”” xmlns:q0=”http://www.webserviceX.NET/” xmlns:xsd=”” xmlns:xsi=”“>







<soap:Envelope xmlns:soap=”” xmlns:xsd=”” xmlns:xsi=”“>


<GetQuoteResponse xmlns=”http://www.webserviceX.NET/“>

  <GetQuoteResult><StockQuotes><Stock><Symbol>IBM</Symbol><Last>193.36</Last><Date>10/19/2012</Date><Time>4:03pm</Time><Change>-1.60</Change><Open>195.12</Open><High>196.08</High><Low>193.18</Low><Volume>6621563</Volume><MktCap>219.9B</MktCap><PreviousClose>194.96</PreviousClose><PercentageChange>-0.82%</PercentageChange><AnnRange>177.06 – 211.79</AnnRange><Earns>13.913</Earns><P-E>14.01</P-E><Name>International Bus</Name></Stock></StockQuotes></GetQuoteResult>




Here is a WSDL for Mortgage  payments calculation:

October 21, 2012 Posted by | Uncategorized | Leave a comment

Spring Documento

In web.xml with Spring MVC (Convenient ApplicationContext instantiation for web applications):

ContextLoader called  by ContextLoaderListener

[ref] : “ContextLoaderListener creates a root web-application-context for the web-application and puts it in the ServletContext. This context can be used to load and unload the spring-managed beans ir-respective of what technology is being used in the controller layer(Struts or Spring MVC) ”

  • org.springframework.web.servlet.DispatcherServlet

[ref] : “DispatcherServlet creates its own WebApplicationContext and the handlers/controllers/view-resolvers are managed by this contextContextLoader”

“When ContextLoaderListener is used in tandem with DispatcherServlet, a root web-application-context is created first as said earlier and a child-context is also created by DispatcherSerlvet and is attached to the root application-context.”


[ref] Spring’s DelegatingFilterProxy provides the link between web.xml and the application context. .. “it finds a bean (“target bean” or “delegate”) in your Spring application context, an invoke it. How is it possible? Because this bean implements javax.servlet.Filter, its doFilter method is called.”


[link ] :  The feature I’m talking about is the ability to reload (and detect changes in) i18n property files on-the-fly.


This interface that maps handlers based on HTTP paths expressed through the RequestMapping annotation at the type or method level.


October 14, 2012 Posted by | IoC | Leave a comment

Now Learning Soap Web Services

Soap is a lightweight protocol for exchanging structured information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts:

  • an envelope that defines a framework for describing what is in a message and how to process it
  • a set of encoding rules for expressing instances of application-defined datatypes
  • a convention for representing remote procedure calls and responses

Soap Request, Soap Response

RPC Style, Document Style Soap

<soapenv:Envelope> <soapenv:Body>

Apache Axis is an implementation of the SOAP by Apache

WSDL document describes the interface of a web service in a language and protocol independent way:

  • service : Defines service
  • binding : possible ways to invoke service
  • port: defined endpoint
  • porttype: particular interface
  • operation: defines method
  • message :
  • types: datatypes with schema




October 3, 2012 Posted by | Web/Tech | Leave a comment