• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Very Simple Web Service

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.. Java newb coming from .NET development
I've posted this on several forums but nobody answered
What am trying to do is actually very simple, don't need a fancy (heavy) IDE, notepad is more than enough
I downloaded and installed both JDK 1.6 & Glassfish v3, both installed correctly and are up and running
I need to create a simple HELLO web service, code goes like this

Code:


What I need next is to simply put this in a .war file and place it in the "autodeploy" folder of the glassfish web server
Coming from the .NET world, things are as simple as creating your asmx file and copying it over to IIS, you can simply use notepad to write the following

Code:


Save that as "Hello.asmx", copy it to "C:\inetpub\wwwroot\", go to "http://localhost/Hello.asmx" and there you go, you have your webservice working perfectly

Is it possible to do the same with Java & Glassfish !?
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are ok with using Netbeans IDE + Glassfish, then the details of packaging your code are all taken care of. The generated build scripts do all the work.

And once you build, you can copy it to the autodeploy folder or simply right-click the project and select Deploy to deploy it. It is mostly very intuitive and easy to use. You can download Netbeans/Glassfish from here: http://netbeans.org/downloads/ - Its the 216 MB download in the Java column.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
No, developing a Java web service is not quite as simple as writing a single file and deploying it.
In this case, you will need to:
1. Write an annotated Java class (using the @WebService) annotation.
2. Compile it.
3. Package it in a WAR file.
4. Deploy it to GlassFish.

I personally would not do this with "notepad" - perhaps with vi in a *nix terminal, though (with the appropriate Java tools installed).
For further details, I would recommend the NetBeans tutorials on web services: http://netbeans.org/kb/trails/web.html
There you can get a feeling about the degree of difficulty developing Java web services, even though NetBeans will hide some of the more gory details.
Best wishes!
 
Wael Reslan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help guys
What's an "annotated Java class" ?? Can you please provide an example regarding the simple Hello code I wrote ?
I do have Netbeans but am not quite satisfied! A lot goes around in the background without you knowing what's really happening.. that's not how I like 2 do my work.. I prefer full control over my code
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to use an IDE; in fact, I recommend not to use one while learning WS, since they hide a lot of the details that you need to understand to be a successful WS developer.

Both Metro and Apache Axis2 have implementations of JAX-WS (which is the major Java SOAP API), and both have lots of tutorials and example code on their respective web sites. The WebServicesFaq also points to lots of helpful material.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, check this. you may find what you want.
Please, do not consider that "xjc" work if you want ws with simple parameters and return type.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Manan Panchal wrote:Please, check this. you may find what you want.


A good example, but not as simple as it could have been made.
There is no need for XML schemas, JAXB bean classes, not even a web.xml deployment descriptor is needed.

Here is a simple example of an annotated endpoint implementation class that, once deployed, will become a web service:

Best wishes!
 
Wael Reslan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am starting to like this forum.. people are actually helpful thanks guys for the effort
So Ivan how do I deploy that to Glassfish? What your saying is that I should put this piece of code in let's say a HelloWorldWS.java file then use "jar cvf HelloWorldWS.war HelloWorldWS.java" from the command line to convert it to a war file and then I can deploy it ?
Well I already tried this approach with the sample code I wrote in my first post (which I think is very similar to the code you wrote), but deployment to Glassfish failed !?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
- Create a web application project (Dynamic Web Project in Eclipse).
- Develop the endpoint implementation class in the new project, in some source package.
- Deploy the project to GlassFish (in Eclipse, Run As -> Run on Server).

That's it! Let me know if you still have any problems!
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic