Hey guys, I'm really new to this :icon_confused: I've managed to setup a Web Service and a Client to access the service within Eclipse. However, I want to access a Web Service that already exists. From what I understand, that service must have a WSDL (Web Services Description Language) for it to be used by Eclipse. The Web Service that I want to interact with does not have a WSDL or at the very least it doesn't have a .wsdl file. Um I'm hoping that's possible or perhaps I've confused the application I'm trying to access for a Web Service?

I'm using a pre-defined platform that can process SOAP requests. Just to confirm the following is a SOAP request hey?

<?xml version="1.0" encoding="UTF-8"?>
<GetObservation service="SOS" version="0.0.31"
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"
xmlns:swe="http://www.opengis.net/swe">
<offering>TAG_READING</offering>
<eventTime>
<ogc:During>
<gml:TimePeriod>
<gml:beginPosition>2007-12-10T08:00:00</gml:beginPosition>
<gml:endPosition>2007-12-13T12:00:00</gml:endPosition>
</gml:TimePeriod>
</ogc:During>
</eventTime>
<procedure>urn:ogc:def:procedure:wavertrend_rx201_sensory_web</procedure>
<observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:temperature</observedProperty>
<featureOfInterest>
<ObjectID>COR01</ObjectID>
</featureOfInterest>
<resultFormat>text/xml;subtype="OM"</resultFormat>
</GetObservation>

I want to be able to send requests via a Java program and interpret these results within the program. Can anyone please tell me how this is done? I'd need the appropriate .jar files hey? I'm not sure what they are or if they even come with Eclipse. The version of Eclipse that I have is the JaveEE one. Please advise :icon_neutral:

Recommended Answers

All 7 Replies

I think that a Web Service offers remote procedure calls (methods that can be called over the internet). The application I'm working with is really a servlet that accepts xml requests so I guess it isn't a web service? I'm a bit unsure as to how I would perform such the xml request in Java though. I think that I'd need to create a URL object that points to the actual servlet?

URL service = new URL("http://localhost:8080/52nSOSv2/sos");
URLConnection connection = service.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

I'm not really sure what other parameters are used in setRequestProperty but can I simply create an output stream and write the xml request to it?

ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
String request = ""; //xml request with correct escape sequences
out.writeChars(request);

It doesn't seem to be working out, can someone please advise?

hi,

web service soap interface is defined by a wsdl file.
you can manually write a wsdl file or you can use some tools to generate the same(preferred way).

now, this wsdl file will work as a contract between soap server and soap client .
both server and the client can use this file to generate the stub files wrt soap methods.

I m not sure whether u was asking the same or you have some other doubt!!

Have fun with it!!

Manoj

commented: Thanks for your help :) +2

Thanks for replying! So I should find a .wsdl file somewhere within the application if I was indeed working with a web service? Then I most definitely do not have a Web Service. That's one doubt cleared up thank you!

Now I'm not sure how to interact with the serlvet. The Java program I'm writing must be able to send requests in the form of xml to the servlet and get the response back. Hmmm this sounds like something for the JSP forum. I've been reading up on servlets bust still can't get it right. The error looks something like this: An xml error occurred when parsing the request: XML Exception: error: Illegal XML character: 0x0

hi,

for a web service method....input and output parameters should be an xml document.

let me tell me the basic logic.........

wsdl file is nothing but is an interface(just like some other java interface) and you should have some .java file which is implementing this interface.

wsdl file contains the information about the name of the methods, input/output parameters , message format, binding information, url's etc....,

so just like any other class what you have to do is to get the access of wsdl file(soap interface) from some other code(servlet/c# code/c++ code) and call the respective interface - as simple as that....

i dont have much idea in servlets...but if u want i can tell u with example how to access the same from c# code.

Have fun with it!!

Manoj

I understand that the wsdl file is written in xml and describes what remote methods (which could be regarded as services) are accessible and what their parameters are. I noticed that in Eclipse one can import a war file. I've done that and it Eclipse automatically generates the wsdl file. However, the import process isn't totally successful and the project itself has alota xml errors; errors that I'm not sure how to resolve. What I don't understand is that the wsdl file describes access to the servlet. A servlet has methods that are automatically invoked whenever access to a servlet is invoked. So instead of actually using SOAP, one would be able to simply POST to a serlvet. But I suppose being able to POST using SOAP could be useful in my application. Regardless, I still can't seem to get the project up so I can't test it. Thank you for your help Manoj! I wish I could just POST to the servlet as if I was using a HTML form but within a standard Java Application.

one update from my side...if yuo are using sevlets then better use jsp with it- no need to call any html form or something.

JSP is really a cool extension of HTML. I think the most common way to interact with a servlet via a JSP is to use the HTML <form> tag. I have managed to successfully create a connection to the servlet via a standard Java application. The thing I completely overlooked was that the xml request that I was sending had to be sent in URL encoding. If anyone’s interested, this is who I've done it:

URL service = new URL("http://localhost:8080/52nSOSv2/sos");
URLConnection connection = service.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
String request = URLEncoder.encode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
			"<GetObservation service=\"SOS\" version=\"0.0.31\" " +
			"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\" " +
			"xmlns:swe=\"http://www.opengis.net/swe\">" +
			"<offering>TAG_READING</offering>" +
			"<eventTime>" +
			"<ogc:During>" +
			"<gml:TimePeriod>" +
			"<gml:beginPosition>2001-12-10T08:00:00</gml:beginPosition>" +
			"<gml:endPosition>2008-12-13T12:00:00</gml:endPosition>" +
			"</gml:TimePeriod>" +
			"</ogc:During>" +
			"</eventTime>" +				
			"<procedure>urn:ogc:def:procedure:wavertrend_rx201_sensory_web</procedure>" +		
			"<observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:temperature</observedProperty>"  + 
			"<featureOfInterest>" +
			"<ObjectID>COR01</ObjectID>" +
			"</featureOfInterest>" +
			"<resultFormat>text/xml;subtype=\"OM\"</resultFormat>" +
			"</GetObservation>", "UTF-8");
System.out.println(request);
out.writeBytes(request);
out.flush();
out.close();
DataInputStream in = new DataInputStream(connection.getInputStream());
String line = "";
System.out.println("Response!!");
while ((line = in.readLine()) != null)
	System.out.println(line);

This site was rather useful: http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
The guy there said that the HTTP request's "content-type" field to be "application/x-www-form-urlencoded" because it is necessary since some versions of Netscape's browser has a bug which does not give out this proper content type when doing POSTs.

I think it would have been better if I just read in the xml request from a file - that's what I think I'll try to do now :icon_wink: Oh and the URL: http://localhost:8080/52nSOSv2/sos specifies the URL to the servlet as defined in the web.xml of any servlet driven website.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.