[keycloak-user] Custom rest endpoint
Mariusz Chruscielewski - Info.nl
mariusz at info.nl
Thu Sep 29 05:41:11 EDT 2016
Google didn’t help.
There was 2 things, first of all, I should return Response object (not String):
@Path("/{action}")
@GET
public Response get(@PathParam("action") String action) {
String json = "{\"test\" : \"" + action + "\"}";
return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build();
}
Second thing is that you need to add dependency to module (during install) because you will get ClassNotFoundException:
--dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-services,javax.servlet.api,org.jboss.resteasy.resteasy-jaxrs,javax.ws.rs.api"
I hope this will help other people.
Mariusz Chruścielewski
From: Stian Thorgersen [mailto:sthorger at redhat.com]
Sent: donderdag 29 september 2016 11:33
To: Stian Thorgersen <stian at redhat.com>
Cc: Mariusz Chruscielewski - Info.nl <mariusz at info.nl>; keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Custom rest endpoint
Also, try Googling "RESTEASY003815: Subresource for target class has no jax-rs annotations". I'm sure others has had that issue with RestEasy/JAX-RS before.
On 29 September 2016 at 11:31, Stian Thorgersen <sthorger at redhat.com<mailto:sthorger at redhat.com>> wrote:
Did you try the example does it work?
On 28 September 2016 at 13:35, Mariusz Chruscielewski - Info.nl <mariusz at info.nl<mailto:mariusz at info.nl>> wrote:
I can’t make REST endpoint work, I’m using exactly code supplied in example, I tried also to check how standard endpoints in keycloak code are created, all looks similar:
/**
* @author <a href="mailto:sthorger at redhat.com<mailto:sthorger at redhat.com>">Stian Thorgersen</a>
*/
public class HelloResourceProvider implements RealmResourceProvider {
private KeycloakSession session;
public HelloResourceProvider(KeycloakSession session) {
this.session = session;
}
@GET
@Produces(MediaType.TEXT_HTML)
@Path("/{action}")
public String get(@PathParam("action") String action) {
//String requestUri = session.getContext().getUri().getRequestUri().toString();
String title = "APP_REQUEST";
if (action.equals("auth")) {
title = "AUTH_RESPONSE";
} else if (action.equals("logout")) {
title = "LOGOUT_REQUEST";
}
StringBuilder sb = new StringBuilder();
sb.append("<html><head><title>" + title + "</title></head><body>");
UriBuilder base = UriBuilder.fromUri("http://localhost:8180/auth");
sb.append("<a href=\"" + RealmsResource.accountUrl(base).build("test").toString() + "\" id=\"account\">account</a>");
sb.append("</body></html>");
return sb.toString();
}
@Override
public Object getResource() {
return this;
}
@Override
public void close() {
}
}
But I’m still getting:
RESTEASY003815: Subresource for target class has no jax-rs annotations.: nl.vi.keycloak.providers.rest.HelloResourceProvider
Can you please help me? Thanks
Kind Regards,
Mariusz Chruscielewski
Software Engineer | mariusz at info.nl<mailto:mariusz at info.nl>
+31 (0)20 530 91 13 | +48 695 555 292<tel:%2B48%20695%20555%20292>
info.nl <http://www.info.nl/> making platforms work<http://www.info.nl/nl?utm_source=e-mail_sig&utm_medium=e-mail&utm_term=connecting_the_dots&utm_campaign=info_sig>
Sint Antoniesbreestraat 16 | 1011 HB Amsterdam | +31 (0)20 530 91 11
Facebook<https://www.facebook.com/infonl> | Twitter<https://twitter.com/infonl> | LinkedIn<https://www.linkedin.com/company/info-nl> | Google+<https://plus.google.com/+infonl/>
_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org<mailto:keycloak-user at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/keycloak-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160929/b4292032/attachment-0001.html
More information about the keycloak-user
mailing list