File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Illegal Argument Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Illegal Argument Exception" Watch "Illegal Argument Exception" New topic
Author

Illegal Argument Exception

Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
Hi All,

I am trying to figure this out. From my html form I call a servlet. In the servlet I am doing req.getParameter("name"), which I am passing thru the form. I am also checking to see if req.getParameter("name") is null or the length is 0. But it is giving me IllegalArgumentException at HttpUtils.parseQueryString. Can somebody explain to me as to what are the possible cause for getting this exception.

TIA
khudiram Barik
Greenhorn

Joined: Feb 12, 2001
Posts: 17
How is your servlet called ( get or post ?). Paste the code where you are in doubt of getting error.
Thanks.
Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
its using doPost
khudiram Barik
Greenhorn

Joined: Feb 12, 2001
Posts: 17
Please paste the code ,
Note:--- req.getParameter("name") does not through any exception. It's somewhere else you are trying to do something else.
Thanks.
Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
and also I went inside the HttpUtils class and changed the parseQueryString to display more information, but it is not working. Is it that I can not change the standard classes in Java? The above mentioned method throws IllegalArgumentException(), what I wanted was to throw IllegalArgumentException(s), so that I can see what is the value of String s.

Any hints
Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
This is the line no 49 in my code AddReseller.java

String rsCoCode = req.getParameter("name");
And this is the exception being thrown

java.lang.IllegalArgumentException
at javax.servlet.http.HttpUtils.parseQueryString(HttpUtils.java)
at javax.servlet.http.HttpUtils.parsePostData(HttpUtils.java)
at org.apache.tomcat.util.RequestUtil.readFormData(RequestUtil.java)
at org.apache.tomcat.core.RequestImpl.handleParameters(RequestImpl.java)
at org.apache.tomcat.core.RequestImpl.getParameterValues(RequestImpl.java)
at org.apache.tomcat.core.RequestImpl.getParameter(RequestImpl.java)
at org.apache.tomcat.facade.HttpServletRequestFacade.getParameter(HttpServletRequestFacade.java)
at epoch.servlets.AddReseller.doPost(AddReseller.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java)
at org.apache.tomcat.core.Handler.service(Handler.java)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java)
at org.apache.tomcat.service.connector.Ajp13ConnectionHandler.processConnection(Ajp13ConnectionHandler.java)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java)
at java.lang.Thread.run(Thread.java:484)
khudiram Barik
Greenhorn

Joined: Feb 12, 2001
Posts: 17
To my knowledge the single line you have shown does not look to have any problem. It is very difficult to know or assume the rest of your code unless we see that. Always entire code helps very much for other to understand. If you are concerned about that, it's OK.
Hope you understand.
Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
hi Khudiram,

The entire code is too lengthy and it contains company specific info, but here it is

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {

// Go with single database connection instead of pooling
DB m_db = null;
PrintWriter out = null;
HttpSession session = null;

try {

res.setContentType("text/html");
//out = res.getWriter();
out = new PrintWriter(res.getOutputStream(),true);

// Get the ip to use in logging (Joel 1/26/2000)
String ipAddress = req.getRemoteAddr();
// Get all the form information
String rsCoCode = req.getParameter("name");
String username = req.getParameter("username");
String password = req.getParameter("password");
String rsCode = req.getParameter("rs_code");
String rsName = req.getParameter("rs_name");
String rsContact = req.getParameter("rs_contact");
String rsEmail = req.getParameter("rs_email");
String rsStreet = req.getParameter("rs_street");
String rsCity = req.getParameter("rs_city");
String rsState = req.getParameter("rs_state");
String rsZip = req.getParameter("rs_zip");
String rsCountry = req.getParameter("rs_country");
String rsPhone = req.getParameter("rs_phone");
String rsPassword = req.getParameter("rs_password");
String rsPaymethod = req.getParameter("rs_paymethod");
String rsPercentage = req.getParameter("rs_percentage");
String rsTaxId = req.getParameter("rs_taxid");



if ( isResellerAbuse( rsCoCode ) ) {
try{Thread.sleep(10000);}catch(Exception e){}
System.err.println("Company blocked from adding resellers until cycle. " + rsCoCode + " IP: " + ipAddress);
return;
}

// Use the info from their session object, if it exists
session = req.getSession(false);
if ( session != null ) {
if ( rsCoCode == null ) rsCoCode = (String)session.getValue("name");
if ( username == null ) username = (String)session.getValue("username");
if ( password == null ) password = (String)session.getValue("password");
}

// Get rid of all leading and trailing whitespace
Perl5Util perl = new Perl5Util();
if ( rsCode != null ) rsCode = rsCode.trim();
if ( rsCoCode != null ) rsCoCode = rsCoCode.trim();
if ( rsName != null ) rsName = rsName.trim();
if ( rsContact != null ) rsContact = rsContact.trim();
if ( rsEmail != null ) rsEmail = rsEmail.trim();
if ( rsStreet != null ) rsStreet = rsStreet.trim();
if ( rsCity != null ) rsCity = rsCity.trim();
if ( rsState != null ) rsState = rsState.trim();
if ( rsCountry != null ) rsCountry = rsCountry.trim();
if ( rsZip != null ) rsZip = rsZip.trim();
if ( rsPhone != null ) rsPhone = rsPhone.trim();
if ( rsPassword != null ) rsPassword = rsPassword.trim();
if ( rsPaymethod != null ) rsPaymethod = rsPaymethod.trim();
if ( rsPercentage != null ) rsPercentage = rsPercentage.trim();
if ( rsTaxId != null ) rsTaxId = rsTaxId.trim();

// Give an error if they enter "a" for the reseller code
// ("a" is default for the company itself - Joel 10/16/2000)
if ( "a".equals(rsCode) ) {
out.println( ReportUtils.getErrorHTML(
"Add Reseller Error!",
"Reseller code \"a\" is already taken.") );
return;
}

// Give an error if username or password is missing
if ( username == null | | username.length() < 1 | |
password == null | | password.length() < 1 ) {

out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"Your username and password information is missing in this request."));
System.err.println("Add Reseller MISSING USER/PASS: " + rsCoCode+": "+rsCode+
": "+rsName+": "+rsContact + " IP: " + ipAddress);
return;
}

