org.apache.hc.core5.http.ContentType Java Examples

The following examples show how to use org.apache.hc.core5.http.ContentType. 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: AsyncApacheHttp5Client.java    From feign with Apache License 2.0 6 votes vote down vote up
private ContentType getContentType(Request request) {
  ContentType contentType = null;
  for (final Map.Entry<String, Collection<String>> entry : request.headers().entrySet()) {
    if (entry.getKey().equalsIgnoreCase("Content-Type")) {
      final Collection<String> values = entry.getValue();
      if (values != null && !values.isEmpty()) {
        contentType = ContentType.parse(values.iterator().next());
        if (contentType.getCharset() == null) {
          contentType = contentType.withCharset(request.charset());
        }
        break;
      }
    }
  }
  return contentType;
}
 
Example #2
Source File: Http5FileContentInfoFactory.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    String contentMimeType = null;
    String contentCharset = null;

    try (final Http5FileObject<Http5FileSystem> http4File = (Http5FileObject<Http5FileSystem>) FileObjectUtils
            .getAbstractFileObject(fileContent.getFile())) {
        final HttpResponse lastHeadResponse = http4File.getLastHeadResponse();

        final Header header = lastHeadResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE);

        if (header != null) {
            final ContentType contentType = ContentType.parse(header.getValue());
            contentMimeType = contentType.getMimeType();

            if (contentType.getCharset() != null) {
                contentCharset = contentType.getCharset().name();
            }
        }

        return new DefaultFileContentInfo(contentMimeType, contentCharset);
    } catch (final IOException e) {
        throw new FileSystemException(e);
    }
}
 
Example #3
Source File: JenkinsPipelineManager.java    From testgrid with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new pipeline job in Jenkins server by calling its REST API.
 * @param configXml configuration file for the new job.
 * @param jobName name for the new job.
 * @return URL to check the status of the new job.
 */
public String createNewPipelineJob(String configXml, String jobName) throws TestGridException, IOException {
    Response response = Request
            .Post(ConfigurationContext.getProperty(
                    ConfigurationContext.ConfigurationProperties.JENKINS_HOST) + "/createItem?name=" + jobName)
            .addHeader(HttpHeaders.USER_AGENT, USER_AGENT)
            .addHeader(HttpHeaders.AUTHORIZATION, "Basic " +
                    ConfigurationContext.getProperty(
                            ConfigurationContext.ConfigurationProperties.JENKINS_USER_AUTH_KEY))
            .addHeader(Constants.JENKINS_CRUMB_HEADER_NAME, getCrumb())
            .addHeader(HttpHeaders.CONTENT_TYPE, "application/xml")
            .bodyString(configXml, ContentType.APPLICATION_XML)
            .execute();
    if (response.returnResponse().getCode() == HttpStatus.SC_OK) {
        return buildJobSpecificUrl(jobName);
    } else {
        logger.error("Jenkins server error for creating job " + jobName + " " +
                response.returnResponse().getCode());
        throw new TestGridException("Can not create new job in Jenkins. Received " +
                response.returnResponse().getCode() + " " +
                response.returnContent().asString() + ".");
    }
}
 
Example #4
Source File: PauseUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link PauseUsersPlaybackRequest}.
 */
@Override
public PauseUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/pause");
  return new PauseUsersPlaybackRequest(this);
}
 
Example #5
Source File: ClientCredentialsRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A {@link ClientCredentialsRequest}.
 */
public ClientCredentialsRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new ClientCredentialsRequest(this);
}
 
Example #6
Source File: AuthorizationCodeRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return An {@link AuthorizationCodeRequest}.
 */
public AuthorizationCodeRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new AuthorizationCodeRequest(this);
}
 
Example #7
Source File: AuthorizationCodeRefreshRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return An {@link AuthorizationCodeRefreshRequest}.
 */
public AuthorizationCodeRefreshRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new AuthorizationCodeRefreshRequest(this);
}
 
Example #8
Source File: SaveShowsForCurrentUserRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SaveShowsForCurrentUserRequest}.
 */
@Override
public SaveShowsForCurrentUserRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/shows");
  return new SaveShowsForCurrentUserRequest(this);
}
 
Example #9
Source File: SaveAlbumsForCurrentUserRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SaveAlbumsForCurrentUserRequest}.
 */
@Override
public SaveAlbumsForCurrentUserRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/albums");
  return new SaveAlbumsForCurrentUserRequest(this);
}
 
Example #10
Source File: SaveTracksForUserRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SaveTracksForUserRequest}.
 */
@Override
public SaveTracksForUserRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/tracks");
  return new SaveTracksForUserRequest(this);
}
 
Example #11
Source File: FollowArtistsOrUsersRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link FollowArtistsOrUsersRequest}.
 */
@Override
public FollowArtistsOrUsersRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/following");
  return new FollowArtistsOrUsersRequest(this);
}
 
Example #12
Source File: FollowPlaylistRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link FollowPlaylistRequest}.
 */
