Spring-Social-facebook + Spring MVC integration - spring-social

I am trying to access facebook data via spring social facebook integration using the instructions provided at http://spring.io/guides/gs/accessing-facebook.
But currently i am facing 2 type of problem
When i run example as mentioned in tutorial i get following error
No matching bean of type [org.springframework.social.facebook.api.Facebook] found for dependency
When i run this with #Configuration on FacebookConfig class, i get below mentioned error
A ConnectionFactory for provider 'facebook' has already been registered
Is there a workaround to it?
I have kept the war file with source code at https://skydrive.live.com/redir?resid=EA49CD7184E0E40!168&authkey=!AIkoKKx5-Um8AQE

What version are you using?
Try using the version 1.1.0.RELEASE
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
If it not works, please try post the stacktrace printed.
You need to create a the beans to your class, please post more information like your pom.xml and your spring context configuration.

Ihad the same problem. Spring Social Facebook will automatically add connection factory based on the configuration in application.properties. This auto-configured connection factory is clashing with the one that you're trying to add. Try just to remove your connection factory you add through addConnectionFactories.

Try to use different setting to load your custom connection factory...
E.g. Instead of using OOTB keys use different keys:
#Facebook Social App Details:
# Commented below 2 OOTB Keys & Bingo it worked.
#spring.social.facebook.appId=APP_ID
#spring.social.facebook.appSecret=APP_SECRET
facebook.app.id=APP_ID
facebook.app.secret=APP_SECRET
This will resolve your problem.

Related

Upgrading to Springboot 3: 'org.springframework.hateoas.server.LinkRelationProvider' that could not be found

I am upgrading my springboot app from 2.7.x to 3.0.0, I have made required changes for jakartaEE. When starting my app I am getting the below error
{"#timestamp":"2023-01-03T15:28:01.149Z","#version":"1","message":"\r\n\r\n***************************\r\nAPPLICATION
FAILED TO
START\r\n***************************\r\n\r\nDescription:\r\n\r\nParameter
1 of method collectionModelContentConverter in
org.springdoc.core.configuration.SpringDocHateoasConfiguration
required a bean of type
'org.springframework.hateoas.server.LinkRelationProvider' that could
not be found.\r\n\r\n\r\nAction:\r\n\r\nConsider defining a bean of
type 'org.springframework.hateoas.server.LinkRelationProvider' in your
configuration.\r\n","logger_name":"org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter","thread_name":"main","level":"ERROR","level_value":40000}
I am using hateos lib for representation in my app, Also I am using springdoc-openapi-starter-webmvc-ui for swagger UI.
When I disable configuration for api-docs springdoc.api-docs.enabled=false the above error go away but my swagger page is also gone, which definitely means this is not the solution.
Could someone please guide me why this bean is not getting found with springboot 3 while it was all working before with springboot2.7.x and java-11.
here is my pom.xml https://gist.github.com/bruce2019/c93a16dc20f7edb7d922b1e284f39d15
Thanks in advance
You can use springdoc-openapi-starter-webmvc-ui with 2.0.2 version
Add "/v3/api-docs/**" to mvcMatchers in WebSecurityCustomizer

Optaplanner Quarkus reflection issues

I'm creating a solver factory based on an XML file using the built in
solverFactory = SolverFactory.createFromXmlResource("solverConfig.xml");
This works fine until compiling into a Quarkus native application, now I get reflection issues from Optaplanner enums:
ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.lang.NoSuchFieldError: org.optaplanner.core.api.domain.common.DomainAccessType: REFLECTION
at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getEnumConstants(ReflectionNavigator.java:25)
at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getEnumConstants(ReflectionNavigator.java:34)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.calcConstants(EnumLeafInfoImpl.java:117)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.getConstants(EnumLeafInfoImpl.java:181)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.link(EnumLeafInfoImpl.java:188)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.link(ModelBuilder.java:427)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.link(RuntimeModelBuilder.java:103)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:439)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:273)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:109)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1126)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:135)
at java.lang.reflect.Method.invoke(Method.java:566)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:275)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:264)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:403)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:89)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:81)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.<init>(SolverConfigIO.java:27)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:207)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:182)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:122)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:97)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:55)
I can work through these issues by adding #RegisterForReflection on my class calling SolverFactory.createFromXmlResource("solverConfig.xml"), but it feels like these reflection registrations should not have to be a manual step. Currently I'm at #RegisterForReflection(targets = {EnvironmentMode.class, RandomType.class, DomainAccessType.class}), but I'm guessing there will be a lot more enums to add to that list... Should it really be this complex? I'm using the Quarkus Optaplanner dependency
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-quarkus</artifactId>
</dependency>
By doing it another way, I was able to solve the issue.
In my class that previously called solverFactory = SolverFactory.createFromXmlResource("solverConfig.xml"), I now just inject the factory:
#Inject
SolverFactory<Schedule> solverFactory;
And moved the XML file name to application.properties instead:
quarkus.optaplanner.solver-config-xml=solverConfig.xml

