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:

<context-param>
  <param-name>
    org.apache.shale.remoting.CLASS_RESOURCES
  </param-name>
  <param-value>
    /static/*:org.apache.shale.remoting.impl.ClassResourceProcessor
  </param-value>
</context-param>

<context-param>
  <param-name>
    org.apache.shale.remoting.DYNAMIC_RESOURCES
  </param-name>
  <param-value>
    /dynamic/*:org.apache.shale.remoting.impl.MethodBindingProcessor
  </param-value>
</context-param>

<context-param>
  <param-name>
    org.apache.shale.remoting.WEBAPP_RESOURCES
  </param-name>
  <param-value>
    /webapp/*:org.apache.shale.remoting.impl.WebResourceProcessor
  </param-value>
</context-param>

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"; %>

<f:view>
  <[EMAIL PROTECTED]  file="messages.jspf"%>

<html>

  <head>
    <title><h:outputText     value="#{messages['welcome.title']}"/></title>
    <script type="text/javascript" src="js/prototype.js"/>
    <script type="text/javascript" src=""js/rico.js""></script>
    <script type="text/javascript">
          function hideMessage() {
             $("message").style.display = "none"; // the $ is Prototype's
shorthand for window.document.getElementById()
          }
          // dynamic/welcome/validateUsername.faces
          function validateUsername(username) {
             new Ajax.Request(
               
"http://localhost:8081/myShaleApp/dynamic/welcome/validateUsername.faces";,
                {
                   method: "post",
                   parameters: "username=" + username,
                   onComplete: showMessage
                }
             );
          }   

          function getStaticRes() {
             new Ajax.Request(
               
"http://localhost:8081/myShaleApp/static/resource/hello.txt.faces";,
                {
                   method: "post",
                   onComplete: showMessage
                }
             );
          }  

          function getStaticRes2() {
             new Ajax.Request(
                "/static/resource/hello.txt.faces",
                {
                   method: "post",
                   onComplete: showMessage
                }
             );
          }  

          function getWebAppRes() {
             new Ajax.Request(
               
"http://localhost:8081/myShaleApp/webapp/resource/hello.txt.faces";,
                {
                   method: "post",
                   onComplete: showMessage
                }
             );
          }  

          function getWebAppRes2() {
             new Ajax.Request(
                "/webapp/resource/hello.txt.faces",
                {
                   method: "post",
                   onComplete: showMessage
                }
             );
          }  
          
          function showMessage(xhr) {
             var msg = $("message");  
             msg.style.display = "inline";
             msg.style.color = "red";
             msg.innerHTML = xhr.responseText; // set the innerHTML of the
message DIV
          }                 
    </script>
  </head>

  <body>
    <p>
      <h1>Hello World</h1>
      <h:outputText          value="#{messages['welcome.prompt']}"/>
      <h:outputText          value="#{welcome.timestamp}">
        <f:convertDateTime    type="both"/>
      </h:outputText>
    </p>
            <h:panelGroup>

              <h:commandButton id="staticRes" onclick="getStaticRes();
return false;"/>

              <h:commandButton id="webAppRes" onclick="getWebAppRes();
return false;"/>

              <h:commandButton id="staticRes2" onclick="getStaticRes2();
return false;"/>

              <h:commandButton id="webAppRes2" onclick="getWebAppRes2();
return false;"/>


              <h:commandButton id="empty" onclick=""/>

              <h:inputText id="username" onfocus="hideMessage();"
                 onblur="validateUsername(this.value);"/>

              <h:inputText id="password"/>

              <f:verbatim>
                <div id="message" style="display: none;"></div>
              </f:verbatim>

            </h:panelGroup>
  </body>

</html>

</f:view>


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?

Kristian
-- 
View this message in context: 
http://www.nabble.com/Shale-Remoting-Troubles-tf2252955.html#a6248519
Sent from the Shale - Dev forum at Nabble.com.

Reply via email to