I am trying to create a web app that is querying my oracle database and returns a list of menu titles from a table but when i navigate to the page it throws the area shown below.
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
oracle.DatabaseConnector.selectAllMenus(DatabaseConnector.java:63)
org.apache.jsp.menus_jsp._jspService(menus_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
Below is the offending part of the code inside my java class that queries the database. But i am not sure why this would cause the above error? Can someone take a look and see if there is a problem?
public MenuList selectAllMenus(String ordering) {
MenuList list = null;
try {
String strQuery = "SELECT title"
+ " FROM menus"
+ " ORDER BY " + ordering;
PreparedStatement stmt = conn.prepareStatement(strQuery);
results = stmt.executeQuery();
list = new MenuList(results);
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
This is what was in the log file:
28-Feb-2012 14:40:57 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at oracle.DatabaseConnector.selectAllMenus(DatabaseConnector.java:63)
at org.apache.jsp.menus_jsp._jspService(menus_jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Thread.java:662)
Hope you are using MySQL DB..
Make sure you add the correct MySQL Java Connector as an external library and also add Tomcat as an external server (In the Build Path of the Project in Eclipse).
(You can also copy all the libraries in the lib folder of your $TOMCAT_HOME/$CATALINA_HOME to your build path.
This should resolve this problem.
Thanks.
You can look in your logs : Apache Tomcat/6.0.35 logs
But the error message itself is pretty clear : The db connection is null, probably your connection string/parameters are incorrect.
I assume conn is open.
Instead of printing the stack trace, why don't you print the error message?
line:
PreparedStatement stmt = conn.prepareStatement(strQuery);
"conn" is not being created in any place
try something like this to create a connection:
public class MyConnection {
Connection conn;
String username;
String password;
public Connection getConnection(){
try {
String url = "jdbc:mysql://localhost/yourDBName?";
Class.forName("com.mysql.jdbc.Driver");
try {
conn = (Connection) DriverManager.getConnection(url,username,password);
} catch (Exception e) {
System.out.println(e);
}
} catch (SQLException e) {
System.out.println(e);
}
return conn;
}
}
Related
I don't understand why I am getting this error.. In my web application I have used many methods where I execute insert, select, update etc where all of them works correctly without errors... Now I want to implement a delete action. So, I have:
public void deleteBox(Label label)
throws SQLException, ClassNotFoundException {
System.out.println("Deleting box from BOXES");
sq = "DELETE FROM BOXES WHERE product=? AND version=? AND productionD=? AND AA=?";
try {
Class.forName(typeDB);
c = DriverManager.getConnection(path);
PreparedStatement stm = c.prepareStatement(sq);
stm.setString(1, label.getProduct());
stm.setString(2, label.getVersion());
stm.setString(3, label.getDateProduction());
stm.setString(4, label.getPacketNumber());
stm.executeUpdate();
} catch (SQLException e) {
System.out.println("hereeee error: " + e.getMessage());
e.printStackTrace();
} finally {
if (stm != null)
stm.close(); //<---
if (c != null)
c.close();
}
}
where path and typeDB are defined as:
private final String path = "jdbc:sqlite:C:\\DB_LABELS\\labels.sqlite";
private final String typeDB= "org.sqlite.JDBC";
and in the start of the class:
private Connection c = null;
PreparedStatement stm = null;
This method is called from the servlet here:
try{
Label box = (Label) session.getAttribute("boxFound");
action.deleteBox(box); //here I call the method
//some other stuff here..
action.addTransaction(box, "extract", timeStamp1, user.getId());
old = action.searchQuantityOfPackage(box);
}catch(SQLException | ClassNotFoundException e){
System.err.println("Exception at extract. More: " + e);
}
When it is executed I get an error:
Deleting box from BOXES
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
and all the other commands aren't executed inside the try. I don't understand why is this happening. As I said in the begging I use the same setting for other sql actions so both path and typeDB must be defined correctly. If I delete action.deleteBox(box); no error is happening, so sth is happening in this method...
ALSO
I forgot to mention that the delete of the row in the table BOXES is happening despite the error!
I add also the ful stack trace
Exception at extract. More: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (Connection is closed)
at org.sqlite.core.DB.newSQLException(DB.java:890)
at org.sqlite.core.CoreStatement.internalClose(CoreStatement.java:109)
at org.sqlite.jdbc3.JDBC3Statement.close(JDBC3Statement.java:35)
at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557)
at gr.products.labelInventory.Inventory.processRequest(Inventory.java:285)
at gr.products.labelInventory.Inventory.doGet(Inventory.java:652)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gr.products.labelInventory.LogFilter.doFilter(LogFilter.java:22)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:724)
this line at gr.products.labelInventory.ActionsDB.deleteBox(ActionsDB.java:557) points to the <-- i put in the code.
Following is my code. I am querying the user_group table and getting the result in a List. I want to iterate the List. But getting the exception as follows.
List<Group> list= empDAO.getStudentList();
for(Group o :list){
System.out.println("NAME :"+ o.getFirstName());
}
this is my DAO method
public List<Group> getStudentList() {
System.out.println("INSIDE DAO");
List<Group> groups = new ArrayList<Group>();
List<Group> rows = jdbcTemplate.queryForList("select * from user_group");
return rows;
}
Group.class
public class Group {
public Group() {
// TODO Auto-generated constructor stub
}
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
I am getting the following exception
Aug 3, 2012 9:22:47 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.common.form.Group
at com.common.controller.HelloWorldController.helloWorld(HelloWorldController.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Can anyone please tell how to fix this error?
The line jdbcTemplate.queryForList("select * from user_group"); is returning a list of HashMap, not a list of Group items (your IDE is probably showing a warning on that line).
You might want to read the Spring documentation about the jdbcTemplate and you might want to use a RowMapper to transform each row to a Group object.
I also think that you want to use the method jdbcTemplate.query(String sql, RowMapper rm) for your use case, check the javadoc.
jdbcTemplate.queryForList does not return a List<Group>, it has no idea what a Group is. It returns a List<Map<String,Object>>, a list of rows, each row a map from the column name to its value.
So do this:
for (Map<String,Object> m : jdbcTemplate.queryForList("select * from user_group")) {
for (Map.Entry<String,Object> e : m.entrySet()) {
String columnName = e.key;
Object columnValue = e.value;
...build a Group somehow?...
}
}
This is the error i get:
14:06:00,355 ERROR [JsonFilter] java.lang.NoSuchMethodException: byte.<init>(java.lang.String)
I have a basic upload form with an input file:
<form method='post' enctype='multipart/form-data'>
<table>
<input type='file' name='logo'>
</table>
</form>
When I submit, it calls a setter servlet, inside the servlet theres an extract() to get the data:
if (fileUp.getContent("compLogo") != null)
{
record.compLogo = fileUp.getContent("compLogo").getData();
} else
System.out.println("logo was null!");
return record;
But the thing, it throws that error before it even got the extact function, i've put many sysouts before it so i will know how the functions are moving around.
15:07:06,915 ERROR [JsonFilter] java.lang.NoSuchMethodException: byte.<init>(java.lang.String)
javax.servlet.ServletException: java.lang.NoSuchMethodException: byte.<init>(java.lang.String)
at com.pinksheets.common.web.req.HttpExtractor.getObject(HttpExtractor.java:160)
at com.pinksheets.common.web.req.HttpExtractor.extract(HttpExtractor.java:88)
at com.pinksheets.common.web.servlet.FetcherServlet.doGet(FetcherServlet.java:52)
at com.pinksheets.common.web.servlet.FetcherServlet.doPost(FetcherServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.pinksheets.common.web.filter.RoleAuthFilter.doFilter(RoleAuthFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.pinksheets.common.web.filter.UserAuthFilter.doFilter(UserAuthFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.pinksheets.common.web.filter.JsonFilter.doFilter(JsonFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.service.session.ClusteredSessionValve.handleRequest(ClusteredSessionValve.java:135)
at org.jboss.web.tomcat.service.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:94)
at org.jboss.web.tomcat.service.session.LockingValve.invoke(LockingValve.java:62)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: byte.<init>(java.lang.String)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at com.pinksheets.common.web.req.HttpExtractor.getObject(HttpExtractor.java:142)
... 37 more
this generates the html codes
EditSplashPageDOM.generate = function (value, callback)
{
var elem, output = document.createElement('form');
output.myValue = value;
output.myCallback = callback;
output.method = 'post';
output.enctype = 'multipart/form-data';
output.onsubmit = function(ev) { callback.handleSubmit(value, this); return false; };
output.appendChild(InputField.genHidden ('id', value.id));
output.appendChild(InputField.genHidden ('name', value.name));
var div, p;
output.appendChild(div = document.createElement('div'));
div.appendChild(p = document.createElement('p'));
p.innerHTML = 'The Splash Page list all the information for the current ad. You may update to change the Splash Page.<br /><span class="footnote">*The info shown are data of the latest ad and the proper format.*</span>';
var table = document.createElement('table');
output.appendChild(table);
table.className = 'detail';
this.createRow(table, 'Company Symbol', 'compSymbol', value.compSymbol, 100, 50);
this.createRow(table, 'Company Sec Id', 'secId', value.secId, 100, 50);
this.createFileRow(table, 'Company Logo', 'compLogo', 100, 47); //this is for input the file
row = table.insertRow (table.rows.length);
cell = row.insertCell(0);
cell.colSpan = 2;
cell.className = 'detailAction'
cell.appendChild(elem = InputField.genSubmit('Submit', 'Insert New Ad'));
return output;
}
this is the submit function
EditSplashPageSimple.prototype.handleSubmit = function(value, form)
{
value.compLogo = form.compLogo.value;
value.compPAL = form.compPAL.value;
value.compUrl = form.compUrl.value;
if(value.compLogo == null)
window.alert("comp logo is null");
else
window.alert("logo is " + value.compLogo);
var me = this;
me.caller.setSplashPage(value);
{
handleRequestData : function(status) {
window.alert('Splash Page is successfully updated with new company ' + value.compSymbol);
// me.callback.handleAddition(value);
},
handleRequestError : function(error) {
// Only deal with validation exceptions.
if (!error.isValidationException) {
window.alert('Sorry, there was an error while trying to add the new information. Please double check the data.');
throw error;
}
window.alert(error.message);
var e;
if (error.field && (e = form.elements[error.field])) {
window.alert('error.field error idk');
e.focus();
}
}
});
}
when submit itll call the servlet
System.out.println("now to extract the content of the file and set it to the logo var");
SplashPage record = (new SplashPageLogoAdapter(request)).extract();
the extract() is the same as i posted
It looks like this com.pinksheets API is assuming a class that it encounters at some point is going to have a constructor that takes a String; when it finds that the class in question is byte (i.e., java.lang.Byte.TYPE, which has no such constructor) you're getting an exception.
I'd want to have a look at the source for com.pinksheets.common.web.req.HttpExtractor.getObject(); that's where you're going to see what's going on.
I am trying to get simple user Details (Name,Phone No, Gender(Option Box)) in an Applet and display the details in an JSP.I put all the three details in an HashMap and send it in a output Stream. The Applet Code is as Follows.
try
{
userUrl = "http://localhost:8080/AppletTest/display.jsp";
/* In the web.xml file I have mapped display.jsp to the Servlet */
testServlet = new URL(userUrl.toString());
servletConnection = testServlet.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
ObjectOutputStream oos1 = new ObjectOutputStream(servletConnection.getOutputStream());
/* DataMap is the HashMap Containing values */
oos1.writeObject(dataMap);
oos1.flush();
oos1.close();
// Thread.currentThread().sleep(5000);
}
catch(Exception ie)
{
ie.printStackTrace();
}
// Finally call servlet by going to that page.
getAppletContext().showDocument(userUrl, "_self");
While on a servlet i just get the HashMap and forward it to a jsp page to display.
try
{
System.out.println("In Servlet");
ObjectInputStream inputFromApplet = new ObjectInputStream(request.getInputStream());
HashMap<String,String> receievedData = (HashMap<String,String>) inputFromApplet.readObject();
request.setAttribute("dataMap",receievedData);
request.getRequestDispatcher("display1.jsp").forward(request, response);
inputFromApplet.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
As asked in the comments in The Question here ,The Sysout("In Servlet") is printed. But an Exception is thrown
In Servlet
SEVERE: Servlet.service() for servlet jsp threw exception java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream. java:2749)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
at org.apache.jsp.display1_jsp._jspService(display1_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
What am I doing wrong. Please Help.
If I understand correctly you are :
sending a request to the servlet
reading from e input stream of that call
sending a jsp as the response to THAT call
redirecting the user from the applet to that same servlet
this causes a SECOND request, without anything serialized in it
the servlet fails on this second request
This unfortunately canno work. You should use two servlets (or the same one with an optional parameter) to handle the two requests, one will read from the input stream, and write to the session, while the second will retrive from the session and display in a jsp.
I suspect an exception is being thrown by the applet and you haven't detected it in the Java Console yet.
I am having problems connecting to gtalk/facebook server from behind a proxy .In my loginservlet under doPost I specify the proxy settings before making a connection with the servers.The code is as follows:
package web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.proxy.ProxyInfo;
import dao.MySASLDigestMD5Mechanism;
public class LoginFacebookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LoginFacebookServlet() {
super();
}
XMPPConnection connection;
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userName = request.getParameter("usrnm_fb");
String password = request.getParameter("password_fb");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
SASLAuthentication.registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism.class);
//SASLAuthentication.supportSASLMechanism("DIGEST-MD5", 0);
ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.HTTP,"proxy.xxx.com" "talk.google.com", port, "username", "password");
ConnectionConfiguration config = new ConnectionConfiguration("chat.facebook.com",5222,proxyInfo);
connection = new XMPPConnection(config);
config.setSASLAuthenticationEnabled(true);
try {
connection.connect();
} catch (XMPPException e) {
e.printStackTrace();
}
try {
connection.login(userName, password);
} catch (XMPPException e) {
e.printStackTrace();
}
System.out.println(connection.isAuthenticated());
// System.out.println("Welcome!!you are now connected to facebook");
}
}
When I run the application it still gives me 500 status error.Following is the stack trace
XMPPError connecting to chat.facebook.com:5222.: remote-server-error(502) XMPPError connecting to chat.facebook.com:5222.
-- caused by: java.net.ConnectException: Connection timed out: connect
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:900)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1415)
at web.LoginFacebookServlet.doPost(LoginFacebookServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Nested Exception:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at org.jivesoftware.smack.proxy.DirectSocketFactory.createSocket(DirectSocketFactory.java:28)
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:888)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:1415)
at web.LoginFacebookServlet.doPost(LoginFacebookServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Apr 26, 2011 11:32:24 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet LoginFacebookServlet threw exception
java.lang.IllegalStateException: Not connected to server.
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:382)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:349)
at web.LoginFacebookServlet.doPost(LoginFacebookServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
I checked to see if any thing more was there to add for by passing proxy but am unable to understand as to where am I going wrong?
Thanks:)
XMPP != HTTP so there's no reason to expect that an HTTP proxy will be used by an XMPP client. However, it seems like Smack has added HTTP proxy support (in addition to SOCKS4 and SOCKS5 proxy support they had earlier). The ConnectionConfiguration can accept a ProxyInfo parameter.
As far as I can tell from the JavaDocs, this is what you need to do:
ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.HTTP, "proxy.xxx.com", 8080, "username", "password")
ConnectionConfiguration config = new ConnectionConfiguration("facebook.com", 5222, proxyInfo);
XMPPConnection conn = new XMPPConnection(config);
conn.connect();
Also, for future questions, please note
Although your question is tagged 'Smack' you posted no Smack specific code. The lines showing use of the URLConnection are pointless since that's not where your connection is failing.
Your question title indicates Google Talk, however everything else refers to Facebook. This is confusing and unclear questions or code that is NOT what you're actually working with will most likely lead to frustration for you and other members. As far as possible, you should post an SSCCE.