JAX-RS service to proxy and authenticate an HTTP request in groovy


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import javax.ws.rs.Path
  2. import javax.ws.rs.POST
  3. import javax.ws.rs.FormParam
  4.  
  5. @Path("/proxy")
  6. @POST
  7. @Path("basic_auth/")
  8. public String basic_auth(@FormParam("url") String url, @FormParam("login") String login,
  9. @FormParam("password") String password) {
  10. def encoded = "$login:$password".getBytes().encodeBase64().toString()
  11. def c= new URL(url).openConnection()
  12. c.setRequestProperty("Authorization", "Basic $encoded")
  13. return c.content.text
  14. }
  15. }

URL: http://blog.jeremi.info/entry/jax-rs-service-to-proxy-an-http-request-in-groovy

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.