On 9/11/06, mainster <[EMAIL PROTECTED]> wrote:
I have been trying to get Shale Remoting working using shale v 1.03 I first tried to follow the guide at: http://shale.apache.org/features-remoting.html I corrected the example to the following: First adding methods to be called by client-side Ajax to the "welcome" bean (WelcomeBean.java), registered in faces-config.xml with request scope : package org.apache.shale.blank; import java.io.IOException; import java.util.Date; import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import org.apache.shale.remoting.faces.ResponseFactory; import org.apache.shale.view.AbstractViewController; public class WelcomeBean extends AbstractViewController { ... public void validateUsername() { FacesContext context = FacesContext.getCurrentInstance(); String username = (String)context .getExternalContext() .getRequestParameterMap().get("username"); if( ! "Joe".equals(username)) writeResponse(context, "Sorry, that's an unathorized username"); } private void writeResponse(FacesContext context, String text) { ResponseWriter writer = (new ResponseFactory()).getResponseWriter(context, "text/plain"); try { writer.writeText(text, null); writer.close(); context.responseComplete(); } catch (IOException e) { e.printStackTrace(); } } The method was refactored a bit, closing the writer and calling reponseComplete() as recommended in http://shale.apache.org/shale-remoting/apidocs/index.html For a text response, acquire a ResponseWriter instance and use its methods, just as a Renderer would: FacesContext context = FacesContext.getCurrentInstance(); ResponseWriter writer = (new ResponseFactory()).getResponseWriter(context, "text/xml"); writer.startDocument(); ... writer.endDocument(); writer.close(); Before returning, the dynamic logic should call responseComplete() on the FacesContext instance for the current request, to bypass the remaining phases of the JavaServer Faces request processing lifecycle. I then went on to configure web.xml with appropriate mappings after the Welcome File List entry: org.apache.shale.remoting.CLASS_RESOURCES /static/*:org.apache.shale.remoting.impl.ClassResourceProcessor org.apache.shale.remoting.DYNAMIC_RESOURCES /dynamic/*:org.apache.shale.remoting.impl.MethodBindingProcessor org.apache.shale.remoting.WEBAPP_RESOURCES /webapp/*:org.apache.shale.remoting.impl.WebResourceProcessor I then changed welcome.jsp to the following, to try different URL patterns for grabbing a resource: <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <[EMAIL PROTECTED] file="messages.jspf"%> Hello World The result :( running mvn deploy on the application and deploying the myShaleApp.war on Tomcat 5.5.17 Prefixing the URL with http://localhost:8081/myShaleApp/ : getStaticRes(), getWebAppRes() and the dynamic validateUsername(..) HTTP 500 - The server encountered an internal error () that prevented it from fulfilling this request. Without the prefix: getStaticRes2(), getWebAppRes2() HTTP 404 - The requested resource (/static/resource/hello.txt.faces) is not available. Any ideas about what I have missed in my configuration? How can I turn on debugging/logging to determine and fix such problems in the future?
The first place you should look to help resolve stuff like this is the log files for your servlet container. The exception chain that caused the 500 error will typically be logged there, and might provide some insight into what is going wrong. For a completely worked example of using the features of Shale Remoting, I would suggest taking a look at the Java Blueprints AJAX components library[1], which is also available with Java Studio Creator. In particular, the Auto Complete Text FIeld component uses Shale Remoting both for downloading static resources (the javascript and stylesheet static files associated with the component) as well as the dynamic callback as each character is typed. NOTE - if you like the default path mappings, you don't need to configure *anything* in web.xml to use Shale Remoting. But, it's not obvious from your description what you are trying to accomplish ... it might be useful to start from that so we can talk about approaches. Craig [1] https://blueprints.dev.java.net/ajaxcomponents.html Kristian
-- View this message in context: http://www.nabble.com/Shale-Remoting-Troubles-tf2252936.html#a6248433 Sent from the Shale - Dev forum at Nabble.com.
