本文整理了Java中javax.ws.rs.ext.Provider
类的一些代码示例,展示了Provider
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Provider
类的具体详情如下:
包路径:javax.ws.rs.ext.Provider
类名称:Provider
暂无
代码示例来源:origin: jersey/jersey
@Provider
@Consumes("text/plain")
@Produces("text/plain")
public static class TextPlain extends ClipboardDataProvider {
@Override
public void writeTo(final Object t, final Class type, final Type genericType, final Annotation[] annotations,
final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream)
throws IOException, WebApplicationException {
entityStream.write(t.toString().getBytes(MessageUtils.getCharset(mediaType)));
}
@Override
public Object readFrom(final Class type, final Type genericType, final Annotation[] annotations,
final MediaType mediaType, final MultivaluedMap httpHeaders, final InputStream entityStream)
throws IOException, WebApplicationException {
return new ClipboardData(readStringFromStream(entityStream, MessageUtils.getCharset(mediaType)));
}
}
代码示例来源:origin: dropwizard/dropwizard
@Provider
@Produces(MediaType.WILDCARD)
public class OptionalIntMessageBodyWriter implements MessageBodyWriter<OptionalInt> {
// Jersey ignores this
@Override
public long getSize(OptionalInt entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return OptionalInt.class.isAssignableFrom(type);
}
@Override
public void writeTo(OptionalInt entity,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
if (!entity.isPresent()) {
throw EmptyOptionalException.INSTANCE;
}
entityStream.write(Integer.toString(entity.getAsInt()).getBytes(StandardCharsets.US_ASCII));
}
}
代码示例来源:origin: resteasy/Resteasy
@Provider
@Consumes("multipart/related")
public class MultipartRelatedReader implements
MessageBodyReader<MultipartRelatedInput>
protected @Context Providers workers;
代码示例来源:origin: Netflix/conductor
@Provider
public class WebAppExceptionMapper implements ExceptionMapper<WebApplicationException> {
@Context
private UriInfo uriInfo;
代码示例来源:origin: dropwizard/dropwizard
@Provider
@Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_XHTML_XML})
public class ViewMessageBodyWriter implements MessageBodyWriter<View> {
@Context
@Nullable
private HttpHeaders headers;
代码示例来源:origin: dropwizard/dropwizard
@Provider
public class DateNotSpecifiedFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
final String dateHeader = requestContext.getHeaderString(HttpHeaders.DATE);
if (dateHeader == null) {
throw new WebApplicationException(new IllegalArgumentException("Date Header was not specified"),
Response.Status.BAD_REQUEST);
}
}
}
代码示例来源:origin: apache/hbase
@Provider
@Consumes({Constants.MIMETYPE_PROTOBUF, Constants.MIMETYPE_PROTOBUF_IETF})
@InterfaceAudience.Private
public class ProtobufMessageBodyConsumer
代码示例来源:origin: dropwizard/dropwizard
@Provider
@Produces(MediaType.WILDCARD)
public class OptionalLongMessageBodyWriter implements MessageBodyWriter<OptionalLong> {
// Jersey ignores this
@Override
public long getSize(OptionalLong entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return OptionalLong.class.isAssignableFrom(type);
}
@Override
public void writeTo(OptionalLong entity,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
if (!entity.isPresent()) {
throw EmptyOptionalException.INSTANCE;
}
entityStream.write(Long.toString(entity.getAsLong()).getBytes(StandardCharsets.US_ASCII));
}
}
代码示例来源:origin: resteasy/Resteasy
@Provider
@Consumes("multipart/*")
public class MultipartReader implements MessageBodyReader<MultipartInput>
protected @Context Providers workers;
代码示例来源:origin: scouter-project/scouter
/**
* Created by Gun Lee(gunlee01@gmail.com) on 2017. 8. 25.
*/
@Provider
@Slf4j
public class ValidationExceptionMapper implements ExceptionMapper<javax.validation.ValidationException> {
@Context
UriInfo uriInfo;
@Override
public Response toResponse(javax.validation.ValidationException e) {
final StringBuilder strBuilder = new StringBuilder("[ValidationException] ");
for (ConstraintViolation<?> cv : ((ConstraintViolationException) e).getConstraintViolations()) {
strBuilder.append(cv.getPropertyPath().toString() + " " + cv.getMessage());
}
CommonResultView resultView = CommonResultView.fail(400, 400, strBuilder.toString(), null);
return Response.status(resultView.getStatus())
.type(MediaType.APPLICATION_JSON)
.entity(resultView).build();
}
}
代码示例来源:origin: resteasy/Resteasy
@Provider
@Produces("text/plain")
public class PKCS7SignatureTextWriter implements MessageBodyWriter<SignedOutput>
@Context
protected Providers providers;
代码示例来源:origin: dropwizard/dropwizard
@Provider
public class DateRequiredFeature implements DynamicFeature {
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
if (resourceInfo.getResourceMethod().getAnnotation(DateRequired.class) != null) {
context.register(DateNotSpecifiedFilter.class);
}
}
}
代码示例来源:origin: atomix/atomix
@Provider
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
private static class JacksonProvider implements ContextResolver<ObjectMapper> {
private final ObjectMapper mapper;
JacksonProvider(ObjectMapper mapper) {
this.mapper = mapper;
}
@Override
public ObjectMapper getContext(Class<?> type) {
return mapper;
}
}
}
代码示例来源:origin: dropwizard/dropwizard
@Provider
@Produces(MediaType.WILDCARD)
public class OptionalDoubleMessageBodyWriter implements MessageBodyWriter<OptionalDouble> {
// Jersey ignores this
@Override
public long getSize(OptionalDouble entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return -1;
}
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return OptionalDouble.class.isAssignableFrom(type);
}
@Override
public void writeTo(OptionalDouble entity,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream) throws IOException {
if (!entity.isPresent()) {
throw EmptyOptionalException.INSTANCE;
}
entityStream.write(Double.toString(entity.getAsDouble()).getBytes(StandardCharsets.US_ASCII));
}
}
代码示例来源:origin: resteasy/Resteasy
@Provider
@Consumes("multipart/related")
public class XopWithMultipartRelatedReader implements MessageBodyReader<Object>
protected @Context Providers workers;
代码示例来源:origin: apache/storm
@Provider
public class AuthorizedUserFilter implements ContainerRequestFilter {
public static IAuthorizer uiAclHandler;
@Context private ResourceInfo resourceInfo;
代码示例来源:origin: dropwizard/dropwizard
/**
* Prevents Jersey from modification Request's User-Agent header with default value,
* to escape the value conflict with Dropwizard
*/
@Provider
public class JerseyIgnoreRequestUserAgentHeaderFilter implements ClientRequestFilter {
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
((ClientRequest) requestContext).ignoreUserAgent(true);
}
}
代码示例来源:origin: jenkinsci/gitlab-plugin
/**
* @author Robin Müller
*/
@Provider
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper> {
public ObjectMapper getContext(Class<?> type) {
return new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
}
}
代码示例来源:origin: swagger-api/swagger-core
@Provider
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "application/yaml"})
public class SwaggerSerializers implements MessageBodyWriter<OpenAPI> {
static boolean prettyPrint = false;
代码示例来源:origin: resteasy/Resteasy
@Provider
@Consumes("multipart/*")
public class ListMultipartReader implements MessageBodyReader<List<?>> {
protected @Context Providers workers;
内容来源于网络,如有侵权,请联系作者删除!