Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 7th, 2012, 04:29 AM
@passat @passat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 @passat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old November 8th, 2012, 05:15 PM
stdunbar's Avatar
stdunbar stdunbar is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 2,398 stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 18 h 14 m 25 sec
Reputation Power: 1660
Send a message via Yahoo to stdunbar Send a message via Google Talk to 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.
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
  #3  
Old November 9th, 2012, 03:32 AM
@passat @passat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 @passat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old November 9th, 2012, 01:42 PM
Annie79's Avatar
Annie79 Annie79 is offline
Meow Black Belt
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2005
Location: Beaverton OR
Posts: 932 Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)Annie79 User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 49426 Folding Title: Beginner FolderFolding Points: 49426 Folding Title: Beginner FolderFolding Points: 49426 Folding Title: Beginner Folder
Time spent in forums: 4 Weeks 1 Day 1 h 36 m 24 sec
Reputation Power: 525
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.
__________________

Reply With Quote
  #5  
Old November 9th, 2012, 02:18 PM
stdunbar's Avatar
stdunbar stdunbar is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 2,398 stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 18 h 14 m 25 sec
Reputation Power: 1660
Send a message via Yahoo to stdunbar Send a message via Google Talk to stdunbar
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
  1. import javax.jws.WebMethod;
  2. import javax.jws.WebService;
  3.  
  4. @WebService( serviceName = "TranslationService" )
  5. public class Translator {
  6.  
  7.     @WebMethod
  8.     public String  getWord( String word, String originalLanguage, String targetLanguage ) {
  9.         // lookup word in original language, return in target language
  10.        
  11.         return word + originalLanguage;
  12.     }
  13. }


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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Simple Java Web Service - help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap