From Basic Java Project With Web Service To Deployable Glassfish Artifacts? - java

I am trying to learn about Web Services, Glassfish, Eclipse, etc. and the way I learn is I like to do things manually Instead of playing around with Dynamic Web Projects as many of the tutorials online ask you to do. I am starting with a basic Java project and creating the WSDLs, client stubs, etc. by hand.
I have (remarkably) come pretty far along. What I have done so far is create a web service class and used wsgen to create the WSDL and then used wsimport to create client stubs.
The part that I am stuck on is how do I deploy my service to Glassfish? I have been able to do it using Eclipse (right-click, -> Web Services -> Create Web Service) but as I stated above I want to learn how things work under the covers. So let's say I was using nothing but Notepad and a Java command line compiler how would I go from my current Web Service project to something that is deployable in Glassfish?
Thanks!

You find a hell lot of examples on the Apache TomEE website. This one might fit your needs.
http://openejb.apache.org/examples-trunk/simple-webservice/
You need to package your Webservice and deploy it to the container. There is merely anything happening "under the hood". It's just bred and butter stuff for your IDE. you could also do everything "by hand" (war, http://www.openscope.net/2010/01/25/war-deployment-file-structure/ ; asadmin deploy http://docs.oracle.com/cd/E19798-01/821-1751/giobi/index.html).
M

Related

how to access method of dynamic web project using web service?

I know the core java only and started to learning J2EE. I have a doubt related to Dynamic Web Project.
Currently I have a Dynamic Web Project, JBOSS server and I have to access methods from it using web service.
I am confused about it and tried the different ways like import the package, import the JAR of it, etc.
But I am not getting how to do it with the help of web service. I also don't know the how to create the web service?
Pls tell me how do I access method from it?
Thanks
If you can do what you're trying to do with a servlet, then don't create a full fledged web service. A servlet is much easier, much more efficient, and arguably much more portable to a wider range of potential clients.
If, for whatever reason, you can't use a servlet (and you must, for whatever reason, create a web service), then consider REST instead of SOAP.
For example:
RESTEasy, or
JAX-RS
If you want to create stub files from a wsdl file on windows OS you can use of "java org.apache.axis.wsdl.WSDL2Java -o src -s WSDL wsdl_name" by setting the classpath variables
in your batch file with(.bat) extensions.
Have a look in apache axis.
http://axis.apache.org/axis/

How to came know that some web services is present in project in java

