Spring social ConnectController /connect/facebook gives a 404 error - facebook

I am trying to get the facebook login working with spring social.
I have created an app on facebook.
Dispatcher Servlet
<servlet-mapping>
<servlet-name>ABC</servlet-name>
<url-pattern>*.cs</url-pattern>
</servlet-mapping>
configfured the xmls
<servlet-mapping>
<servlet-name>ABC</servlet-name>
<url-pattern>*.cs</url-pattern>
</servlet-mapping>
<!-- Configure a connection repository through which account-to-provider connections will be stored -->
<beans:bean id="connectionRepository" class="org.springframework.social.connect.jdbc.JdbcConnectionRepository">
<beans:constructor-arg ref="dataSource" />
<beans:constructor-arg ref="textEncryptor" />
</beans:bean>
<!-- Configure a Facebook service provider -->
<beans:bean class="org.springframework.social.facebook.connect.FacebookServiceProvider">
<beans:constructor-arg index="0" value="564846465216" />
<beans:constructor-arg index="1" value="f4554iojfjh9iu7km54f54pok5ok4" />
<beans:constructor-arg index="2" ref="connectionRepository" />
</beans:bean>
<beans:bean id="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors" factory-method="noOpText" />
<beans:bean class="org.springframework.social.web.connect.ConnectController">
<beans:constructor-arg index="0" value="http://localhost:8080/CitySpanks/" />
</beans:bean>
I am referring this link
http://static.springsource.org/spring-social/docs/1.0.0.M2/reference/html/connecting.html
in my jsp
Connect to Facebook
Anything i am missing ??? I keep getting a 404 error on clicking the above link.
Thanks :)

I'm not sure where you are at in your project but I think the following may be easy to overlook...
If you look at the sample projects for spring-social-showcase you'll notice that under
spring-social-showcase-sec/src/main/webapp/WEB-INF/views/connect
exist the following pages:
status.jsp, facebookConnect.jsp, facebookConnected.jsp.
In the sample project when the following (left) is requested it will resolve the .jsp's below (right):
"connect/facebook" => Connected => "connect/facebookConnected.jsp"
"connect/facebook" => Not Connected => "connect/facebookConnect.jsp"
"connect" => "connect/status.jsp"
This is documented here: 4.3.1 Displaying a connection page
So, to get that example to work in YOUR code you have to create the same directory structure "WEB-INF/views/connect/" with the above .jsp's in it. Otherwise they will not be found, hence the 404. I believe this is resolved by the ConnectController class, behind the scenes, as described in docs linked above.
However, you may want to start off with using their web.xml configuration found in spring-social-samples and once you get the hang of that, go from there.
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

DispatcherServlet is mapped to *.cs, but the link in your JSP is to /connect/facebook (relative to the application root). That URL doesn't end in .cs, so there's no match and DispatcherServlet never gets involved.
Although you can still map DispatcherServlet to any arbitrary URL pattern, the "best practice" since Spring 3.0 is to simply map it to "/", to allow it to respond to a variety of URLs, including those for RESTful APIs.
Of course, that also means that DispatcherServlet will respond to requests for images, style sheets, javascript, and other resources, which is probably not what you want. and were created to solve that problem. See the reference documentation here and here for more details.

Related

Spring/REST Application with HOT Deployment: Groovy script does not load dynamically from applicationContext.xml on tomcat startup at runtime

