Announcement Announcement Module
Collapse
No announcement yet.
Compile Error for Spring Social Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Compile Error for Spring Social

    Hi guys, I have decided that I want to learn how to use Twitters API with Spring Social. I have to following code in a controller:

    Code:
    ...
    String consumerKey = "myDetails";
         String consumerSecret = "myDetails";
         String accessToken = "myDetails";
         String accessTokenSecret = "myDetails";
    
         TwitterTemplate twitterTemplate = new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
    
         TwitterProfile profile = twitterTemplate.userOperations().getUserProfile("markabruce");
    ...
    I then get the following error:

    cannot access org.springframework.social.oauth1.AbstractOAuth1Ap iBinding
    class file for org.springframework.social.oauth1.AbstractOAuth1Ap iBinding not found

    Any ideas?

    Thanks,
    Mark

  • #2
    I think i fixed it by adding spring-social-core-1.0.0.RC2.jar to my classpath.

    I then added the following servlet-context xml config:

    Code:
        <bean id="connectionFactoryLocator" class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
        <property name="connectionFactories">
            <list>
                <bean class="org.springframework.social.twitter.connect.TwitterConnectionFactory">
                    <constructor-arg value="${twitter.consumerKey}" />
                    <constructor-arg value="${twitter.consumerSecret}" />
                </bean>
            </list>
        </property>
        </bean>
    Here is my "web.xml" config for the NEW ERROR I have mentioned below, thanks:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext-servlet.xml</param-value>
        </context-param>
    
        <servlet>
            <servlet-name>applicationContext</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>applicationContext</servlet-name>
            <url-pattern>*.htm</url-pattern>
        </servlet-mapping>
    
    </web-app>
    Last edited by markabrucey; Aug 16th, 2011, 06:28 AM.

    Comment


    • #3
      It seemed to work but I ran into more underlying errors now(HTTP 503 ERROR: SERVICE_UNAVAILABLE):
      (It's just weird as I didn't get these errors prior to setting up Spring Social, also my web.xml (shown above) points to the classes i need)

      Code:
      WARNING: Could not instantiate listener org.springframework.web.context.ContextLoaderListener
      java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      	at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      	at org.mortbay.jetty.handler.ContextHandler.loadClass(ContextHandler.java:1101)
      	at org.mortbay.jetty.webapp.WebXmlConfiguration.initListener(WebXmlConfiguration.java:630)
      	at org.mortbay.jetty.webapp.WebXmlConfiguration.initWebXmlElement(WebXmlConfiguration.java:368)
      	at org.mortbay.jetty.webapp.WebXmlConfiguration.initialize(WebXmlConfiguration.java:289)
      	at org.mortbay.jetty.webapp.WebXmlConfiguration.configure(WebXmlConfiguration.java:222)
      	at org.mortbay.jetty.webapp.WebXmlConfiguration.configureWebApp(WebXmlConfiguration.java:180)
      	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1247)
      	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
      	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.jetty.Server.doStart(Server.java:224)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:186)
      	at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:162)
      	at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:172)
      	at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:164)
      	at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
      	at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
      	at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      Aug 16, 2011 10:14:38 AM com.google.apphosting.utils.jetty.JettyLogger warn
      WARNING: EXCEPTION 
      java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
      	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      	at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      	at org.mortbay.util.Loader.loadClass(Loader.java:91)
      	at org.mortbay.util.Loader.loadClass(Loader.java:71)
      	at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:73)
      	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:242)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
      	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
      	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
      	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
      	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.jetty.Server.doStart(Server.java:224)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:186)
      	at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:162)
      	at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:172)
      	at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:164)
      	at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
      	at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
      	at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      Aug 16, 2011 10:14:38 AM com.google.appengine.tools.development.ApiProxyLocalImpl log
      SEVERE: javax.servlet.ServletContext log: unavailable
      javax.servlet.UnavailableException: org.springframework.web.servlet.DispatcherServlet
      	at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:79)
      	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:242)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
      	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
      	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
      	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
      	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
      	at org.mortbay.jetty.Server.doStart(Server.java:224)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:186)
      	at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:162)
      	at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:172)
      	at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:164)
      	at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
      	at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
      	at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      
      Aug 16, 2011 10:14:38 AM com.google.apphosting.utils.jetty.JettyLogger warn
      WARNING: failed applicationContext: java.lang.NullPointerException
      Aug 16, 2011 10:14:38 AM com.google.apphosting.utils.jetty.JettyLogger warn
      WARNING: Failed startup of context [email protected]124{/,/Users/markabrucey/Development_Workspace/SpringTestApplication/out/artifacts/SpringTestApplication_war_exploded}
      java.lang.NullPointerException
      	at java.lang.Class.isAssignableFrom(Native Method)
      	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
      	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
      	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
      	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
      	at ...
      Last edited by markabrucey; Aug 16th, 2011, 06:52 AM.

      Comment


      • #4
        Here is my web.xml:

        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <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">
        
            <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>
        
            <welcome-file-list>
        		<welcome-file>index.jsp</welcome-file>
        	</welcome-file-list>
        
            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/applicationContext-servlet.xml</param-value>
            </context-param>
        
            <servlet>
                <servlet-name>applicationContext</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
            </servlet>
        
            <servlet-mapping>
                <servlet-name>applicationContext</servlet-name>
                <url-pattern>*.htm</url-pattern>
            </servlet-mapping>
        
        </web-app>

        Comment


        • #5
          Removing and then Re-adding the .jars into the lib file did the trick...

          Now a new problem...

          After trying to use the Police API I was getting:

          500 Error: access denied (java.net.SocketPermission search.twitter.com resolve)

          I thought I would quickly do this for twitter as well since it was a possibility it could be a problem on the Police API's end... I set up a simple twitter search by following your documentation/tutorial and I am still getting: access denied (java.net.SocketPermission search.twitter.com resolve)

          I am looking into this and it appears that my privileges may not be set up properly, I am revising how to fix this now, but if you get to me while I am still looking, that would be fantastic.

          The requests never seem to leave my computer because of this error.

          Thanks in advance,
          Mark

          Comment


          • #6
            The lesson to be learned here is never to use HTTPClient4 with Spring MVC. I had no idea Spring had its own library to handle client stuff, the result was the HTTPClient4 jars were being found by springs own handling and was probably trying to use sockets it didn't have access to according to spring configuration of some sort and thus my end created a 500 SocketException. If someone more experienced with Spring can explain this better, that would be great for me and others.

            Thanks,
            Mark
            Last edited by markabrucey; Aug 17th, 2011, 05:17 AM.

            Comment


            • #7
              Actually, there are a few things in play here and using HTTPClient 4 shouldn't be a problem if the other things are dealt with.

              First, the reason you got a 500 error is because of a deeper permission exception in your code. The 500 was just the server's way of expressing that something bad happened internally. The actual problem is a JVM security issue.

              Somewhere in your server's configuration, you have security turned on. You never said what server you're using, so I'm assuming Tomcat (if I'm wrong, you'll need to look up the details for your server). When Catalina (i.e., Tomcat) is run with -security, it turns on Tomcat security, enforcing certain policies to be enforced. Those policies are defined in the conf/catalina.policy file. This isn't a Spring configuration detail--it's a server configuration detail. You can take a look at http://tomcat.apache.org/tomcat-7.0-...ger-howto.html to get more details on how this works.

              In your case, the app was trying to resolve search.twitter.com, but didn't have permission (per the policies) to do that. It would've also needed connect permission.

              Adding the following to your policy file would probably do the trick:

              Code:
              grant {
                permission java.net.SocketPermission 
                "search.twitter.com", "connect,resolve";
              };
              But you can also restrict that permission to only certain applications or subsets of code. And, for development time purposes, there may be no need to have security turned on at all. I encourage you to read more on Java security policies (especially for whatever server your using) to determine the best direction for your needs.

              Comment


              • #8
                Thank you for clearing this up! I feel stupid, because I have your book and of course you used HTTPClient in that! So I have no idea why I assumed HTTPClient doesn't work, your explanation is excellent!
                Last edited by markabrucey; Aug 18th, 2011, 07:35 AM.

                Comment


                • #9
                  Oops, double post, sorry! I did try granting permissions after reading about it, but it seemed to have no affect either, but I have sorted this now. (by the way, I am using the Google App Engine in case you wanted to know)

                  Thanks,
                  Mark
                  Last edited by markabrucey; Aug 18th, 2011, 07:32 AM.

                  Comment


                  • #10
                    Now I am getting my data, I am at a blank on how to get it to display in my view, could you please enlighten me if possible on how to do this?

                    Here's my code so far:

                    Code:
                    @Controller
                    public class TwitterRESTController {
                    
                         @RequestMapping(value = "/twitterFeed", method = RequestMethod.POST)
                         public @ResponseBody TwitterProfile twitterPublicFeed() {
                    
                         String consumerKey = "...";
                         String consumerSecret = "...";
                         String accessToken = "...";
                         String accessTokenSecret = "...";
                    
                         TwitterTemplate twitterTemplate = new TwitterTemplate(/*consumerKey, consumerSecret, accessToken, accessTokenSecret*/);
                    
                         TwitterProfile profile;
                         profile = twitterTemplate.userOperations().getUserProfile("markabruce");
                    //     SearchResults results;
                    //     results = twitterTemplate.searchOperations().search("#spring");
                    
                    
                         return profile;
                    
                         }
                    }
                    Do I need to return a model and view instead and add it to that ModelAndView?

                    Or I could create a JSP, return that JSP view and use expression language to get the values?

                    I'm quite confused on returning the JSON to a page though, currently the above just returns a downloadable file containing the JSON data.

                    Any help would be fantastic,

                    Thank you,

                    Mark

                    Comment


                    • #11
                      I see you can use Ajax (http://blog.springsource.com/2010/01...in-spring-3-0/), but I can't get my head around how its fully interacting with the Controller that has just gathered the JSON data.

                      The example in the URL seems great, but I am having difficulty relating it to my own controller.
                      Last edited by markabrucey; Aug 18th, 2011, 07:56 AM.

                      Comment


                      • #12
                        I'm giving it a go and this is what I'm coming up with so far:

                        function to use controller to get tweets:
                        Code:
                        <script type="text/javascript">
                          function getTwitterUser() {
                             $.getJSON("twitterFeed.htm", function(data)
                                       {
                                          $('#tweets').text('');
                        
                                          for (var index in data) {
                                             $('#tweets').append('<p>' + data[index].title + '</p>');
                                          }
                                       });
                         }
                        </script>
                        Part where I activate my function:
                        Code:
                                               <div id="tweets">
                                                    <h1 class="areatitle">Tweets...</h1>
                                                   <input type="button" value="Feeds" onclick="getTwitterUser()"/>
                        
                                               </div>
                        Am I along the right lines? Thanks!

                        Comment


                        • #13
                          There are many different ways you could display the data on the page, the most basic of which is to put it into the model (from within the controller) and then render it from a JSP (the model data ends up being request attributes that are easily accessible from the JSP). But again, there are several options here.

                          The Spring Social samples will give you some insight into how this can be done: https://github.com/SpringSource/spring-social-samples

                          At this point (in fact, quite a few posts back) this became more of a basic Spring MVC discussion and less of a Spring Social discussion. In the interest of staying on topic, may I recommend that this discussion be continued in the Web forum (http://forum.springsource.org/forumdisplay.php?25-Web)?

                          Comment


                          • #14
                            I get a list of "undefined" displayed, so at least it is doing something.

                            I also get the following warning:

                            Code:
                            Aug 18, 2011 1:05:40 PM com.google.appengine.repackaged.org.apache.http.client.protocol.ResponseProcessCookies processCookies
                            WARNING: Invalid cookie header: "Set-Cookie: guest_id=v1%3A131367273963776229; domain=.twitter.com; path=/; expires=Sun, 18 Aug 2013 01:05:39 GMT". Unable to parse expires attribute: Sun, 18 Aug 2013 01:05:39 GMT
                            EDIT: OH SORRY! SURE! I'll take it to the other forum.

                            Thanks.

                            Comment

                            Working...
                            X