Im new to ofbiz.So is my question is have any mistake forgive me for my mistakes.Im new to ofbiz so i did not know some terminologies in ofbiz.Sometimes my question is not clear because of lack of knowledge in ofbiz.So try to understand my question and give me a good solution with respect to my level.Because some solutions are in very high level cannot able to understand for me.So please give the solution with good examples.
My project namely "productionmgntSystem" is in "ofbiz/hot-deploy" folder.In my project i had a file namely "app_details_1.ftl" with the following codings
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!--<meta http-equiv="Content-Type" content="multipart/form-data; charset=ISO-8859-1">-->
<title>Insert title here</title>
<script TYPE="TEXT/JAVASCRIPT" language=""JAVASCRIPT">
function uploadFile()
{
//alert("Before calling upload.jsp");
window.location='<@ofbizUrl>testing_service1</@ofbizUrl>'
}
function logout1()
{
//alert("Logout1");
alert("<@ofbizUrl>logout1</@ofbizUrl>");
window.location='<@ofbizUrl>logout1</@ofbizUrl>'
}
</script>
</head>
<!-- <form action="<@ofbizUrl>testing_service1</@ofbizUrl>" enctype="multipart/form-data" name="app_details_frm"> -->
<form enctype="multipart/form-data" action="<@ofbizUrl>uploadAttachFile</@ofbizUrl>" METHOD=POST>
<center style="height: 299px; ">
<table border="0" style="height: 177px; width: 788px">
<tr style="height: 115px; ">
<td style="width: 103px; ">
<td style="width: 413px; "><h1>APPLICATION DETAILS</h1>
<td style="width: 55px; ">
</tr>
<tr>
<td style="width: 125px; ">Application name : </td>
<td>
<input name="app_name_txt" id="txt_1" value=" " />
</td>
</tr>
<tr>
<td style="width: 125px; ">Excell sheet : </td>
<td>
<input type="file" name="filename"/>
</td>
</tr>
<tr>
<td>
<input type="button" name="logout1_cmd" value="Logout" onclick="logout1()"/>
<!-- <input type="submit" name="logout_cmd" value="logout"/>-->
</td>
<td>
<input type="submit" name="upload_cmd" value="UPLOAD" />
<!-- <input type="button" name="upload1_cmd" value="Upload" onclick="uploadFile()"/> -->
</td>
</tr>
</table>
</center>
</form>
</html>
the following are the some of the coding present in the "controller.xml" file
..........
..........
...........
<request-map uri="uploadAttachFile">
<security https="true" auth="true"/>
<!-- <event type="simple" invoke="createCommunicationContent" path="component://productionmgntSystem/script/org/ofbiz/productionmgntSystem/CommunicationEventEvents.xml"/> -->
<event type="java" path="org.ofbiz.productionmgntSystem.web_app_req.Uploading" invoke="uploadFile"/>
<response name="AttachementSuccess" type="view" value="AttachementSuccess"/>
<response name="AttachementException" type="view" value="AttachementException"/>
</request-map>
...............
...........
............
<!-- I DEFINED - START -->
<view-map name="AttachmentError" type="ftl" page="file_attach_error.ftl"/>
<view-map name="AttachementException" type="ftl" page="file_attach_error.ftl"/>
<view-map name="AttachementSuccess" type="ftl" page="AttachementSuccess.ftl"/>
<!-- I DEFINED - END -->
...............
...............
.............
The following are the coding in the file "AttachementSuccess.ftl"
<html>
<head>
<title>FILE ATTACH SUCCESS</title>
</head>
<form action="<@ofbizUrl>logout1</@ofbizUrl>" enctype="multipart/form-data" name="file_attach_error_frm">
<table>
<tr>
<td>
<td>
<td>
</tr>
<tr>
<td>
<td>File attachement success</td>
<td>
</tr>
<tr>
<td>
<td><input type="submit" value="LOGOUT"/></td>
<td>
</tr>
</table>
</form>
</html>
The following are the coding present in the file "file_attach_error.ftl"
<html>
<head>
<title>FILE ATTACH ERROR</title>
</head>
<form action="<@ofbizUrl>logout1</@ofbizUrl>" enctype="multipart/form-data" name="file_attach_error_frm">
<table>
<tr>
<td>
<td>
<td>
</tr>
<tr>
<td>
<td>File attachement error</td>
<td>
</tr>
<tr>
<td>
<td><input type="submit" value="LOGOUT"/></td>
<td>
</tr>
</table>
</form>
</html>
the following are the coding inside the file "Uploading.java"
//UPLOADING A CONTENT TO THE SERVER
package org.ofbiz.productionmgntSystem.web_app_req;
import java.io.File;
import java.nio.ByteBuffer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.ofbiz.service.ServiceUtil;
import java.util.List;
public class Uploading
{
public static String uploadFile(HttpServletRequest request,HttpServletResponse response)
{
//ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory(10240, new File(new File("runtime"), "tmp"))); //Creation of servletfileupload
System.out.println("\n\n\t****************************************\n\tuploadFile(HttpServletRequest request,HttpServletResponse response) - start\n\t");
ServletFileUpload fu = new ServletFileUpload(new DiskFileItemFactory()); //Creation of servletfileupload
java.util.List lst = null;
String result="AttachementException";
try
{
lst = fu.parseRequest(request);
}
catch (FileUploadException fup_ex)
{
System.out.println("\n\n\t****************************************\n\tException of FileUploadException \n\t");
fup_ex.printStackTrace();
result="AttachementException";
return(result);
}
if(lst.size()==0) //There is no item in lst
{
System.out.println("\n\n\t****************************************\n\tLst count is 0 \n\t");
result="AttachementException";
return(result);
}
FileItem file_item = null;
FileItem selected_file_item=null;
//Checking for form fields - Start
for (int i=0; i < lst.size(); i++)
{
file_item=(FileItem)lst.get(i);
String fieldName = file_item.getFieldName();
//Check for the attributes for user selected file - Start
if(fieldName.equals("filename"))
{
selected_file_item=file_item;
break;
}
//Check for the attributes for user selected file - End
}
//Checking for form fields - End
//Uploading the file content - Start
if(selected_file_item==null) //If selected file item is null
{
System.out.println("\n\n\t****************************************\n\tThe selected file item is null\n\t");
result="AttachementException";
return(result);
}
byte[] file_bytes=selected_file_item.get();
ByteBuffer byteWrap=ByteBuffer.wrap(file_bytes);
byte[] extract_bytes=null;
byteWrap.get(extract_bytes);
System.out.println("\n\n\t****************************************\n\tExtract succeeded :content are : \n\t");
if(extract_bytes==null)
{
System.out.println("\n\n\t****************************************\n\tExtract bytes is null\n\t");
result="AttachementException";
return(result);
}
for(int k=0;k<extract_bytes.length;k++)
System.out.print((char)extract_bytes[k]);
System.out.println("\n\n\t****************************************\n\tuploadFile(HttpServletRequest request,HttpServletResponse response) - end\n\t");
return("AttachementSuccess");
//Uploading the file content - End
}
}
I want to upload a file into the server using " tag.When i execute the application the following error is shown in browser.
The following are the stackTrace print in the console
[java] 2010-12-29 10:56:38,336 (http-0.0.0.0-443-1) [ JavaEventHandler.ja
va:100:ERROR]
[java] ---- runtime exception report --------------------------------------
------------
[java] Problems Processing Event
[java] Exception: java.lang.NullPointerException
[java] Message: null
[java] ---- stack trace ---------------------------------------------------
------------
[java] java.lang.NullPointerException
[java] java.nio.ByteBuffer.get(ByteBuffer.java:675)
[java] org.ofbiz.productionmgntSystem.web_app_req.Uploading.uploadFile(Uplo
ading.java:76)
[java] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
.java:39)
[java] sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.java:25)
[java] java.lang.reflect.Method.invoke(Method.java:597)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java
:92)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java
:78)
[java] org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java
:592)
[java] org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.jav
a:361)
[java] org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:20
2)
[java] org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:7
8)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:290)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:206)
[java] org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:2
59)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:235)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:206)
[java] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
Valve.java:233)
[java] org.apache.catalina.core.StandardContextValve.invoke(StandardContext
Valve.java:175)
[java] org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
java:128)
[java] org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
java:102)
[java] org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
lve.java:109)
[java] org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java
:568)
[java] org.ofbiz.catalina.container.CrossSubdomainSessionValve.invoke(Cross
SubdomainSessionValve.java:62)
[java] org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.ja
va:286)
[java] org.apache.coyote.http11.Http11Processor.process(Http11Processor.jav
a:844)
[java] org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proc
ess(Http11Protocol.java:583)
[java] org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:4
47)
[java] java.lang.Thread.run(Thread.java:619)
[java] --------------------------------------------------------------------
------------
[java]
[java] 2010-12-29 10:56:38,336 (http-0.0.0.0-443-1) [ ControlServlet.ja
va:205:ERROR]
[java] ---- exception report ----------------------------------------------
------------
[java] Error in request handler:
[java] Exception: org.ofbiz.webapp.event.EventHandlerException
[java] Message: Problems processing event: java.lang.NullPointerException (
null)
[java] ---- cause ---------------------------------------------------------
------------
[java] Exception: java.lang.NullPointerException
[java] Message: null
[java] ---- stack trace ---------------------------------------------------
------------
[java] java.lang.NullPointerException
[java] java.nio.ByteBuffer.get(ByteBuffer.java:675)
[java] org.ofbiz.productionmgntSystem.web_app_req.Uploading.uploadFile(Uplo
ading.java:76)
[java] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
.java:39)
[java] sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.java:25)
[java] java.lang.reflect.Method.invoke(Method.java:597)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java
:92)
[java] org.ofbiz.webapp.event.JavaEventHandler.invoke(JavaEventHandler.java
:78)
[java] org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java
:592)
[java] org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.jav
a:361)
[java] org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:20
2)
[java] org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:7
8)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
[java] javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:290)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:206)
[java] org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:2
59)
[java] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:235)
[java] org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:206)
[java] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
Valve.java:233)
[java] org.apache.catalina.core.StandardContextValve.invoke(StandardContext
Valve.java:175)
[java] org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
java:128)
[java] org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
java:102)
[java] org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
lve.java:109)
[java] org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java
:568)
[java] org.ofbiz.catalina.container.CrossSubdomainSessionValve.invoke(Cross
SubdomainSessionValve.java:62)
[java] org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.ja
va:286)
[java] org.apache.coyote.http11.Http11Processor.process(Http11Processor.jav
a:844)
[java] org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proc
ess(Http11Protocol.java:583)
[java] org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:4
47)
[java] java.lang.Thread.run(Thread.java:619)
[java] --------------------------------------------------------------------
------------
[java]
[java] 2010-12-29 10:56:38,336 (http-0.0.0.0-443-1) [ ControlServlet.ja
va:221:ERROR] An error occurred, going to the errorPage: /error/error.jsp
[java] 2010-12-29 10:56:38,351 (http-0.0.0.0-443-1) [ ControlServlet.ja
va:228:ERROR] Including errorPage: /error/error.jsp
[java] 2010-12-29 10:56:38,367 (http-0.0.0.0-443-1) [ ControlServlet.ja
va:302:INFO ] [[[uploadAttachFile] Request Done- total:0.063,since last([uploadA
ttachFile...):0.063]]
I cannot able to solve the issue.So please help me to solve the issue.
Thanks & Regards, Sivakumar.J
In Uploading.uploadFile()
method there are two lines (near the end) like this:
byte[] extract_bytes=null;
byteWrap.get(extract_bytes);
Because you are passing a null
array to get()
method you are getting a NullPointerException
.