我正在使用jersey
api实现RESTful服务,并且我知道我需要注册自定义xmlWriter和xmlReader。客户端代码实现MessageBodyWriter,我需要知道ho0w在服务器端注册它,因为我得到MessageBodyProviderNotFoundException
媒体类型application / xml。
MessageBodyWriter代码
public class SendDocumentsServiceRequestXMLWriter extends BaseMessageBodyWriter implements MessageBodyWriter<SendDocumentsRequest> {
public boolean isWriteable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ) {
return type == SendDocumentsRequest.class && !mediaType.isWildcardType()
&& !mediaType.isWildcardSubtype() && mediaType.isCompatible( MediaType.valueOf( "application/xml" ) );
}
public long getSize( SendDocumentsRequest t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ) {
return 0;
}
public void writeTo( SendDocumentsRequest t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream ) throws IOException, WebApplicationException {
try {
ESignatureClientJAXBContextFactory.getMarshaller( SendDocumentsRequest.class ).marshal( t, entityStream );
} catch (Exception e) {
throw new ESignatureClientException( e );
}
}
}
我如何注册这个课程以便泽西捡起它?
由于
答案 0 :(得分:2)
将@Provider
与@Produces
或@Consumes
一起放在您的实施类上,具体取决于Writer或Reader。