Monday 12 March 2012

An Analysis of JAX-WS usage of NetBeans 1.2.1 (Production of the webclient)

This is a closer look at JAX-WS examples provided by JAVAEE5/JAVAEE6 tutorials. The names of the examples are helloservice, webclient and appclient. This is the continuation of the first part. I will explain the development of the webclient first in
An Analysis of JAX-WS usage of NetBeans 1.2.1 (Production of the webclient)
And then I will compare dynamically the changes in the directory and project levels at the different phases of the project in the succeeding section
An Analysis of JAX-WS usage of NetBeans 1.2.2 (Anaysis of the webclient)

1 webclient:



Please notice the configuration files and other folders, there is nothing related to the webservic accept the WSDL address we entered into HelloServlet.java:
HelloServlet.java
/*
* Copyright 2011 Oracle and/or its affiliates.
* All rights reserved. You may not modify, use,
* reproduce, or distribute this software except in
* compliance with the terms of the License at:
* http://developers.sun.com/license/berkeley_license.html
*/


package webclient;

//import helloservice.endpoint.HelloService;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;


@WebServlet(name = "HelloServlet", urlPatterns = {
"/HelloServlet"}
)
public class HelloServlet extends HttpServlet {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/ars-PC_8080/helloservice/HelloService.wsdl")
public HelloService service;

/**
* Processes requests for both HTTP <code>GET</code>
* and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

try {
out.println("<html lang=\"en\">");
out.println("<head>");
out.println("<title>Servlet HelloServlet</title>");
out.println("</head>");
out.println("<body>");
out.println(
"<h1>Servlet HelloServlet at " + request.getContextPath()
+ "</h1>");
out.println("<p>" + sayHello("world") + "</p>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(
HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
} // </editor-fold>

private String sayHello(java.lang.String arg0) {
//helloservice.endpoint.Hello port = service.getHelloPort();
webclient.Hello port = service.getHelloPort();
return port.sayHello(arg0);
}
}

2 The WSDL adress given above as:
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/ars-PC_8080/helloservice/HelloService.wsdl")

Can be found by doing:
2.1 Open the GlassFish server Admin
2.2 Go to applications, helloservice and to the bottom of the page you see:



2.3 Click on the View Endpoint at the right bottom corner:



2.4 Click on the highlighted line which ends with wsdl. Here is the wsdl address:



3. After we get the WSDL adress for the webservice we had created with the helloservice project we can set up for the wsimport of this service.

3.1 Right click on webclient and select new, select Web Service Client:



3.2 Enter the WSDL adress that you have taken from the GlassFish Admin. Select the package your imported and generated java sources will reside.



3.3 When you select finish it begins to parse:




3.4 The output window shows the generated code:



3.5 The project window becomes as shown below. At this point we can pursue our goal of dynamically comparing the changes in the directory and project levels at the different phases of the project:



1.2.2 Please proceed to the section
An Analysis of JAX-WS usage of NetBeans 1.2.2 (Analysis of the webclient)