I don't know much about the J2EE/Web Project in Java.
Actually the thing is like that I have git some projects (10-12) inter-related with each other (contains lots of packages, classes, etc). And it requires JBOSS server to run the complete project.
I am confused after seeing some little bit code of it. When I tried to run it using JBOSS server then it opens a link in the browser.
I want to know that actually where the web service is present in the project so that I can come to know the little bit by bit things.
Sorry for asking idiot question.
Please advice.
Thanks
Have a look at the web.xml file of the Project.
It will give you a head start.
Bhavesh.. Firstly you should know which type of webservice has been developed in your project. Either REST or SOAP service.
Second thing you should know that on which library or technologies your web service built on.
for example REST based service can be developed by using Jersey or Spring MVC (in this case you can find some annotation like #RequestMappling or #GET).
SOAP based web-services commonly contain WSDL file and some .XSD (in case of contract first webservice) file.
Being without specific information it is pretty hard to tell about where is your web-service part in project.

Export java web service from eclipse java ee

This might be a newbie question. But I am working with iPhone programming and I have hosted my own webservices written in Java on a ubuntu linux and Eclipse EE edition with a glashfish server. Is there any easy way to export this webservice and getting it hosted elsewhere.
I have been looking around for a solution but have not found the grail yet.
All help is appreciated
I don't know what you have in mind when you think "export", but you're deploying a WAR file locally on Glassfish. That's the package you need to pick up and move to your hosting service. They, in turn, have to accept WAR files and deploy on a Java EE app server.
Your WAR file should be portable if it has everything your app needs. Make clear what you need from the server (e.g. dependent JARs); everything else should be in your WAR.
If you can adapt your solution to the limitations of the Google Application Engine, they will host it for free.
This strongly depends on how many Java EE features you use.
there any easy way to export this webservice and getting it hosted elsewhere.
You just need to take war file and deploy it somewhere else you want

What framework + application server + development environment to use for Java services?

I'm trying to write a Java service which runs 24/7, scrapes content from the web, and stores it into a database. What is the best framework to use for this given that I'd like to...
1.) Have an application server that I can deploy my code to (and have it run automatically). This application server should sit on a separate box from the machine that my development environment will run on.
2.) Have a development platform (I would prefer something based on eclipse) which allows me to deploy my code directly to the application server (so I don't have to ftp everything over to test).
3.) Utilize a framework like Spring.
In effect, I'd like to know what to choose for my...
1.) application server
2.) development environment (ide) -- if eclipse, what server adapter to use
3.) framework
So far, I've tried using Virgo with SpringSource STS, but was unable to configure the web server adapter for a non-localhost-residing server. I don't want to have to install Virgo on my development box, and I don't want to have to ftp hop my code over to my production server in order to deploy.
Why don't you just use Tomcat or some other web container, but it may be better to split this into two applications.
Have one that goes out and does the scraping, as a standalone application, for this you can pick anything, I would go with Groovy (http://groovy.codehaus.org/), as ease of development and maintenance is important here, and you can use the Groovy plugin for Eclipse.
The other would be the web service and for this I would think Scala (http://www.scala-lang.org/) would be nice, if you have time to learn it, but Grails (a groovy framework) would be beneficial, so you can write a REST or SOAP web service.
By separating them then you can pick the best solution for that particular aspect, since the web server shouldn't be involved in scraping, but the web server will want to read from the database.
These two languages run on the JVM and can use regular java classes/libraries, but there are improvements over plain Java in them.
Turns out there are some maven plugins that will remotely deploy my app for me. The most notable is Cargo. This way, I can keep all of my initial tools/services the same (Virgo, STS, Maven).
I've actually build something similar quite recently. My application could run without a servlet container or an application server. The reason I choose to run my app in a Tomcat servlet engine is so that I can add a REST API to it to easily retrieve server status information, but I digress.
The plain vanilla Eclipse J2EE installation has decent Tomcat support so without knowing more about your tastes and specifics I'd go with that.
To make your application self starting you need to implement the ServletContextListener interface:
public class ServerClass extends HttpServlet implements ServletContextListener {
public void contextInitialized( ServletContextEvent event ) {
// create and start a thread here.
}
public void contextDestroyed( ServletContextEvent event ) {
}
}
Add the following to your web.xml:
<listener>
<listener-class>com.my.ServerClass</listener-class>
</listener>
Which framework you want to use, only you can decide. Your question is to generic to give a decent answer on that. Read up on a few and pick one. Plain old Java will also do just fine and otherwise Scala might be a good substitute choice.
So, to answer your questions:
Tomcat servlet engine
Vanilla J2EE Eclipse version
Plain old Java

Web Services in Java, beginner question

Im new to the subject of web services in java, though im familiar with the concept of web services. As im new to this topic,i have the following questions which i would like someone to help me with.
1) How are web services created in Java ?.Ive come across methods like using Eclipe WTP (Web Tools Platform), Sun WSDP (Web Services Developer Pack). What is the difference between them and which one to use ?
2) Is there any particular book or article on the web which i can refer to for learning how to create a basic web service using Java ?
3) If i have a WSDL file, is there any way i can test it ?
Thank You
1) Actually you have a lot of choices. See this question for a discussion about Java Web Services Frameworks. The two methods actually use a different framework, Eclipse uses Axis2.
2) Most, if not all, frameworks support 'contract first' development (from an existing WSDL), both for services and clients. For testing, SoapUI may also suit your needs.
Before choosing any tool and technology, first understand what webservice technology is about and what benefits it offers.
Its always better to understand the proper semantics of xml, xsd and other concepts(including namespaces).
Then pickup a book/article that explains how to implements one in java.
Choose a framework (Apache Axis, Spring ws etc) and implement one.
There are lot of resources available online that help you in your learning path.
Happy webservices.
For #3, you can test it using the web services explorer in Eclipse. Its really nice actually. Copy the source for the WSDL and copy it into some file in your project (xxxx.wsdl). Then, right click on that file in the navigator and choose "Web Services" -> "Test with Web Services Explorer"
If you dont have this option, then you need to install the necessary plugins into Eclipse to do this (or I think if you install the EE version of Eclipse it already has this). I dont recall which plugin I installed that added this functionality, but it was something relating to web work.
Once you've opened this, you can input values as the wsdl specifies and view the source xml as needed.
I'm also new to web development and I've found this incredibly helpful.
Best of luck!

Categories

Resources