Posted By

jeremi on 01/26/10


Tagged

groovy proxy JSR-311 JAX-RS exo exoplatform


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

javadude


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


 / Published in: Groovy
 

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

  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. }

Report this snippet  

You need to login to post a comment.