Java Code Examples for javax.ws.rs.core.MediaType#toString()

The following examples show how to use javax.ws.rs.core.MediaType#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotifierInfoCatalogResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers/{id}")
@Timed
public Response addOrUpdateNotifierInfo(@PathParam("id") Long id,
                                        @FormDataParam("notifierJarFile") final InputStream inputStream,
                                        @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                        @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                        @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier);
    return WSUtils.respondEntity(newNotifier, CREATED);
}
 
Example 2
Source File: UDFCatalogResource.java    From streamline with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new UDF.
 * <p>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/udfs' -F udfJarFile=/tmp/foo-function.jar
 * -F udfConfig='{"name":"Foo", "description": "testing", "type":"FUNCTION", "className":"com.test.Foo"};type=application/json'
 * </p>
 */
@Timed
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs")
public Response addUDF(@FormDataParam("udfJarFile") final InputStream inputStream,
                       @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader,
                       @FormDataParam("udfConfig") final FormDataBodyPart udfConfig,
                       @FormDataParam("builtin") final boolean builtin,
                       @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_UDF_ADMIN);
    MediaType mediaType = udfConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    UDF udf = udfConfig.getValueAs(UDF.class);
    processUdf(inputStream, udf, true, builtin);
    UDF createdUdf = catalogService.addUDF(udf);
    SecurityUtil.addAcl(authorizer, securityContext, UDF.NAMESPACE, createdUdf.getId(), EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdUdf, CREATED);
}
 
Example 3
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Supplier<String> matchMessageLogSupplier(OperationResourceInfo ori,
    String path, String httpMethod, MediaType requestType, List<MediaType> acceptContentTypes,
    boolean added) {
    org.apache.cxf.common.i18n.Message errorMsg = added
        ? new org.apache.cxf.common.i18n.Message("OPER_SELECTED_POSSIBLY",
                                               BUNDLE, ori.getMethodToInvoke().getName())
        : new org.apache.cxf.common.i18n.Message("OPER_NO_MATCH",
                                               BUNDLE,
                                               ori.getMethodToInvoke().getName(),
                                               path,
                                               ori.getURITemplate().getValue(),
                                               httpMethod,
                                               ori.getHttpMethod(),
                                               requestType.toString(),
                                               convertTypesToString(ori.getConsumeTypes()),
                                               convertTypesToString(acceptContentTypes),
                                               convertTypesToString(ori.getProduceTypes()));
    return () -> errorMsg.toString();
}
 
Example 4
Source File: AttachmentUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static Attachment getMultipart(Multipart id,
                                      MediaType mt,
                                      List<Attachment> infos) throws IOException {

    if (id != null) {
        for (Attachment a : infos) {
            if (matchAttachmentId(a, id)) {
                checkMediaTypes(a.getContentType(), id.type());
                return a;
            }
        }
        if (id.required()) {
            org.apache.cxf.common.i18n.Message errorMsg =
                new org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND",
                                                       BUNDLE,
                                                       id.value(),
                                                       mt.toString());
            LOG.warning(errorMsg.toString());
            throw ExceptionUtils.toBadRequestException(
                      new MultipartReadException(id.value(), id.type(), errorMsg.toString()), null);
        }
        return null;
    }

    return !infos.isEmpty() ? infos.get(0) : null;
}
 
Example 5
Source File: DevfileEntityProvider.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public DevfileDto readFrom(
    Class<DevfileDto> type,
    Type genericType,
    Annotation[] annotations,
    MediaType mediaType,
    MultivaluedMap<String, String> httpHeaders,
    InputStream entityStream)
    throws IOException, WebApplicationException {

  try {
    if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) {
      return asDto(
          devfileManager.parseJson(
              CharStreams.toString(
                  new InputStreamReader(entityStream, getCharsetOrUtf8(mediaType)))));
    } else if (mediaType.isCompatible(MediaType.valueOf("text/yaml"))
        || mediaType.isCompatible(MediaType.valueOf("text/x-yaml"))) {
      return asDto(
          devfileManager.parseYaml(
              CharStreams.toString(
                  new InputStreamReader(entityStream, getCharsetOrUtf8(mediaType)))));
    }
  } catch (DevfileFormatException e) {
    throw new BadRequestException(e.getMessage());
  }
  throw new NotSupportedException("Unknown media type " + mediaType.toString());
}
 
