Results 1 to 2 of 2
  1. #1
    champ is offline Member
    Join Date
    Aug 2014
    Posts
    1
    Rep Power
    0

    Default webbased client who uses a public SOAP

    Hello I need help with my program.
    The service I use, "Periodic Table" from WebserviceX.NET. With this service you should pick up information that various elements in the periodic table. Such as learn boiling point, melting point, density, etc.. A description of the service, including the address of the WDSL

    My program succeed in what I want but I can not get to it exactly as I want.
    I must enter the element twice. First, on a site which then takes me on to the "right" website. Does anyone see what's in my code that I can arrange for you to directly get to the other site and do not have to enter the element twice?

    webbased client who uses a public SOAP-java1.jpg
    webbased client who uses a public SOAP-java2.jpg
    webbased client who uses a public SOAP-java3.jpg


    The code:

    Java Code:
    @WebServlet(name = "atomServlet", urlPatterns = {"/atomServlet"})
    public class atomServlet extends HttpServlet {
    
        private Periodictable periodic = new net.webservicex.Periodictable();
        private final net.webservicex.PeriodictableSoap periodicSoap = periodic.getPeriodictableSoap();
    
        /**
         * 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 {
                /* TODO output your page here. You may use following sample code. */
                out.println("<!DOCTYPE html>");
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet atomServlet</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Servlet atomServlet at " + request.getContextPath() + "</h1>");
                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 {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Sökning</title>");
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Sök efter grundämmnen</h1>");
                out.println("<form method = \"post\">");
                out.println("Ange ett grundämne: <input type = \"text\" name =\"elementName\" /><br/>");
                out.println("<input type = \"submit\" name =\"Sök\" /> ");
                out.println("</form>");
                out.println("</body>");
                out.println("</html>");
    
            } finally {
                out.close();
            }
    
        }
    
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            String bajs = request.getParameter("elementName");
            String bajs2 = periodicSoap.getAtomicNumber(bajs);
    
            InputStream inputStream = new ByteArrayInputStream(bajs2.getBytes());
            DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
    
            try {
                Document parse = newInstance.newDocumentBuilder().parse(inputStream);
    
                NodeList atomLista = parse.getElementsByTagName("Table");
    
                for (int i = 0; i < atomLista.getLength(); i++) {
                    atomServlet a = new atomServlet();
                    Element atomElement = (Element) atomLista.item(i);
    
                    NodeList atomicNumberList = atomElement.getElementsByTagName("AtomicNumber");
                    String atomicNumber = atomicNumberList.item(0).getFirstChild().getNodeValue();
    
                    NodeList atomNameList = atomElement.getElementsByTagName("ElementName");
                    String atomName = atomNameList.item(0).getFirstChild().getNodeValue();
    
                    NodeList symbolList = atomElement.getElementsByTagName("Symbol");
                    String symbol = symbolList.item(0).getFirstChild().getNodeValue();
    
                    NodeList atomicWeightList = atomElement.getElementsByTagName("AtomicWeight");
                    String atomicWeight = atomicWeightList.item(0).getFirstChild().getNodeValue();
    
                    NodeList boilingPointList = atomElement.getElementsByTagName("BoilingPoint");
                    String boilingPoint = boilingPointList.item(0).getFirstChild().getNodeValue();
    
                    NodeList ionisationPotentialList = atomElement.getElementsByTagName("IonisationPotential");
                    String ionisationPotential = ionisationPotentialList.item(0).getFirstChild().getNodeValue();
    
                    NodeList eletroNegativityList = atomElement.getElementsByTagName("EletroNegativity");
                    String eletroNegativity = eletroNegativityList.item(0).getFirstChild().getNodeValue();
    
                    NodeList atomicRadiusList = atomElement.getElementsByTagName("AtomicRadius");
                    String atomicRadius = atomicRadiusList.item(0).getFirstChild().getNodeValue();
    
                    NodeList meltingPointList = atomElement.getElementsByTagName("MeltingPoint");
                    String meltingPoint = meltingPointList.item(0).getFirstChild().getNodeValue();
    
                    NodeList densityList = atomElement.getElementsByTagName("Density");
                    String density = densityList.item(0).getFirstChild().getNodeValue();
                    
                    PrintWriter out = response.getWriter();
    
                    
                    out.println("<html>");
                    out.println("<head>");
                    out.println("<title>Sökning</title>");
                    out.println("</head>");
                    out.println("<body>");
                    out.println("<h1>Ange ett grundämne och välj vilka egenskaper som ska visas</h1>");
                    out.println("<form method = \"post\">");
                    out.println("Ange ett grundämne: <input type = \"text\" name =\"elementName\" /><br/>");
                    
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + atomicNumber  + ">Atomic Number <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + atomName + ">Element Namn <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + symbol + " >Symbol <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + atomicWeight + " >Atomvikt <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + boilingPoint + " >Kokpunkt <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + ionisationPotential + " >Jonisering Potential <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + eletroNegativity + " >Elektronnegativitet <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + atomicRadius + " >Atomic Number <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + meltingPoint + " >Smältpunkt <br/>");
                    out.println("<input type = \"checkbox\" name = \"kukName\" value = " + density + " >Densitet <br/>");
                    out.println("<br/>");
                    out.println("<input type = \"submit\" name =\"Sök\" /> <br/>");
                    out.println("</form>");
                    out.println("</body>");
                    out.println("</html>");
    
    
                    String[] kuk = request.getParameterValues("kukName");         
                    response.setContentType("text/html;charset=UTF-8");
    
                    out.println("Egenskaperna är: " + Arrays.toString(kuk));
                    
    
                }
    
            } catch (ParserConfigurationException ex) {
                Logger.getLogger(atomServlet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SAXException ex) {
                Logger.getLogger(atomServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
    
            {
    
            }
        }
    
        /**
         * Returns a short description of the servlet.
         *
         * @return a String containing servlet description
         */
        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>
    }
    Thanks in advance and sorry for bad english

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    368
    Rep Power
    5

    Default Re: webbased client who uses a public SOAP

    Your service is exposing 4 operations.
    You can test service operation GetAtomicNumber by entering Element name like oxygen on this page:
    periodictable Web Service

    Result is:
    XML Code:
    <NewDataSet>
      <Table>
        <AtomicNumber>8</AtomicNumber>
        <ElementName>Oxygen</ElementName>
        <Symbol>O</Symbol>
        <AtomicWeight>15.9994</AtomicWeight>
        <BoilingPoint>90.2</BoilingPoint>
        <IonisationPotential>13.61</IonisationPotential>
        <EletroNegativity>3.5</EletroNegativity>
        <AtomicRadius>0.74</AtomicRadius>
        <MeltingPoint>55</MeltingPoint>
        <Density>1.3318</Density>
      </Table>
    </NewDataSet>
    Based on your needs, you can either create a form with a single input for oxygen element,
    or you can you add checkboxes to the form to filter service reponse based on selection.

    1. create JSP with this form
    2. call servlet POST method and send element name (and checkboxes selected if needed)
    3. create web service client based on WSDL
    http://www.webservicex.net/periodictable.asmx?WSDL
    If you use e.g. Apache Axis as Web service runtime you will end up with several classes and you can recognize the one called 'proxy'

    Your app logic inside doPost() of you servlet will call this proxy :

    Java Code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		String parameter = request.getParameter("element");
    		PeriodictableSoapProxy proxy = new PeriodictableSoapProxy();
    		try {
    			String atomicNumberServiceTable = proxy.getAtomicNumber(parameter);
    ....then you simply parse response regarding filter needs...



    good luck!

Similar Threads

  1. Suppressing soap header in Axis2 client
    By MonsM in forum Advanced Java
    Replies: 1
    Last Post: 05-12-2011, 01:16 PM
  2. async client with Soap Header (jax-wsi 2.0)
    By micpie in forum Advanced Java
    Replies: 0
    Last Post: 01-25-2011, 01:36 PM
  3. SOAP RPC Java Client
    By _SolidSnake_ in forum Advanced Java
    Replies: 0
    Last Post: 01-19-2011, 11:00 AM
  4. SOAP Client
    By sathish_2111 in forum Advanced Java
    Replies: 2
    Last Post: 01-27-2010, 07:08 AM
  5. create a Java Client to consume WEBSERVICES XML SOAP
    By Felissa in forum Web Frameworks
    Replies: 2
    Last Post: 05-16-2008, 06:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •