The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Homework - Simple Java Web Service - help
Discuss Simple Java Web Service - help in the Java Help forum on Dev Shed. Simple Java Web Service - help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 7th, 2012, 04:29 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 25 m 35 sec
Reputation Power: 0
|
|
|
Homework - Simple Java Web Service - help
This is the task:
Create a translation service.
Customer service to activate the service method as follows:
getWord ("car", "russian", "polish")
The first parameter is the required word, the second is the original language, and the third target language.
The method should return a string with the appropriate word or words separated by commas if there are synonyms.
Data source, the service should use XML documents (the system may have only a few words, in order to test the functionality).
I started by creating an XML file and establishing a connection between Java and XML:
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class Main {
public static void main(String[] args) throws
ParserConfigurationException, SAXException, IOException{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
sp.parse ("Servis.xml", new MySaxHandler());
}
}
I have no idea what to do next. Please help.
|

November 8th, 2012, 05:15 PM
|
 |
Contributing User
|
|
Join Date: May 2004
Location: Superior, CO, USA
|
|
|
I'm not sure what you're trying to do - a SOAP web service or what? Is this just a command line program or a web based program? Let us know some more details and we'll try to help.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.
|

November 9th, 2012, 03:32 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 25 m 35 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by stdunbar I'm not sure what you're trying to do - a SOAP web service or what? Is this just a command line program or a web based program? Let us know some more details and we'll try to help. |
I need to create a Java web service . I can use SOAP or JAX-WS. I am using NetBeans and GlassFish server but this field is new for me so I do not even know where to start.
|

November 9th, 2012, 01:42 PM
|
 |
Meow Black Belt
|
|
Join Date: Oct 2005
Location: Beaverton OR
|
|
Quote: | Originally Posted by @passat I need to create a Java web service . I can use SOAP or JAX-WS. I am using NetBeans and GlassFish server but this field is new for me so I do not even know where to start. |
Refer to Java EE tutorial for getting started with creating a web service.
__________________
|

November 9th, 2012, 02:18 PM
|
 |
Contributing User
|
|
Join Date: May 2004
Location: Superior, CO, USA
|
|
I'd take a look at this link to get started.
A tiny bit of code to get you going:
java Code:
Original
- java Code |
|
|
|
import javax.jws.WebMethod; import javax.jws.WebService; @WebService( serviceName = "TranslationService" ) public class Translator { @WebMethod // lookup word in original language, return in target language return word + originalLanguage; } }
All this does is define the "TranslationService". And in my case it simply adds the string of the originalLanguage to the end - just something to show that it's different.
If you deploy this to glassfish you'll be able to see that the web service exists by going to something like http://localhost:8080/yourwebapp/TranslationService?WSDL. In this case "yourwebapp" is the name of your web application.
The client side is a bit more involved. Basically you'll want to use the Java command "wsimport". This is in the bin directory of your JDK. In a directory, and assuming that your service is deployed to http://localhost:8080/yourwebapp/TranslationService?wsdl you would run something like:
Code:
mkdir src
wsimport -keep -s src -p com.yourpackagename.soap http://localhost:8080/yourwebapp/TranslationService?wsdl
This will generate several files in src/com/yourpackagename/soap. You do not need to understand each of these files. But your two most important ones will be src/com/yourpackagename/soap/TranslationService.java and src/com/yourpackagename/soap/Translator.java (assuming that you use my code above). From there you can access the "service" and "port" (the port will contain a mirror of the method you want.
That's alot of stuff. Give it a shot and let us know where it breaks.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|