406 HTTP response in REST springboot service (XML) - spring

I'm new to springboot development and JAVA, I'll be needing your help.
I have created a REST service using springboot to accept and produce message of XML format.
I have generated JAVA class files for XSD schema using JAXB plugin.
I'm able to pass the XML request to the REST service and display the values as well, but in response of service i'm getting 406 HTTP response.
I tried checking stackoverflow for any hint, i found that adding below dependency in pom will resolve the issue. When i added below dependency then i was able to get the proper XML response but then i was unable to get the input XML in the service, i want getting "NULL" object as input to service after adding dependency
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
Can you please help me and let me know how can i pass input XML request and get output XML response as well. Currently either one of the case is working for me.
Thank you

I have resolved this issue by adding #XmlRootElement annotation in all the JAXB generated java class files.
Hope this will help someone!

Related

How to consume Soap Rpc encoded in spring boot?

Hello I managed to generate classes from wsdl using axis 1.4.But I am stuck at invoking services. I tried to used WebServiceTemplate and jaxb2marshaller but there is no request class generated. So I tried created request class manually based on the generated response class. But it is getting any response from server.It says xmlrootelement is not found. So i think jaxb2marshaller is not the correct way to invoke service since it is old rpc encoded soap wsdl. Suggest me the idea to invoke service.
Update:
when using axis 1.4
I found the solution to invoke methods.It is simple 2 line code.
SomeService service=new SomeServiceLocator().getSomeServicePort();
Sample sample=service.fetchSample();

Output is not coming in JSON format when NoHandlerFoundException coming

I am using spring 4.X to develop rest api using annotation configuration. I have added servlet.setThrowExceptionIfNoHandlerFound(true) to send NoHandlerFoundException. Created one GlobalExceptionHandler to handle all exception. My question is if NoHandlerFoundException occurs than output is not coming in JSON Format. Do i need to add anything in my servlet configuration

How to define camel jetty routes for https request and pass the parameter to some api for authentication?

I want to send https consumer request using camel-jetty component and that address returns some response in JSON format, below I mention my DSL code.
from("jetty:https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__").to("stream:out");
I am getting this warning:
[WARNING]
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0 (Native Method)
at sun.nio.ch.Net.bind (Net.java:433)
at sun.nio.ch.Net.bind (Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind
But whenever I hit this HTTP URL in browser it will execute perfectly with authentication.
If anyone knows what to do to perform this action in apache camel please help me it will be very cheerful for me and others.
And how could I know which method camel using for sending a request like POST or GET.
Thank You
Could you try this instead? I'll comment each line to help understand your problem.
// endpoint to start your route. could be a http endpoint you expose via jetty, jms, vm, seda or any other option. Here I'm using the simplest one.
from("direct:start")
// logs on
.to("log:DEBUG?showBody=true&showHeaders=true")
// consume the endpoint
.to("https://someSiteAddress.com/api/control/authorizeUser?username=__&password=__"")
// log the body to the console so you could process the response later knowing what to do (the token you are mentioning should be in here.
.to("log:DEBUG?showBody=true&showHeaders=true")
.to("stream:out") //or whatever you want to
Don't forget the camel-http dependency for this example to work:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
</dependency>
Cheers!
This is also working fine.
from("direct:in")
.to("https://www.someAddress.com/api/control /authorizeUser?username=__ &password=__")
.to("stream:out");
Thanks #RicardoZanini

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-Social-facebook + Spring MVC integration

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.

Resources