Using ServiceTasks with TimerCatchingEvents in activiti bpmn workflow behaving inconsistently

When using ServiceTasks with IntermediateTimerEvents sometimes it did not execute the service task due to exception raised in ACT_RU_JOB table. EXCEPTION_MSG_ column in ACT_RU_JOB table is populated with Unknown property used in expression: #{serviceTask1.execute(execution). value for that particular job.
Please refer the activiti workflow image i have attached below for clear picture of the usecase.
NOTE: I am using spring-boot microservice using maven to run the workflow.
spring-boot version: 1.5.5.RELEASE
activity version: 5.22.0
Activity and Connection Pool dependencies in pom.xml:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
</dependency>
Connection Pooling dependency:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
application.properties configuration attached below:
spring.activiti.job-executor-activate=false
spring.activiti.async-executor-enabled=true
spring.activiti.async-executor-activate=true
spring.datasource.tomcat.initial-size=15
spring.datasource.tomcat.max-active=100
ANALYSIS: The error i am getting above is not consistent.
activiti workflow
Project link on Github:
https://github.com/cloudnativeview/spring-activiti-bpmn-kickstart
The exception is totally expected because you don't set the appropriate process variable when starting your process instance. Also Activiti engine is not able to resolve named bean serviceTask1.
From the Activiti 5.22.0 userguide docs (inside the file activiti-5.22.0.zip), more precisely section 8.5.3. Java Service Task you have 4 ways of declaring how to invoke Java logic.
Specifying a class that implements JavaDelegate or ActivityBehavior.
Evaluating an expression that resolves to a delegation object.
Invoking a method expression.
Evaluating a value expression.
In your BPMN process definition file you are invoking service task Java logic with method expression technique. If you want to successfully invoke your method you have to make sure your bean serviceTask1 is a process variable from your execution or a named object in Spring context.
Unfortunately you don't provide necessary information to your BPM engine on where to find your bean with Java logic.
I suggest you the following steps.
Read the technical and userguide documentation (chapter 8.5.3. Java Service Task), from the provided links.
Try to invoke Java logic with the way of specifying a class that implements JavaDelegate or ActivityBehavior. In my humble opinion it is far more easier to get the first touch with Activiti BPM engine.

automatic configuration of Spring Social’s ConnectController not working

I have followed the steps given in the below site to create a simple spring boot application that access the facebook data using maven and spring boot.
http://spring.io/guides/gs/accessing-facebook/
which is also same as http://www.technicalkeeda.com/spring/spring-social-facebook-integration-example but in gradle.
The problem i am facing is when i am trying to run the application, I have am seeing that url is successfully redirected to "/connect/facebook" but it doesnt load the facebookConnect.html instead it throws error
as shown below:
"
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Mar 10 19:24:41 IST 2015
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
"
I have also tried using the same code given in the site and also used my facebook appId and appSecret in it , which i had generated by giving a random host name in the facebook app, still i get same error.
I have also tried adding the random host name which i created to the /etc/hosts file in the windows.
Could anyone please help me why i am not able to see the .html page that has to be rendered by the ConnectController automatically ?
I finally got the answer.
it is we need to additional parameter in the application.properties file which is
"spring.social.auto_connection_views=true
along with the id and secret.
spring.social.facebook.appId=
spring.social.facebook.appSecret=
this property was not mentioned in the tutorials. finally this worked. :)
"
Had the exact same issue. spring.social.auto-connection-views: true in the application.yml (or .parameter equivalent) does indeed solve it, but then the default facebookConnect.html and facebookConnected.html are being used.
I solved it by removing the above application parameter and simply adding Thymeleaf tempting engine to the pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
And then you can use your own facebookConnect.html and facebookConnected.html located at src/main/resources/templates/connect/
Hope it can help.

Spring messaging websockets - how to call setMessageCodec

I am trying to use Spring websockets with Genson instead of Jackson. When I try and connect from a client I get the following:
java.lang.IllegalStateException: A SockJsMessageCodec is required but not available: Add Jackson 2 to the classpath, or configure a custom SockJsMessageCodec.
It would appear I need to set a custom message codec.
I can see that a .setMessageCodec method appears on the TransportHandlingSockJsService but I can't see anywhere in the configuration options where I can actually set it.
I think the the .setMessageCodec method should be present on the SockJsServiceRegistration class so it can be set from configuration...but it isn't...any ideas?
EDIT: I believe this is a bug so have raised: https://jira.spring.io/browse/SPR-12091
Have a look at this issue https://jira.spring.io/browse/SPR-11184.
It looks like that you could implement it by overriding the configureMessageConverters method in WebSocketMessageBrokerConfigurer.

Resources