Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Error while obtaining attributes from Map on client side

    Be sure your post includes:

    1. Using Smart GWT 2.2

    2. IE8 is browser

    3.
    Code:
    public interface AdminMainService extends RemoteService {
    Map<String, String> findCookieByName(String cookieName1, String cookieName2) throws IllegalArgumentException;
    }
    
    public interface AdminMainServiceAsync {
    void findCookieByName(String cookieName1, String cookieName2, AsyncCallback<Map<String, String>> asyncCallback);
    }
    
    public class AdminMainServiceImpl extends RemoteServiceServlet implements
    		AdminMainService {
    public Map<String, String> findCookieByName(String cookieName1, String cookieName2) {
    Map<String, String> hmUserName = new HashMap<String, String>();
    String username = (String) this.getThreadLocalRequest().getAttribute("username");	
    hmUserName.put("username", username);
    return hmUserName ;
    }
    
    } // class end
    
    The AdminMain class gets called initially at the client side.
    
    public class AdminMain implements EntryPoint {
    
      public void onModuleLoad() {
    
    adminMainService.findCookieByName("username", "SM12", new AsyncCallback<Map<String, String>>() {
    			public void onSuccess(Map<String, String> result) {
    				if(result != null) {
                            process further & display the page
                                     }
    }
    4. The adminMainService.findCookieByName gets called. After that the browser displays UnCaught Exception.

    2013-05-14 18:28:43,922 [ERROR] Uncaught Exception
    java.lang.ClassCastException:
    null
    at Unknown.Wtb(Unknown source:0)
    at Unknown.qS(Unknown source:0)
    at Unknown.sp(Unknown source:0)
    at Unknown.C6(Unknown source:0)
    at Unknown._N(Unknown source:0)
    at Unknown.DO(Unknown source:0)
    at Unknown.anonymous(Unknown source:0)
    at Unknown.JH(Unknown source:0)
    at Unknown.anonymous(Unknown source:0)

    Looking at the Interfaces & Implementation, I am using Map.
    I am not sure why I get ClassCastException & null printed below ClassCastException.

    Can anyone guide me what is the right approach for obtaining request parameters?

    Is using this.getThreadLocalRequest().getAttribute("username"); right approach?

    The username is being set in httpservletrequest by a filter class. I have verified that the value always exists & not null.


    Thanks

    #2
    Hi,
    Perhaps a trivial suggestion, but are you sure that you set an Attribute and not a Parameter?
    Maybe a:
    Code:
    getThreadLocalRequest().getParameter("username");
    could solve?

    (I think also you could avoid the "this." prefix)

    Bye,

    Luca.

    Comment

    Working...
    X