Re: [Resteasy-users] Problem using RESTEasy mock framework withexception mapper

2012-09-04 Thread Bill Burke
Our queue is pretty full at the moment, Log a JIRA and we'll put it on 
our Queue.

On 9/3/2012 5:43 PM, Jim Showalter wrote:
 The response to this wasn’t exactly overwhelming. One email said the
 mock framework is going to be deprecrated, which is fine, but in the
 meantime it would be good to find the cause of this.
 A few minor changes to show that it’s tied to the exception:
 package com.foo;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 @Path(/rest/v1)
 public class FooService {
  public static boolean BLOW_UP = false;
  @GET
  @Path(/foo)
  @Produces({application/xml})
  public Foo doFoo() throws FooValidationException {
  if (BLOW_UP) {
  throw new FooValidationException(FOO);
  }
  Foo foo = new Foo();
  foo.setName(FOO);
  return foo;
  }
 }
 package com.foo;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URISyntaxException;
 import org.jboss.resteasy.core.Dispatcher;
 import org.jboss.resteasy.mock.MockDispatcherFactory;
 import org.jboss.resteasy.mock.MockHttpRequest;
 import org.jboss.resteasy.mock.MockHttpResponse;
 import
 org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory;
 public final class TestFooExceptionMapper {
  public static void main(String[] args) throws URISyntaxException,
 UnsupportedEncodingException, IOException {
  Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
 dispatcher.getRegistry().addResourceFactory(new
 POJOResourceFactory(FooService.class));
 dispatcher.getProviderFactory().addExceptionMapper(FooExceptionMapper.class);
  MockHttpRequest request;
  MockHttpResponse response;
  System.out.println(Test without exception:);
  request = MockHttpRequest.get(/rest/v1/foo);
  response = new MockHttpResponse();
  dispatcher.invoke(request, response);
  System.out.println(new
 String(((ByteArrayOutputStream)response.getOutputStream()).toByteArray(), 
 UTF-8));
  System.out.println();
  System.out.println(Test with exception:);
  request = MockHttpRequest.get(/rest/v1/foo);
  response = new MockHttpResponse();
  FooService.BLOW_UP = true;
  dispatcher.invoke(request, response);
  System.out.println(new
 String(((ByteArrayOutputStream)response.getOutputStream()).toByteArray(), 
 UTF-8));
  }
 }
 Test without exception:
 ?xml version=1.0 encoding=UTF-8
 standalone=yes?foonameFOO/name/foo
 Test with exception:
 Sep 03, 2012 2:34:37 PM org.jboss.resteasy.core.SynchronousDispatcher
 SEVERE: Failed executing GET /rest/v1/foo
 org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data
 of type: javax.servlet.http.HttpServletRequest
  at
 org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:56)
  at $Proxy18.getHeader(Unknown Source)
  at com.foo.FooExceptionMapper.toResponse(FooExceptionMapper.java:50)
  at com.foo.FooExceptionMapper.toResponse(FooExceptionMapper.java:1)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.executeExceptionMapper(SynchronousDispatcher.java:330)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:359)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:348)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:220)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:196)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:551)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:513)
  at
 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125)
  at com.foo.TestFooExceptionMapper.main(TestFooExceptionMapper.java:35)
 At the point where it blows up, it’s trying to get contextual data for
 HttpServletRequest.
 Why is it doing that when the type of mock request sent in is a subclass
 of HttpRequest? Where does it get confused about the appropriate type to
 be looking up? This seems like a bug.
 I thought about changing our POM to download resteasy-jaxrs-beta1.jar,
 which has a MockHttpServletRequest, but then our test configuration
 differs from our runtime configuration in too many ways.
 *Sent:* Monday, August 27, 2012 9:42 AM
 *To:* resteasy-users@lists.sourceforge.net
 mailto:resteasy-users@lists.sourceforge.net
 *Subject:* [Resteasy-users] Problem using RESTEasy mock framework
 withexception mapper
 RESTEasy mock framework works fine without exception mapper--request is
 received and entity is returned with expected contents.
 After registering exception mapper and forcing an exception, call fails

Re: [Resteasy-users] Problem using RESTEasy mock framework withexception mapper

2012-08-28 Thread Jim Showalter
Does anyone on this list have a pointer to a working example of RESTEasy mock + 
exception mapper? Is it known to work?--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users


Re: [Resteasy-users] Problem using RESTEasy mock framework withexception mapper

2012-08-28 Thread Bill Burke
Also, FYI, we'll probably be deprecating and then removing the mock 
framework in favor of an in-memory client executor.  So, you'll be 
building requests with JAX-RS 2.0 client api that execute directly on 
server side without going over the wire.

On 8/28/2012 4:20 PM, Jim Showalter wrote:
 Does anyone on this list have a pointer to a working example of RESTEasy
 mock + exception mapper? Is it known to work?


 --
 Live Security Virtual Conference
 Exclusive live event will cover all the ways today's security and
 threat landscape has changed and how IT managers can respond. Discussions
 will include endpoint security, mobile security and the latest in malware
 threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/



 ___
 Resteasy-users mailing list
 Resteasy-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/resteasy-users


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users


Re: [Resteasy-users] Problem using RESTEasy mock framework withexception mapper

2012-08-28 Thread Jim Showalter
I did post a working simple example--the link was in my original email on 
this topic.

Here it is again:

http://stackoverflow.com/questions/12136780/resteasy-mock-vs-exception-mapper-vs-context

-Original Message- 
From: Bill Burke
Sent: Tuesday, August 28, 2012 1:32 PM
To: resteasy-users@lists.sourceforge.net
Subject: Re: [Resteasy-users] Problem using RESTEasy mock framework 
withexception mapper

Should work.  If you have a simple case that isn't working post it and
we'll try and reproduce.

On 8/28/2012 4:20 PM, Jim Showalter wrote:
 Does anyone on this list have a pointer to a working example of RESTEasy
 mock + exception mapper? Is it known to work?


 --
 Live Security Virtual Conference
 Exclusive live event will cover all the ways today's security and
 threat landscape has changed and how IT managers can respond. Discussions
 will include endpoint security, mobile security and the latest in malware
 threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/



 ___
 Resteasy-users mailing list
 Resteasy-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/resteasy-users


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users 


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users