Well, I'm still having problems and the code won't deploy and I still get the HTTP 503 error.
Here are exactly the files I have as follows:
1)
Java source code - "<my_project>/src/java/com/csharp/MyBean.java":
package com.csharp;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.*;
public class MyBean {
private UploadedFile myFile;
private
String myParam;
private String myResult;
public UploadedFile getMyFile() {
return myFile;
}
public void setMyFile(UploadedFile myFile) {
this.myFile = myFile;
}
public String getMyParam() {
return myParam;
}
public void setMyParam(String myParam) {
this.myParam = myParam;
}
public String getMyResult() {
return myResult;
}
public void setMyResult(String myResult) {
this.myResult = myResult;
}
public String processMyFile() {
try {
MessageDigest md
= MessageDigest.getInstance(myParam);
InputStream in = new BufferedInputStream(
myFile.getInputStream());
try {
byte[] buffer = new byte[64 * 1024];
int count;
while ((count = in.read(buffer)) > 0)
md.update(buffer, 0, count);
} finally {
in.close();
}
byte hash[] = md.digest();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < hash.length; i++) {
int b = hash[i] & 0xFF;
int c = (b >> 4) & 0xF;
c = c < 10 ? '0' + c : 'A' + c - 10;
buf.append((char) c);
c = b & 0xF;
c = c < 10 ? '0' + c : 'A' + c - 10;
buf.append((char) c);
}
myResult = buf.toString();
return "OK";
} catch (Exception x) {
FacesMessage message = new FacesMessage(
FacesMessage.SEVERITY_FATAL,
x.getClass().getName(), x.getMessage());
FacesContext.getCurrentInstance().addMessage(
null, message);
return null;
}
}
}
After copying the jar files, including tomahawk-1.1.6.jar into "<my_project>/web/WEB-INF/lib/" then compiling, I create the class file without errors in "<my_project>/web/WEB-INF/classes/com/csharp/".
Then we have the HTML/JSP files.
2) HTML start file - "<my_project>/web/index.html":
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Refresh" content= "0; URL=index.faces"/>
<title>Start Web Application</title>
</head>
<body>
<p>Please wait for the web application to start.</p>
</body>
</html>
This just redirects to index.jsp, which I added and use as recommended in "Core JavaServer Faces".
3) JSP start file - "<my_project>/web/index.jsp":
<jsp:forward page="MyForm.faces"/>
This is just one line and is the start point from the code taken from the "onjava" reference mentioned earlier. In a real application this is redundant.
4) JSP MyForm page - "<my_project>/web/MyForm.jsp" which is where the real display is supposed to start:
<%@ page contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<f:view>
<html>
<head>
<title>
Test 2 of Uploading Files</title>
</head>
<body>
<h:form id="MyForm" enctype="multipart/form-data" >
<h:messages globalOnly="true" styleClass="message"/>
<h:panelGrid columns="3" border="0" cellspacing="5">
<h:outputLabel for="myFileId" value="File: "/>
<x:inputFileUpload id="myFileId"
value="#{myBean.myFile}"
storage="file"
required="true"/>
<h:message for="myFileId"/>
<h:outputLabel for="myParamId" value="Param: "/>
<h:selectOneMenu id="myParamId"
value="#{myBean.myParam}"
required="true">
<f:selectItem itemLabel="" itemValue=""/>
<f:selectItem itemLabel="MD5" itemValue="MD5"/>
<f:selectItem itemLabel="SHA-1" itemValue="SHA-1"/>
<f:selectItem itemLabel="SHA-256" itemValue="SHA-256"/>
<f:selectItem itemLabel="SHA-384" itemValue="SHA-384"/>
<f:selectItem itemLabel="SHA-512" itemValue="SHA-512"/>
</h:selectOneMenu>
<h:message for="myParamId"/>
<h:outputText value=" "/>
<h:commandButton value="Submit"
action="#{myBean.processMyFile}"/>
<h:outputText value=" "/>
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>
5) JSP MyResults page - "<my_project>/web/MyResult.jsp":
<%@ page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<html>
<head>
<title>Test 2 of Uploading Files Results Page</title>
</head>
<body>
<h:panelGrid columns="2" border="0" cellspacing="5">
<h:outputText value="File Name:"/>
<h:outputText value="#{myBean.myFile.name}"/>
<h:outputText value="File Size:"/>
<h:outputText value="#{myBean.myFile.size}"/>
<h:outputText value="Param:"/>
<h:outputText value="#{myBean.myParam}"/>
<h:outputText value="Result:"/>
<h:outputText value="#{myBean.myResult}"/>
</h:panelGrid>
</body>
</html>
</f:view>
Now we have the XML files, which is presumably where I am having the problemss:
6) web.xml file - "<my_project>/web/WEB-INF/web.xml":
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
<!--<description>Set the size limit for uploaded files.
Format: 10 - 10 bytes
10k - 10 KB
10m - 10 MB
1g - 1 GB
</description>-->
</init-param>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
</web-app>
On attempting to deploy, the <description> tag generated an error, as apparently it was not recognised, so I commented it out and continued.
7) faces-config.xml file "<my_project>/web/WEB-INF/faces-config.xml":
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd" version="1.2">
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>com.csharp.MyBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/MyForm.jsp</from-view-id>
<navigation-case>
<from-outcome>OK</from-outcome>
<to-view-id>/MyResult.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
After deployment I get the HTTP Status 503 error, followed by this blurb in the log:
Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.<clinit>(ExtensionsPhaseListener.java:49) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at..........
Obviously something is not working properly, and it must have something to do with one or both xml files.
Sorry for cluttering up my posting with all that code, but this has been bugging me for some time, and I think that the best way of getting some help is to show exactly what I have. As I said before, I don't know anybody here in Lyon, France, who can help me, be it in English or in French.
Christopher