Solved

Web Service Java help

Posted on 2004-04-26
7
444 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now