[Resteasy-users] RESTEasy Client in OSGi Environment

2014-05-23 Thread Rohrberg, Timo
Hello everybody,

I am currently trying to use the RESTEasy client framework within an OSGi 
environment (Eclipse Equinox). To provide the required dependencies, I created 
a separate Eclipse Plug-In containing the required JAR libraries and exporting 
the contained packages to downstream bundles. Then, I am using the RESTEasy 
client framework as follows within my main bundle which includes the before 
mentioned bundle as required bundle:

ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client
.target( 
http://192.168.100.181:5952/RXT_RESTWebService-2.1/jobtemplates/Vitaphone 300 
BT/386340 );
RxtDevice device = target.request().get( RxtDevice.class );
System.out.println( device.getId() );

Unfortunately, I always get the following error:

javax.ws.rs.client.ResponseProcessingException: 
javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader of 
content-type application/xml and type class 
com.vitasystems.remosxt.rest.client.model.RxtDevice
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:140)
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:444)
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:165)
  at 
de.vitasystems.example.resteasy.client.Activator.start(Activator.java:25)
  at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
  at java.security.AccessController.doPrivileged(Native Method)
  at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
  at 
org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
  at 
org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
  at 
org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
  at 
org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
  at 
org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
  at 
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
  at 
org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: javax.ws.rs.ProcessingException: Unable to find a MessageBodyReader 
of content-type application/xml and type class 
com.vitasystems.remosxt.rest.client.model.RxtDevice
  at 
org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:39)
  at 
org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:73)
  at 
org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:50)
  at 
org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
  at 
org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:245)
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:179)
  at 
org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:211)
  at 
org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:104)
  ... 18 more

By debugging the included libraries, I tracked the problem down to the 
following location:

ResteasyProviderFactory.java

protected T MessageBodyReaderT resolveMessageBodyReader(ClassT type, Type 
genericType, Annotation[] annotations, MediaType mediaType, 
MediaTypeMapSortedKeyMessageBodyReader availableReaders)
{
ListSortedKeyMessageBodyReader readers = 
availableReaders.getPossible(mediaType, type);

//logger.info( getMessageBodyReader ***);
for (SortedKeyMessageBodyReader reader : readers)
{
//logger.info( matching reader:  + reader.getClass().getName());
if (reader.obj.isReadable(type, genericType, annotations, mediaType))
{
return (MessageBodyReaderT) reader.obj;
}
}
return null;
}

The problem is a little weired: The readers list of MessageBodyReader instances 

Re: [Resteasy-users] Injecting an EJB in a Resteasy Resource authenticated with OAuth 2.0

2014-05-23 Thread Bill Burke
I didn't actually solve this for the resteasy oauth implementation.  We 
solved it in Keycloak, but I haven't been able to get back to resteasy 
to fix the problem there.