I am in the process of converting an already exisiting Java Web application into a RESTful web application using Spring MVC and Groovy.
One of the main features I wanted to achieve was HOT DEPLOYMENT.
I chose groovy because I did not want to make changes to the already implemented Business logic(handlers) and also if I had to ever make changes to the groovy code after deployment, I could easily do that without restarting the server(ie. at runtime).
This can be done because Spring supports Dynamic reloading of groovy scripts(beans). It reloads classes of dynamic languages if they are changed.
I am using Spring annotations to map request URL's to controller methods and the application is deployed in tomcat 6.0.35.
This is the web.xml file
//web.xml
<?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">
<!-- Spring Dispatcher -->
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- Loads application context files in addition to ${contextConfigLocation} -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Set session timeout to 30 minutes -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
This groovy file is the controller to which the DispatcherServlet maps the request.
// UserController.groovy
#Controller
class UserController
{
// This is the method to which the HTTP request is submitted to based on the mapping of the
// action field of the form ie. /service/user/login/auth.json
#RequestMapping(value="/user/login/auth.{extension:[a-zA-Z]+}", method=RequestMethod.POST)
#ResponseBody
public String authenticate(
#PathVariable String extension,
#RequestParam(value="username", required=true) String username,
#RequestParam(value="password", required=true) String password)
{
// UserResource makes the backend calls, authenticates a user and returns the result.
def user = new UserResource()
def result = user.login(name:username, userPassword:password)
// Output the result of the query. Method makeView makes a JSON response of the result
// and sends to the client(browser)
def builder = makeView(extension)
{
it.login(action:result.action, message:result.message)
}
}
}
The Spring configuration file is as follows where I have used the "lang:groovy" tag which supports dynamic languages. I have also mentioned the refresh time to be 5 seconds, so that any changes made to those groovy files at runtime can be seen every 1 second and the classes are reloaded.
//applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="app.controller,app.resource" />
<lang:groovy id="user" script-source="classpath:controller/UserController.groovy" refresh-check-delay="1000"></lang:groovy>
<!-- To enable #RequestMapping process on type level and method level -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- Resolves view names to template resources within the directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".html"/>
</bean>
</beans>
I have configured my Buildpath and groovy compiler accordingly, so that all the groovy scripts directly get copied to the target folder instead of getting compiled to class files.
THE MAIN PROBLEM
When I deploy this project in a tomcat server, it loads all the Spring beans required including the ScriptProcessor. Now, when I go to my browser, load the form, and try to submit the authentication form, I get the following error in Tomcat log:
15:20:09 WARN - No mapping found for HTTP request with URI [/service/user/login/auth.json] in DispatcherServlet with name 'rest'
I have also made changes in $TOMCAT_DIR/conf/context.xml to antilock resources and JARS
<Context antiResourceLocking="true" antiJARLocking="true" reloadable="true" privileged="true">
.
.
.</Context>
However, if I configure my project to compile those groovy scripts into bytecode classes, comment out the "lang:groovy" tag in applicationContext.xml, and then restart the server, the groovy scripts get compiled into class files and the request is serviced perfectly. Authentication takes place.
Also, if I configure the dynamic beans in my applicationContet.xml using the following two lines instead of the tag, my beans DO get created dynamically at runtime and the URLs do get mapped to the respective controller methods because of the annotations.
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor" />
<bean id ="User" class="org.springframework.scripting.groovy.GroovyScriptFactory">
<constructor-arg value="classpath:controller/UserController.groovy" />
</bean>
But I do not know how to create the bean refreshing functionality with this style. So I guess there is an issue with the way the tag processes the groovy scripts.
I would really appreciate some help on this. I have searched all over the internet and read an infinite number of tutorials, and followed the exact procedure mentioned there. But I cant find out whats going wrong.
Please help me solve this problem.
Thank you.
Try creating the controller with Java/Groovy that is compiled and let it get injected the Groovy 'script' as a dependency to do the actual work. I seem to remember doing this before and it might be the annotations or the way Spring loads controllers that makes the 'script' not work for you properly.

implementing authentication using oauth 2.0 and wicket

I try to bring up secure communication with our customer using oauth 2.0.
first of all I have to confess that I am totally new to oauth.
Used technologies are as follow: wicket, spring,
I took the following steps.
Add dependency in pom.xml
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth</artifactId>
<version>1.0.0.M3</version>
</dependency>
Then I added the following in WEB-INF/web.xml
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Finally I added these lines to META-INF/spring-context/application.xml
<beans:bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.InMemoryOAuth2ProviderTokenServices">
<beans:property name="supportRefreshToken" value="true" />
</beans:bean>
<oauth:provider client-details-service-ref="clientDetails" token-services-ref="tokenServices">
<oauth:verification-code user-approval-page="/oauth/confirm_access" />
</oauth:provider>
<oauth:client-details-service id="clientDetails">
<oauth:client clientId="foo" authorizedGrantTypes="authorization_code" />
</oauth:client-details-service>
But I got this error:
25 09 12 14:48:11:921:ERROR: [ContextLoader] Context initialization failed
java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
at java.lang.Class.getConstructor0(Class.java:2714)
at java.lang.Class.getDeclaredConstructor(Class.java:2002)
...
I think you need the spring-core in your maven dependencies. Specifically version 3.1 or upwards.
It is usually like this that when we add a dependency, It contains necessary dependencies itself. Isn't it?
Cause I got so Error and I add till now many dependency but still face some new ones?
Is that logical ... to add dependency till I can run the project.
I have still no code inside ... just try to add OAUTH dependency!

gwt logs are not generated

Using gwt logs jar I am able to display logs on my console. But now I wanted to add logs in my olgs file from cient side, as we do using log4j on server side. So i reffered to http://code.google.com/p/gwt-log/wiki/GettingStarted this link but i dont see any client side logs getting generated in my log file.
Following is my gwt.xml file
<inherits name="com.allen_sauer.gwt.log.gwt-log-DEBUG" />
<set-property name="log_DivLogger" value="DISABLED" />
<!-- In gwt-log-3.0.3 or later -->
<inherits name="com.allen_sauer.gwt.log.gwt-log-RemoteLogger" />
<set-configuration-property name="log_pattern" value="%d [%t] %p - %m
%n" />
Following is my web.xml file
<servlet>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<servlet-class>com.allen_sauer.gwt.log.server.RemoteLoggerServiceImpl</servlet-class>
<!--
The `symbolMaps` parameter specifies the server directory
containing the GWT compiler symbol maps output, which is used
for stack trace deobfuscation
-->
<init-param>
<!-- This value assumes a GWT compile with '-deploy war/WEB-INF/deploy/' -->
<param-name>symbolMaps</param-name>
<!--
Modify the param-value based on your server environment. Some web servers
use your `war` directory as the 'current working dir', while other
vendors will do something different. You may use trial and error. Specify the
relative path you think should work, then check the server log after forwarding
the first client log message to the server. If the directory cannot be found,
gwt-log will report the full path which it tried.
-->
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!--
Additional or alternate directories may be specified via additional parameter
which also begin with `symbolMaps`. This may be useful if you deploy to multiple
server environments which use different directory structures or have a different
notion of what the 'current working directory' is.
-->
<init-param>
<param-name>symbolMaps_2</param-name>
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!-- Optionally enable CORS (http://www.w3.org/TR/cors/)
<init-param>
<param-name>Access-Control-Allow-Origin</param-name>
<param-value>http://your-applications-origin</param-value>
</init-param>
-->
</servlet>
<servlet-mapping>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<url-pattern>/com.renault.detectfiles/gwt-log</url-pattern>
</servlet-mapping>
I have added log on clinet side as follows
Log.debug("Hi this is a debug log");
First of all, make sure that you compile your GWT application with the additional parameter -deploy war/WEB-INF/deploy/.
Second, make sure that symbol maps exist in the directory
WEB-INF/deploy/detectfiles/symbolMaps/. I observed that symbolMaps go to the directory WEB-INF/deploy/<module-name>/symbolMaps/ when I compiled. Here, detectfiles does not look like your module name. Because, in the url-pattern, you have specified com.renault.detectfiles as the module name.
These might be the possible cause of not seeing the log.

gwt app deployment to tomcat doesn't load compiled javascript

I use Eclipse GWT Plug-in to build a GWT app. Later on, I'll have to deploy this as a Tomcat webapp. I have read many pages on how to do it and it looks dead simple but it doesn't work here.
If I create a new Web application using the plug-in and that I copy the war directory content to de tomcat_install/webapps folder it works right out the box, I get the application and all the things get loaded correctly.
If I do the same with the application I'm working on for a couple of weeks now, I get nothing, there is just the plain html file I use as welcome page that loads. If I inspect the page I can see it has correctly loaded the .nocache.js but no controls whatsoever show up on my page.
Everything works in development, my servlet are correctly mapped.
Here is my app.gwt.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='VirtualLabPortal'>
<inherits name="com.google.gwt.user.User" />
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<set-property name="gwt.logging.enabled" value="FALSE"/>
<define-property name="webkitVariant" values="safari, chrome" />
<collapse-all-properties />
<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr" />
<set-property-fallback name="locale" value="fr"/>
<entry-point
class="com.banctecmtl.ca.vlp.view.webview.client.VirtualLabPortal" />
<source path='view/webview/client' />
<source path='shared' />
<source path='model' />
</module>
My web,xml, where my two servlet are mapped looks like this :
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>VlpControllerService</servlet-name>
<servlet-class>com.banctecmtl.ca.vlp.view.webview.server.VlpControllerServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>UserAccessService</servlet-name>
<servlet-class>com.banctecmtl.ca.vlp.view.webview.server.UserAccessServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VlpControllerService</servlet-name>
<url-pattern>/VirtualLabPortal/VlpController</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UserAccessService</servlet-name>
<url-pattern>/VirtualLabPortal/UserAccess</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>VirtualLabPortal.html</welcome-file>
</welcome-file-list>
</web-app>
Note that in my services interfaces I use #RemoteServiceRelativePath("VlpController") and #RemoteServiceRelativePath("UserAccess") to ensure a correct mapping.
This is the content of my entrypoint, that I made plain simple just to see if I could get it to work on deployment :
public class VirtualLabPortal implements EntryPoint {
/**
* Entry point method.
*/
public void onModuleLoad() {
RootPanel.get().add(new Label("This"));
}
}
Since the body of my html page is empty, a white page shows up, the javascript should write the test label on that page, but nothing happens. As I said, my VirtualLabPortal.nocache.js is loaded in the html page.
Is there something I'm completely missing here?
EDIT :
I think i just got it, I removed two properties my partner added to the gwt.xml file to reduce the number of permutations and it seems to be fixed so far:
<set-property name="gwt.logging.enabled" value="FALSE"/>
<define-property name="webkitVariant" values="safari, chrome" />
<collapse-all-properties />
Do you compile your project via :
project right clic > google > gwt compile
and then
project right clic > export > WAR file
this is the way I proceed, it works !
check this one:
Deploying GWT app from GAE to Tomcat
After long hours of searching and testing, I understtod how GWT bootstrapping process was working. I looked over my module.gwt.xml file and I found the following line added by one of my partners to reduce the number of permutations :
<collapse-all-properties />
Removing this line brought us back to 18 permutations and deploying the WAR folder to my tomcat webapps directory did the job. Compiling only once was not generating the file used required by my locale. Maybe if my browser language would have been in English it would have worked out the first time.
Well now it works as all the required files are correctly compiled.

Struts no action mapped issue

When deploying a struts application to tomcat running in eclipse I'm getting the following error to the console when trying to load the welcome page.
"There is no Action mapped for namespace / and action name . - [unknown location]"
I was trying to follow the tutorial at: http://viralpatel.net/blogs/2009/12/tutorial-create-struts-2-application-eclipse-example.html.
I am obviously just getting started with struts and any help would be appreciated.
Make sure to have the URL-Pattern mapped to Struts in your web.xml file.
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
Make sure you have the action name then mapped to a Java class in your struts.xml.
<action name="find" class="findAction" method="input">
<interceptor-ref name="myStack" />
<result name="input">find</result>
</action>
These are the essentials. The result will then need mapped to a JSP. Good Luck.