Example 6
Source File: NotifierInfoCatalogResource.java    From streamline with Apache License 2.0 5 votes vote down vote up
/**
 * Sample request :
 * <pre>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/notifiers' -F notifierJarFile=/tmp/email-notifier.jar
 * -F notifierConfig='{
 *  "name":"email_notifier",
 *  "description": "testing",
 * "className":"com.hortonworks.streamline.streams.notifiers.EmailNotifier",
 *   "properties": {
 *     "username": "[email protected]",
 *     "password": "testing12",
 *     "host": "smtp.gmail.com",
 *     "port": "587",
 *     "starttls": "true",
 *     "debug": "true"
 *     },
 *   "fieldValues": {
 *     "from": "[email protected]",
 *     "to": "[email protected]",
 *     "subject": "Testing email notifications",
 *     "contentType": "text/plain",
 *     "body": "default body"
 *     }
 * };type=application/json'
 * </pre>
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers")
@Timed
public Response addNotifier(@FormDataParam("notifierJarFile") final InputStream inputStream,
                            @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                            @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                            @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_NOTIFIER_ADMIN);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    Collection<Notifier> existing = null;
    existing = catalogService.listNotifierInfos(Collections.singletonList(new QueryParam(Notifier.NOTIFIER_NAME, notifier.getName())));
    if (existing != null && !existing.isEmpty()) {
        LOG.warn("Received a post request for an already registered notifier. Not creating entity for " + notifier);
        return WSUtils.respondEntity(notifier, CONFLICT);
    }
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier createdNotifier = catalogService.addNotifierInfo(notifier);
    SecurityUtil.addAcl(authorizer, securityContext, Notifier.NAMESPACE, createdNotifier.getId(),
            EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdNotifier, CREATED);
}
 
Example 7
Source File: StreamingDataSourceEntityProvider.java    From everrest with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public DataSource readFrom(Class<DataSource> type,
                           Type genericType,
                           Annotation[] annotations,
                           MediaType mediaType,
                           MultivaluedMap<String, String> httpHeaders,
                           InputStream entityStream) throws IOException {
    return new StreamingDataSource(entityStream, mediaType == null ? null : mediaType.toString());
}
 
Example 8
Source File: UDFCatalogResource.java    From streamline with Apache License 2.0 4 votes vote down vote up
/**
 * Update a udf.
 * <p>
 *     curl -X PUT 'http://localhost:8080/api/v1/catalog/udfs/34'
 *     -F udfJarFile=@/tmp/streams-functions-0.6.0-SNAPSHOT.jar
 *     -F udfConfig='{"name":"stddev", "description": "stddev",
 *                   "type":"AGGREGATE", "className":"com.hortonworks.streamline.streams.rule.udaf.Stddev"};type=application/json'
 * </p>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 48,
 *     "name": "SUBSTRING",
 *     "description": "Substring",
 *     "type": "FUNCTION",
 *     "className": "builtin"
 *   }
 * }
 * </pre>
 */
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs/{id}")
@Timed
public Response addOrUpdateUDF(@PathParam("id") Long udfId,
                               @FormDataParam("udfJarFile") final InputStream inputStream,
                               @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader,
                               @FormDataParam("udfConfig") final FormDataBodyPart udfConfig,
                               @FormDataParam("builtin") final boolean builtin,
                               @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkPermissions(authorizer, securityContext, UDF.NAMESPACE, udfId, WRITE);
    MediaType mediaType = udfConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    UDF udf = udfConfig.getValueAs(UDF.class);
    processUdf(inputStream, udf, false, builtin);
    UDF newUdf = catalogService.addOrUpdateUDF(udfId, udf);
    return WSUtils.respondEntity(newUdf, CREATED);
}
 
Example 9
Source File: ProviderCache.java    From cxf with Apache License 2.0 4 votes vote down vote up
private String getKey(Class<?> type, MediaType mt) {
    return type.getName() + "-" + mt.toString();
}
 
Example 10
Source File: Request.java    From verigreen with Apache License 2.0 2 votes vote down vote up
public Request(String uri, Object entity, MediaType mediaType) {
    
    this(uri, entity, mediaType.toString(), null, null);
}