Solved

Web Service Java help

Posted on 2004-04-26
7
453 Views
Last Modified: 2011-10-03
How do I fix the i == 2 section?

package dii;

import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;
import java.io.*;
import java.lang.*;

public class TransactionClient {

      
    private static String qnameService = "TransactionService";
    private static String qnamePort = "TransactionIF";

    private static String BODY_NAMESPACE_VALUE = "urn:Foo";
    private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";

    public static void main(String[] args) {
            
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("1. Open Account");
            System.out.println("2. Deposit");
            System.out.println("3. Withdrawl");
            System.out.println("0. Exit");
            System.out.println("Selection: ");

            try {
            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(new QName(qnameService));

            QName port = new QName(qnamePort);

            Call call = service.createCall(port);
            call.setTargetEndpointAddress("http://152.15.21.56:8080/webservice/transaction");

            call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
            call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
            QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
                  QName QNAME_TYPE_DOUBLE = new QName(NS_XSD, "double");
                  QName QNAME_TYPE_INTEGER = new QName(NS_XSD, "int");
            call.setReturnType(QNAME_TYPE_STRING);
                  
                  int i;
                  while ( (i = Integer.parseInt(reader.readLine())) != 0)
                  {

                        if (i == 1)
                        {
                              System.out.println("Enter name: ");
                              String userName = reader.readLine();

                              System.out.println("Enter Deposit: ");
                              String initDeposit = reader.readLine();
                              
                              
                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "openAcct"));
                              call.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = new Object[2];
                              params[0] = userName;
                              params[1] = new Double(initDeposit);

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                        else if (i == 2)
                        {
                              System.out.println("Enter Account: ");
                              Object account = reader.readLine();
                              
                              System.out.println("Enter Deposit: ");
                              Object deposit = reader.readLine();
                              
                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "deposit"));
                              call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = { account, deposit };

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                        else if (i == 3)
                        {
                              System.out.println("Enter Account: ");
                              Object account = reader.readLine();
                              //int accountNum = Integer.parseInt(account);

                              System.out.println("Enter Withdrawl: ");
                              Object withdraw = reader.readLine();
                              //double withdrawCon = Double.parseDouble(withdraw);

                              call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "withdraw"));
                              call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                              call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                              Object[] params = { account, withdraw };

                              String result = (String)call.invoke(params);
                              System.out.println(result);
                        }
                  }
                reader.close();
                  System.exit(0);
            } catch      (Exception ex) {
            ex.printStackTrace();
        }
    }
}
0
Comment
Question by:Azrael37
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10916341
what exactly is the problem?
0
 
LVL 9

Accepted Solution

by:
mmuruganandam earned 500 total points
ID: 10916347
You have to create the object and then assign to the parameters.  I have had these kind of similar problems when i started off with the webservices.

The following should work...

>>  Object[] params = { account, deposit };


Object[] params = new Object[2];
params[0] = new Integer(account);
params[1] = new Double(deposit);

This would help... try this out...


Regards,
Muruga
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916359
even you have to do the same for i == 3 section too

Otherwise... that won't work too
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Azrael37
ID: 10916360
Just testing, and it worked.
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916364
change your i == 3 section too

it has the same problem
0
 
LVL 8

Expert Comment

by:william_jwd
ID: 10916375
try this,

else if (i == 2)
                   {
                         System.out.println("Enter Account: ");
                         String account = reader.readLine();
                         Integer intAccount = new Integer(account);
                         
                         System.out.println("Enter Deposit: ");
                         String deposit = reader.readLine();
                         Double dblDeposit = new Double(deposit);
                         
                         call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "deposit"));
                         call.addParameter("int_1", QNAME_TYPE_INTEGER, ParameterMode.IN);
                         call.addParameter("double_2", QNAME_TYPE_DOUBLE, ParameterMode.IN);
                         Object[] params = { intAccount, dblDeposit };

                         String result = (String)call.invoke(params);
                         System.out.println(result);
                    }
0
 
LVL 9

Expert Comment

by:mmuruganandam
ID: 10916381
easy points on my packet... thanx Azrael37.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 38
how to install java on RHEL image on EC2 4 30
login form jsp example 2 26
pagenation logic how it is working in my code 1 32
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question