@Override
public FollowPlaylistRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}/followers");
  return new FollowPlaylistRequest(this);
}
 
Example #13
Source File: FollowPlaylistRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link FollowPlaylistRequest}.
 */
@Override
public FollowPlaylistRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/users/{owner_id}/playlists/{playlist_id}/followers");
  return new FollowPlaylistRequest(this);
}
 
Example #14
Source File: TransferUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link TransferUsersPlaybackRequest}.
 */
@Override
public TransferUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player");
  return new TransferUsersPlaybackRequest(this);
}
 
Example #15
Source File: AddItemToUsersPlaybackQueueRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link AddItemToUsersPlaybackQueueRequest}.
 */
@Override
public AddItemToUsersPlaybackQueueRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/queue");
  return new AddItemToUsersPlaybackQueueRequest(this);
}
 
Example #16
Source File: SkipUsersPlaybackToPreviousTrackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SkipUsersPlaybackToPreviousTrackRequest}.
 */
@Override
public SkipUsersPlaybackToPreviousTrackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/previous");
  return new SkipUsersPlaybackToPreviousTrackRequest(this);
}
 
Example #17
Source File: StartResumeUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link StartResumeUsersPlaybackRequest}.
 */
@Override
public StartResumeUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/play");
  return new StartResumeUsersPlaybackRequest(this);
}
 
Example #18
Source File: SetVolumeForUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The build method.
 *
 * @return A custom {@link SetVolumeForUsersPlaybackRequest}.
 */
@Override
public SetVolumeForUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/volume");
  return new SetVolumeForUsersPlaybackRequest(this);
}
 
Example #19
Source File: SkipUsersPlaybackToNextTrackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SkipUsersPlaybackToNextTrackRequest}.
 */
@Override
public SkipUsersPlaybackToNextTrackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/next");
  return new SkipUsersPlaybackToNextTrackRequest(this);
}
 
Example #20
Source File: SeekToPositionInCurrentlyPlayingTrackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SeekToPositionInCurrentlyPlayingTrackRequest}.
 */
@Override
public SeekToPositionInCurrentlyPlayingTrackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/seek");
  return new SeekToPositionInCurrentlyPlayingTrackRequest(this);
}
 
Example #21
Source File: SetRepeatModeOnUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link SetRepeatModeOnUsersPlaybackRequest}.
 */
@Override
public SetRepeatModeOnUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/repeat");
  return new SetRepeatModeOnUsersPlaybackRequest(this);
}
 
Example #22
Source File: ToggleShuffleForUsersPlaybackRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link ToggleShuffleForUsersPlaybackRequest}.
 */
@Override
public ToggleShuffleForUsersPlaybackRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/me/player/shuffle");
  return new ToggleShuffleForUsersPlaybackRequest(this);
}
 
Example #23
Source File: UploadCustomPlaylistCoverImageRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link UploadCustomPlaylistCoverImageRequest}.
 */
@Override
public UploadCustomPlaylistCoverImageRequest build() {
  setContentType(ContentType.IMAGE_JPEG);
  setPath("/v1/playlists/{playlist_id}/images");
  return new UploadCustomPlaylistCoverImageRequest(this);
}
 
Example #24
Source File: AddItemsToPlaylistRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link AddItemsToPlaylistRequest}.
 */
@Override
public AddItemsToPlaylistRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}/tracks");
  return new AddItemsToPlaylistRequest(this);
}
 
Example #25
Source File: RemoveItemsFromPlaylistRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link RemoveItemsFromPlaylistRequest}.
 */
@Override
public RemoveItemsFromPlaylistRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}/tracks");
  return new RemoveItemsFromPlaylistRequest(this);
}
 
Example #26
Source File: ReplacePlaylistsItemsRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link ReplacePlaylistsItemsRequest}.
 */
@Override
public ReplacePlaylistsItemsRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}/tracks");
  return new ReplacePlaylistsItemsRequest(this);
}
 
Example #27
Source File: ReorderPlaylistsItemsRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link ReorderPlaylistsItemsRequest}.
 */
@Override
public ReorderPlaylistsItemsRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}/tracks");
  return new ReorderPlaylistsItemsRequest(this);
}
 
Example #28
Source File: ChangePlaylistsDetailsRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * The request build method.
 *
 * @return A custom {@link ChangePlaylistsDetailsRequest}.
 */
@Override
public ChangePlaylistsDetailsRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/playlists/{playlist_id}");
  return new ChangePlaylistsDetailsRequest(this);
}
 
Example #29
Source File: CreatePlaylistRequest.java    From spotify-web-api-java with MIT License 5 votes vote down vote up
/**
 * the request build method.
 *
 * @return A custom {@link CreatePlaylistRequest}.
 */
@Override
public CreatePlaylistRequest build() {
  setContentType(ContentType.APPLICATION_JSON);
  setPath("/v1/users/{user_id}/playlists");
  return new CreatePlaylistRequest(this);
}