// Check their username and password
String compCode = CheckLogin.checkMerchant(username, password);
if ( compCode == null | | !compCode.equals(rsCoCode) ) {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"The Username and Password you have supplied are not correct."));
System.err.println("Add Reseller INCORRECT USER/PASS: " + rsCoCode+": "+rsCode+": "+
rsName+": "+rsContact + " IP: " + ipAddress);
return;
}

// Test for all required fields
if ( rsCode == null | | rsCode.length() < 1 | |
rsName == null | | rsName.length() < 1 | |
rsContact == null | | rsContact.length() < 1 | |
rsEmail == null | | rsEmail.length() < 1 | |
rsPassword == null | | rsPassword.length() < 1 | |
rsPercentage == null | | rsPercentage.length() < 1 | |
rsPaymethod == null | | rsPaymethod.length() < 1 ) {

out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"You must fill in all required fields."));
System.err.println("Add Reseller MISSING REQUIRED FIELDS: " +
rsCoCode+": "+rsCode+": "+rsName+": "+rsContact + " IP: " + ipAddress);
incrementMissingFieldCount( rsCoCode );
return;
}

// Test for all the other fields if this is a paymethod = Epoch
// Also make sure rsPaymethod is either "chk" or "man" -- the only valid values
if ( rsPaymethod.equals("chk") ) {
if ( rsStreet == null | | rsStreet.length() < 1 | |
rsCity == null | | rsCity.length() < 1 | |
rsState == null | | rsState.length() < 1 | |
rsZip == null | | rsZip.length() < 1 | |
rsCountry == null | | rsCountry.length() < 1 | |
rsPhone == null | | rsPhone.length() < 1 | |
rsTaxId == null | | rsTaxId.length() < 1 ) {

out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"If the Payment Method is set to Epoch, all fields must be filled in."));
System.err.println("Add Reseller MISSING PAYMENT FIELDS: " +
rsCoCode+": "+rsCode+": "+rsName+": "+rsContact + " IP: " + ipAddress);
return;
}
}
else if ( !rsPaymethod.equals("man") ) {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"The Payment Method supplied is not valid."));
System.err.println("Add Reseller INVALID PAYMENT METHOD: " + rsCoCode+": "+rsCode+": "+rsName+": "+rsContact);
return;
}

// Make sure the percentage field is numeric and between 0 and 100
if ( perl.match("/\\D/", rsPercentage) ) {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"The Reseller Split field must contain numbers only."));
System.err.println("Add Reseller BAD RESELLER SPLIT(num only): " +
rsCoCode+": "+rsCode+": "+rsName+": "+rsContact);
return;
}
else {
Integer iPercentage = new Integer(rsPercentage);
if ( iPercentage.intValue() > 100 | | iPercentage.intValue() < 0 ) {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"The Reseller Split field must be a number between 0 and 100."));
System.err.println("Add Reseller BAD RESELLER SPLIT(0-100): " +
rsCoCode+": "+rsCode+": "+rsName+": "+rsContact);
return;
}
}

// Make sure that this reseller code is unique for this merchant in the database
m_db = new DB();
Hashtable hash = null;
String sqlSelect = "p_getResellerInfo '" + rsCode + "', '" + rsCoCode + "'";

