cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: CXF and swagger
Date Tue, 04 Jun 2013 14:18:07 GMT
Hi
On 04/06/13 14:31, eanbiso wrote:
>
> Hi Sergey,
> the annotation that is responsible for the failure is the
>      @Path("/PubDocs.json")
>
> Removing it the endPoint works fine.
> All the annotations used in the class are the following :
>      @Path("/PubDocs.json")
>
>      @Api(value = "/PubDocs", description = "Operations about pubDocs")
>
>      @Produces({"application/json"})
>
>      public class RestPublicDocsJSON extends RestPublicDocs{}
>
I think I know what it is. CXF supports these type extensions 
(originally from JAX-RS 0.8 I think), so you do for example,

"GET http://host:port/PubDocs.json" and the runtime will replace it with

"http://host:port/PubDocs"
and set
"Accept: application/json"

I think @Path("/PubDocs")

will work with

"GET http://host:port/PubDocs.json"

Can you try it ?

I think we also need to get RequestPreprocessor configurable (which is 
where extensions like .json are checked), we have a JIRA for that

Cheers, Sergey

>
> Thanks,
>
> Andrea
>
> Date: Tue, 4 Jun 2013 02:13:05 -0700
> From: ml-node+s547215n5728690h10@n5.nabble.com
> To: bisomagic@hotmail.it
> Subject: Re: CXF and swagger
>
>
>
> 	Hi
>
> On 03/06/13 16:32, eanbiso wrote:
>
>> Hi all,
>
>> I'm trying to publish and use cxf rest endPoint adding annotations required
>
>> to use the framework com.wordnik.swagger
>
>> I tried to follow the example at
>
>> https://github.com/wordnik/swagger-core/tree/master/samples/java-jaxrs-cxf/src/main/java/com/wordnik/swagger/sample
>> with some differences: I must publish the endPoint directly from java code.
>
>> My situatios is the following...
>
>>
>
>> I have an endPoint with a simple interface like this:
>
>>
>
>>       @WebService(targetNamespace = http://com.prova.pubdocs/)
>
>>       public interface IPublic extends IPublishable{
>
>> 		
>
>>           @GET
>
>> 	@Path("/isReady")
>
>> 	@ApiOperation(value = "Check the instance is ready or not", notes =
>
>> "Returns a boolean corresponding to the instance state.", responseClass =
>
>> "boolean")
>
>> 	boolean isReady();
>
>>
>
>>       }
>
>> (the interface IPublishable specifies only the methods to publish and
>
>> unpublish the endPoints),	
>
>>
>
>> and an implementor like this:
>
>>       @WebService("RestServicePubDocs", "PubDocs")
>
>>       public class RestPublicDocs implements IPublic, IPlat1Service {
>
>>
>
>>       	@Override
>
>> 	public boolean isReady() {
>
>> 		return true;
>
>> 	}
>
>>       ....
>
>>       }
>
>>
>
>> Following the example I've also  daclared the class:
>
>>
>
>>       @Path("/PubDocs.json")
>
>>       @Api(value = "/PubDocs", description = "Operations about pubDocs")
>
>>       @Produces({"application/json"})
>
>>       public class RestPublicDocsJSON extends RestPublicDocs{}
>
>>
>
>> and then I've published the end point in a similar way:
>
>>
>
>> 	private Server publishRestServerSwagger(String addr,
>
>> 			List<Interceptor&lt;? extends Message>> inInterceptors,
>
>> 			List<Interceptor&lt;? extends Message>> outInterceptors){
>
>> 		Server simpl=null;
>
>> 		try {	
>
>> 			JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
>
>> 			sf.setServiceBean(new RestPublicDocsJSON()); //the implementor
>
>> 			sf.setServiceBean(new ApiListingResourceJSON()); //required from swagger
>
>> 			sf.setAddress(addr);
>
>> 			sf.setProvider(new JacksonJsonProvider()); //required from swagger
>
>> 			sf.setProvider(new RestExceptionHandler()); //my exception mapper
>
>> 			
>
>> 			if (inInterceptors != null) {
>
>> 				for (Interceptor<? extends Message> interceptor : inInterceptors) {
>
>> 					sf.getInInterceptors().add(interceptor);
>
>> 				}
>
>> 			}
>
>> 			if (outInterceptors != null) {
>
>> 				for (Interceptor<? extends Message> interceptor : outInterceptors) {
>
>> 					sf.getOutInterceptors().add(interceptor);
>
>> 				}
>
>> 			}
>
>> 			
>
>> 			//add new rest fault interceptor
>
>> 			sf.getOutFaultInterceptors().add(new RestFaultInterceptor());
>
>> 			//new management end
>
>> 			simpl = sf.create();
>
>> 			//disable honorKeepAlive value depending on VMArg (honorKeepAlive default
>
>> value is true)
>
>> 			log.info("Endpoint has been published on " + addr);
>
>> 		} catch (Exception e) {
>
>> 			log.warn("Error publishing endpoint: " + e.toString(), e);
>
>> 		}
>
>> 		
>
>> 		return simpl;
>
>> 	}
>
>>
>
>>
>
>> The publication seems to be successful and no exception occurs but when I
>
>> call the ws, a javax.ws.rs.WebApplicationException with status 404 and all
>
>> values null occurs.
>
>> If I remove the annotations from the RestPublicDocsJSON class the api works
>
>> properly and no exception occurs.
>
>> Someone can help me?
> I can't see what may be going wrong from the code above.
>
> In this fragment,
>
>
>   >      @Path("/PubDocs.json")
>
>   >      @Api(value = "/PubDocs", description = "Operations about pubDocs")
>
>   >      @Produces({"application/json"})
>
>   >      public class RestPublicDocsJSON extends RestPublicDocs{}
>
>
> which annotations affect the api working properly ? Are these
>
> annotations the only ones on RestPublicDocsJSON ?
>
>
> Sergey
>
>
>
>> Thanks a lot,
>
>>
>
>> Andrea
>
>>
>
>>
>
>>
>
>> --
>
>> View this message in context: http://cxf.547215.n5.nabble.com/CXF-and-swagger-tp5728644.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>>
>
>
>
> 	
> 	
> 	
> 	
>
> 	
>
> 	
> 	
> 		If you reply to this email, your message will be added to the discussion below:
> 		http://cxf.547215.n5.nabble.com/CXF-and-swagger-tp5728644p5728690.html
> 	
> 	
> 		
> 		To unsubscribe from CXF and swagger, click here.
>
> 		NAML
> 	 		 	   		
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-and-swagger-tp5728644p5728720.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Mime
View raw message