On 5/22/2014 11:25 AM, JOSÉ INÁCIO DA SILVA JÚNIOR wrote:
 Hi!

 My Resteasy/OAuth2.0 authentication environment is working perfect.
 Everything is fine when I work in a web context.
 But when I inject an EJB in a resteasy resource, I get the following 
 exception:

 12:22:32,027 DEBUG [org.jboss.security.auth.spi.UsersRolesLoginModule] 
 (http--10.0.21.52-8443-5) Bad password for username=customer-portal
 12:22:32,027 ERROR 
 [org.jboss.security.authentication.JBossCachedAuthenticationManager] 
 (http--10.0.21.52-8443-5) Login failure: 
 javax.security.auth.login.FailedLoginException: Password Incorrect/Password 
 Required
   at 
 org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:270)
  [picketbox-4.0.7.Final.jar:4.0.7.Final]
   at 
 org.jboss.security.auth.spi.UsersRolesLoginModule.login(UsersRolesLoginModule.java:155)
  [picketbox-4.0.7.Final.jar:4.0.7.Final]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
 [rt.jar:1.7.0_55]
   at 
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
 [rt.jar:1.7.0_55]
   at 
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  [rt.jar:1.7.0_55]
   at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_55]
   at javax.security.auth.login.LoginContext.invoke(LoginContext.java:762) 
 [rt.jar:1.7.0_55]
   at 
 javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) 
 [rt.jar:1.7.0_55]
   at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690) 
 [rt.jar:1.7.0_55]
   at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688) 
 [rt.jar:1.7.0_55]
   at java.security.AccessController.doPrivileged(Native Method) 
 [rt.jar:1.7.0_55]
   at 
 javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687) 
 [rt.jar:1.7.0_55]
   at javax.security.auth.login.LoginContext.login(LoginContext.java:595) 
 [rt.jar:1.7.0_55]
   at 
 org.jboss.security.authentication.JBossCachedAuthenticationManager.defaultLogin(JBossCachedAuthenticationManager.java:449)
  [picketbox-infinispan-4.0.7.Final.jar:4.0.7.Final]
   at 
 org.jboss.security.authentication.JBossCachedAuthenticationManager.proceedWithJaasLogin(JBossCachedAuthenticationManager.java:383)
  [picketbox-infinispan-4.0.7.Final.jar:4.0.7.Final]
   at 
 org.jboss.security.authentication.JBossCachedAuthenticationManager.authenticate(JBossCachedAuthenticationManager.java:371)
  [picketbox-infinispan-4.0.7.Final.jar:4.0.7.Final]
   at 
 org.jboss.security.authentication.JBossCachedAuthenticationManager.isValid(JBossCachedAuthenticationManager.java:160)
  [picketbox-infinispan-4.0.7.Final.jar:4.0.7.Final]
   at 
 org.jboss.as.security.service.SimpleSecurityManager.authenticate(SimpleSecurityManager.java:306)
  [jboss-as-security-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.as.security.service.SimpleSecurityManager.push(SimpleSecurityManager.java:272)
  [jboss-as-security-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:49)
  [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:45)
  [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at java.security.AccessController.doPrivileged(Native Method) 
 [rt.jar:1.7.0_55]
   at 
 org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:74)
  [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 
 [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at 
 org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
  [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 
 [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at 
 org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
  [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 
 [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at 
 org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32)
  [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
   at 
 org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) 
 [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
   at 
 org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
  

Re: [Resteasy-users] RESTEasy Client in OSGi Environment

2014-05-23 Thread Bill Burke
I know nothing about OSGi.

My guess is that Resteasy automatic provider lookup is not working.  The 
way it works is that it does a 
Classloader.getResources(META-INF/javax.ws.rs.ext.Providers) and 
iterates througha nd loads all those files.  Those files contain Java 
class names which represent the providers.

On 5/23/2014 9:26 AM, Rohrberg, Timo wrote:
 Hello everybody,

 I am currently trying to use the RESTEasy client framework within an
 OSGi environment (Eclipse Equinox). To provide the required
 dependencies, I created a separate Eclipse Plug-In containing the
 required JAR libraries and exporting the contained packages to
 downstream bundles. Then, I am using the RESTEasy client framework as
 follows within my main bundle which includes the before mentioned bundle
 as required bundle:

 ResteasyClient client = *new*ResteasyClientBuilder().build();

 ResteasyWebTarget target = client

 .target(
 _http://192.168.100.181:5952/RXT_RESTWebService-2.1/jobtemplates/Vitaphone
 300 BT/386340_);

 RxtDevice device = target.request().get( RxtDevice.*class*);

 System./out/.println( device.getId() );

 Unfortunately, I always get the following error:

 _javax.ws.rs.client.ResponseProcessingException_:
 _javax.ws.rs.ProcessingException_: Unable to find a MessageBodyReader of
 content-type application/xml and type class
 com.vitasystems.remosxt.rest.client.model.RxtDevice

at
 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(_ClientInvocation.java:140_)

at
 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(_ClientInvocation.java:444_)

at
 org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(_ClientInvocationBuilder.java:165_)

at
 de.vitasystems.example.resteasy.client.Activator.start(_Activator.java:25_)

at
 org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(_BundleContextImpl.java:711_)

at java.security.AccessController.doPrivileged(_Native Method_)

at
 org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(_BundleContextImpl.java:702_)

at
 org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(_BundleContextImpl.java:683_)

at
 org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(_BundleHost.java:381_)

at
 org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(_AbstractBundle.java:390_)

at
 org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(_Framework.java:1176_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(_StartLevelManager.java:559_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(_StartLevelManager.java:544_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(_StartLevelManager.java:457_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(_StartLevelManager.java:243_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(_StartLevelManager.java:438_)

at
 org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(_StartLevelManager.java:1_)

at
 org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(_EventManager.java:230_)

at
 org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(_EventManager.java:340_)

 Caused by: _javax.ws.rs.ProcessingException_: Unable to find a
 MessageBodyReader of content-type application/xml and type class
 com.vitasystems.remosxt.rest.client.model.RxtDevice

at
 org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(_ClientReaderInterceptorContext.java:39_)

at
 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(_AbstractReaderInterceptorContext.java:73_)

at
 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(_AbstractReaderInterceptorContext.java:50_)

at
 org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(_GZIPDecodingInterceptor.java:59_)

at
 org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(_AbstractReaderInterceptorContext.java:53_)

at
 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(_ClientResponse.java:245_)

at
 org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(_ClientResponse.java:179_)

at
 org.jboss.resteasy.specimpl.BuiltResponse.readEntity(_BuiltResponse.java:211_)

at
 org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(_ClientInvocation.java:104_)

... 18 more

 By debugging the included libraries, I tracked the problem down to the
 following location:

 ResteasyProviderFactory.java

 *protected*T MessageBodyReaderT resolveMessageBodyReader(ClassT
 type, Type genericType, Annotation[] annotations, MediaType mediaType,