hash = m_db.doQueryOneRow(sqlSelect);
if ( hash != null ) {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"A reseller already exists with this reseller code. Please choose a different reseller code."));
System.err.println("Add Reseller RESELLER ALREADY EXISTS: " +
rsCoCode+": "+rsCode+": "+rsName+": "+rsContact + " IP: " + ipAddress);
return;
}

// Manipulate all the posted information so it fits the database.
rsCode = perl.substitute("s/'/''/g", rsCode);
rsCoCode = perl.substitute("s/'/''/g", rsCoCode);
rsName = perl.substitute("s/'/''/g", rsName);
rsContact = perl.substitute("s/'/''/g", rsContact);
rsEmail = perl.substitute("s/'//g", rsEmail);
rsEmail = perl.substitute("s/ //g", rsEmail);
rsEmail = perl.substitute("s/\\,/./g", rsEmail); // for compuserve idiots that put a comma instead of a dot rsStreet = perl.substitute("s/'/''/g", rsStreet);
rsStreet = perl.substitute("s/'/''/g", rsStreet);
rsCity = perl.substitute("s/'/''/g", rsCity);
rsState = perl.substitute("s/'/''/g", rsState);
rsCountry = perl.substitute("s/'/''/g", rsCountry);
rsZip = perl.substitute("s/'/''/g", rsZip);
rsPhone = perl.substitute("s/'/''/g", rsPhone);
rsPassword = perl.substitute("s/'/''/g", rsPassword);
rsPaymethod = perl.substitute("s/'/''/g", rsPaymethod);
rsPercentage = perl.substitute("s/'/''/g", rsPercentage);
rsTaxId = perl.substitute("s/'/''/g", rsTaxId);

String sqlInsert = "INSERT INTO Reseller (rs_code, rs_co_code, rs_name, rs_contact, rs_email, " +
"rs_street, rs_city, rs_state, rs_country, rs_zip, " +
"rs_phone, rs_password, rs_paymethod, rs_percentage, " +
"rs_taxid) " +
"VALUES ('" + rsCode + "', '" + rsCoCode + "', '" + rsName + "', '" + rsContact +
"', '" + rsEmail + "', '" + rsStreet + "', '" + rsCity + "', '" + rsState +
"', '" + rsCountry + "', '" + rsZip + "', '" + rsPhone + "', '" + rsPassword +
"', '" + rsPaymethod + "', " + rsPercentage + ", '" + rsTaxId + "')";

if ( m_db.doSQL(sqlInsert) ) {

// Now retrieve all the current information and print it out.
hash = null;
hash = m_db.doQueryOneRow(sqlSelect);

// Sleep to prevent from getting hammered
try { Thread.sleep(5000); } catch ( Exception e ) {}

out.println(ReportUtils.getAddSuccessHTML(res, hash));
System.err.println("Add Reseller SUCCESSFULLY ADDED: " + rsCoCode+": "+rsCode+": "+rsName+": "+rsContact);
return;
}
else {
out.println(ReportUtils.getErrorHTML(
"Add Reseller Error!",
"Unable to add this record to the database. If this error continues " +
"to occur, please contact Epoch Transaction Services.<br><br>" +
m_db.getError()));
System.err.println("Add Reseller UNABLE TO ADD TO DB: " + rsCoCode+": "+rsCode+": "+rsName+": "+rsContact);
return;
}
}
catch ( Exception e ) {
e.printStackTrace();
}
finally {
if ( m_db != null ) m_db.Close();
}
}


khudiram Barik
Greenhorn

Joined: Feb 12, 2001
Posts: 17
That's enough, now I can suggest the following:---
Put a System.out.println surrounding the line 49 ( where you have doubt)
System.out.println("Before this Line");
Line 49's code
System.out.println("After this Line");
and rerun and see if you have pointed out the error line correctly. If so let me know I will do some more research to help you.
Because those lines are simple req.getParameter("") lines and can not have error.
By doing so you can track down the error line correctly.
Thanks.

Vedprakash Pathak
Greenhorn

Joined: Mar 06, 2001
Posts: 24
I did a try catch block for that line and it gave me IllegalArgument Exception.
khudiram Barik
Greenhorn

Joined: Feb 12, 2001
Posts: 17
You have mentioned earlier that you changed HttpUtils's parseQueryString method, what change you made ? Can you change it back ?
Second does name parameter contains a '&' character in the form ?
I mean what value you enter in the screen ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal Argument Exception
 
Similar Threads
A null pointer that I dont quite understand
JDBC code with type 1 driver not working
about hidden from fields
Uploading a file?
Servlet Request (Integer)