cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "iris ding (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6373) CompletionCallback can not get the Throwable if error occurs in other interceptor (no serviceinvokerInterceptor)
Date Sun, 26 Apr 2015 02:27:38 GMT

    [ https://issues.apache.org/jira/browse/CXF-6373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14512834#comment-14512834
] 

iris ding commented on CXF-6373:
--------------------------------

The client: 
             //step 1
             Response response1 = client.target("http://localhost:9080/cdi11_rs20/rest/resource/clear").request().get();
	      response1.close();
	      //step 2
	      Response response = client.target("http://localhost:9080/cdi11_rs20/rest/resource/reset").request().get();
	      response.close();
             //step 3
             Future<Response> suspend = client.target("http://localhost:9080/cdi11_rs20/rest/resource/suspend").request().async().get();
             //step 4
	      Future<Response> register = client.target("http://localhost:9080/cdi11_rs20/rest/resource/register?stage=0").request().async().get();
              // step 5
	      Future<Response> exception = client.target("http://localhost:9080/cdi11_rs20/rest/resource/exception?stage=1").request().async().get();
	      Response response2 = exception.get();

	      Response suspendResponse = suspend.get();
	      suspendResponse.close();
              //step 6
	      Future<Response> error = client.target("http://localhost:9080/cdi11_rs20/rest/resource/error").request().async().get();
	      System.out.println("eeee" + error.get().readEntity(String.class));  // need to get
RunTimeException
	    


Two missied method in Resouce:

 @GET
   @Path("error")
   public String getErrorValue() {
      String name = MyCompletionCallback.getLastThrowableName();
      return name;
   }


@GET
   @Path("clear")
   public void clear() {
      for (int i = 0; i != stage.length; i++)
         stage[i].clear();
   }
		  
 @GET
   @Path("reset")
   public void resetErrorValue() {
      MyCompletionCallback.resetLastThrowableName();
   }

protected static AsyncResponse takeAsyncResponse(int stageId) {
      final ResponseBuilder error = createErrorResponseBuilder();
      AsyncResponse asyncResponse = null;
      try {
         asyncResponse = stage[stageId].take();
      } catch (InterruptedException e) {
         throw new WebApplicationException(error.entity(
                 "ArrayBlockingQueue#take").build());
      }
      return asyncResponse;
   }

   protected static final void addResponse(AsyncResponse response, String stageId) {
      int id = Integer.parseInt(stageId) + 1;
      if (id != stage.length)
         stage[id].add(response);
   }

> CompletionCallback can not get the Throwable if error occurs in other interceptor (no
serviceinvokerInterceptor)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-6373
>                 URL: https://issues.apache.org/jira/browse/CXF-6373
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.3, 3.0.4, 2.7.15
>            Reporter: iris ding
>
> //Resource class
> @Path("resource")
> public class Resource {
>    private static final AsyncResponseBlockingQueue[] step = {
>            new AsyncResponseBlockingQueue(1),
>            new AsyncResponseBlockingQueue(1),
>            new AsyncResponseBlockingQueue(1)};
>    @GET
>    @Path("suspend")
>    public void suspend(@Suspended AsyncResponse asyncResponse) {
>       step[0].add(asyncResponse);
> 	  }
> 	  
>    @GET
>    @Path("register")
>    public String registerObject(@QueryParam("step") String step) {
>       AsyncResponse async = takeAsyncResponse(step);
>       boolean b = async.register(new MyCompletionCallback()).isEmpty();
>       addResponse(async, step);
>       return b ? TRUE : FALSE;
>    }
>    
>    @GET
>    @Path("exception")
>    public String throwExceptionOnAsyncResponse(
>            @QueryParam("step") String step) {
>       System.out.println("********throwExceptionOnAsyncResponse");
>       AsyncResponse async = takeAsyncResponse(step);
>       System.out.println("*****async is not null: " + async);
>       boolean b = async.resume(new ExceptionThrowingStringBean(
>               "throw exception"));
>       System.out.println("execuet finished for resume!!!");
>       addResponse(async, step);
>       return b ? TRUE : FALSE;
>    }
>    }
>    
> ///////  StringBean
>    public class StringBean {
>    private String header;
>    public String get() {
>       return header;
>    }
>    public void set(String header) {
>       this.header = header;
>    }
>    @Override
>    public String toString() {
>       return "StringBean. To get a value, use rather #get() method.";
>    }
>    public StringBean(String header) {
>       super();
>       this.header = header;
>    }
> }
> /////// Throw Exception here
>  public class ExceptionThrowingStringBean extends StringBean {
>    public ExceptionThrowingStringBean(String header) {
>       super(header);
>    }
>    @Override
>    public String get() {
>       throw new RuntimeException(new IOException(super.get()));
>    }
> }
> ////// Register a provider to deal with StringBean, 
> // This cause we have an exception thrown in JaxrsOutInterceptor
> @Provider
> public class StringBeanEntityProvider implements MessageBodyReader<StringBean>,
>         MessageBodyWriter<StringBean> {
>    @Override
>    public boolean isWriteable(Class<?> type, Type genericType,
>                               Annotation[] annotations, MediaType mediaType) {
>       return StringBean.class.isAssignableFrom(type);
>    }
>    @Override
>    public long getSize(StringBean t, Class<?> type, Type genericType,
>                        Annotation[] annotations, MediaType mediaType) {
>       return t.get().length();
>    }
>    @Override
>    public void writeTo(StringBean t, Class<?> type, Type genericType,
>                        Annotation[] annotations, MediaType mediaType,
>                        MultivaluedMap<String, Object> httpHeaders,
>                        OutputStream entityStream) throws IOException,
>            WebApplicationException {
>       entityStream.write(t.get().getBytes());
>    }
>    @Override
>    public boolean isReadable(Class<?> type, Type genericType,
>                              Annotation[] annotations, MediaType mediaType) {
>       return isWriteable(type, genericType, annotations, mediaType);
>    }
>    @Override
>    public StringBean readFrom(Class<StringBean> type, Type genericType,
>                               Annotation[] annotations, MediaType mediaType,
>                               MultivaluedMap<String, String> httpHeaders, InputStream
entityStream)
>            throws IOException, WebApplicationException {
>       String stream = JaxrsUtil.readFromStream(entityStream);
>       StringBean bean = new StringBean(stream);
>       return bean;
>    }
> }
> //////  Need to get the exception throwed from ExceptionThrowingStringBean.get() method
in this callback
> public class MyCompletionCallback implements CompletionCallback {
>    private static String throwableName;
>    public static final String NULL = "NULL";
>    public static final String NONAME = "No name has been set yet";
>    @Override
>    public void onComplete(Throwable throwable) {
> 	   
>       throwableName = throwable == null ? NULL : throwable.getClass()
>               .getName();
>    }
>    public static final String getLastThrowableName() {
>       return throwableName;
>    }
>    public static final void resetLastThrowableName() {
>       throwableName = NONAME;
>    }
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message