Engineering Full Stack Apps with Java and JavaScript
Before trying out this example, you will need to download and install Java EE 7 SDK which comes with GlassFish Open Source Edition 4 (currently 4.1.1) and then configure eclipse to deploy Java EE applications directly to GlassFish Server.
For details, refer to http://www.javajee.com/configuring-glassfish-server-4-with-eclipse-to-bu....
Start the Eclipse (Java EE eclipse configured with Glassfish server)
Create a Dynamic Web Project selecting Glassfish server as the Target runtime.
Screenshot: Dynamic Web Project
Right click on src folder under java resources and create a simple class annotated as web service:
package com.javajee.webservices.soap;
import javax.jws.WebService;
@WebService
public class MyWebService {public String myServiceMethod() {
return "Message From myServiceMethod";}
}
Right click Glassfish server in the servers tab, click on "Add or Remove", and add "WebServiceDemo".
Right click on the server in the servers view and go to Glassfish > view Admin Console. This will take you to the admin console @ http://localhost:4848/common/index.jsf.
Click on Applications tab on left to see the list of deployed applications. You can see the application WebServicesDemo. Note Engines are specified as webservices and web.
Click on the application to go to Edit Application page.
Under 'Modules and Components' click on 'View Endpoint' link. It will provide links to the wsdl as well as a tester for testing out the SOAP web service.
View the wsdl and test the application using the tester to see the SOAP request and SOAP response.
Screenshot: Tester
Delpoyment may fail with below error:
cannot Deploy WebServiceDemo
deploy is failing=Application with name
[WebServiceDemo] is not deployed
Solution 1:
Check:
if you have defined a package for your web service class. Default package will result in NullPointerException
if you have at least one public method in your web service class
Solution 2:
(If solution 1 did not help)
Right click Glassfish server in the servers tab and check (select) "Use JAR archives for deployment" in the Glassfish tab.