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

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

Related

How to map path elements to method parameter in spring cloud function web

I'm working on a Microservice that receives webhooks, the idea is to use path variables for some processing down stream,
/webhooks/{foo}/{bar}/{baz}
for example
/webhooks/sony/pony/tony would populate foo=sony; bar=pony; baz=tony.
Can't figure how to make it work in spring cloud function web.
This was never the purpose of spring-cloud-function to replace spring-mvc etc.
Also, Function has only one argument, so what you can do is have Function<Message, ...> and we translate HTTP request into Message where body will turn into payload and HTTP headers will turn into Message headers.

406 HTTP response in REST springboot service (XML)

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!

404 when do logout in Spring Security Rest Plugin for Grails

I'm setting the security system on my project (Grails - Angularjs) with Spring Security Rest Plugin v1.5.4 (using spring security core 2.0.0) for Grails 2.4.4. Doc about this plugin can be found here.
I'm testing the login and logout with postman chrome rest client and I'm able to do a login OK, but I'm getting a 404 when I do logout.
In the documentation clearly says:
The logout filter exposes an endpoint for deleting tokens. It will
read the token from an HTTP header. If found, will delete it from the
storage, sending a 200 response. Otherwise, it will send a 404
response
You can configure it in Config.groovy using this properties:
Config key...................................................................................Default
value
grails.plugin.springsecurity.rest.logout.endpointUrl....................../api/logout
grails.plugin.springsecurity.rest.token.validation.headerName....X-Auth-Token
So, after doing a login successfully, I tried to do a logout to that url (my_host_url/api/logout) with a GET method and sending a header X-Auth-Token with the token I got previously from login.
But I keep getting a 404. See image below
Edit: I'm setting the chain map like this (in order to get a stateless behavior):
grails.plugin.springsecurity.filterChain.chainMap = [
'/api/**': 'JOINED_FILTERS,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter,-rememberMeAuthenticationFilter', // Stateless chain
'/**': 'JOINED_FILTERS,-restTokenValidationFilter,-restExceptionTranslationFilter' // Traditional chain
]
So. What am I doing wrong here, or what am I missing?
Thanks in advance!
You missed another excerpt from the docs. It's a warning message literally before the chunk you quoted, and says:
Logout is not possible when using JWT tokens (the default strategy), as no state is kept in the server.
If you still want to have logout, you can provide your own implementation by creating a subclass of JwtTokenStorageService and overriding the methods storeToken and removeToken. Then, register your implementation in resources.groovy as tokenStorageService.

Apache Tomcat 7 CORS Filter IE8, IE9 always return 403 response

I was trying to implement Cross-domain requesting using AJAX CORS.
I enabled my server side by using CORS Filter of tomcat.
But for IE8,9, tomcat always returns 403.
Are there any ideas about this question?
First of all, you should specify what request method you are using and add source code examples.
I can only guess, but if you are using POST method and default apache CorsFilter, the issue is in the following:
for CORS requests IE8 and IE9 use XDomainRequest object, which doesn't appear to send any Content-Type header at all and in turn, CorsFilter considers this request as INVALID (see checkRequestType method).
Possible solution is to add your own CorsFilter based on apache version that handles empty Content-Type.
Cors Filter here (http://software.dzhuvinov.com/cors-filter.html) is a good alternative that has no such problem.
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>2.1.2</version>
</dependency>

regarding CSRF Filter in Tomcat 7 url encoding

I work on a web application that is vulnerable to CSRF(Cross Site Request Forgery) attack. Tomcat 7 has a CSRF prevention filter. I went through the description to configure this filter.
This filter expects that we call HttpServletResponse#encodeRedirectURL(String) or HttpServletResponse#encodeURL(String).
However, I see that in my application we are not using the above mentioned methods. We forward the response using mapping.findForward(target); without touching the request or response object. Can you please let me know how or where can I integrate encodeURL() or encodeRedirectURL() methods in my code?
Any help in this regard is appreciated.
Thanks,
You can Write a Servlet and map all urls (/*) to this servlet in your web.xml file. now you can use encodeUrl method through HttpServletResponse.

Resources