use of org.apache.hc.core5.util.Args in project mercury by yellow013.
the class ClientPreemptiveDigestAuthentication method main.
public static void main(final String[] args) throws Exception {
try (final CloseableHttpClient httpclient = HttpClients.createDefault()) {
final HttpHost target = new HttpHost("http", "httpbin.org", 80);
final HttpClientContext localContext = HttpClientContext.create();
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials("user", "passwd".toCharArray()));
localContext.setCredentialsProvider(credentialsProvider);
final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd");
System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
for (int i = 0; i < 3; i++) {
try (final CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
System.out.println("----------------------------------------");
System.out.println(response.getCode() + " " + response.getReasonPhrase());
EntityUtils.consume(response.getEntity());
final AuthExchange authExchange = localContext.getAuthExchange(target);
if (authExchange != null) {
final AuthScheme authScheme = authExchange.getAuthScheme();
if (authScheme instanceof DigestScheme) {
final DigestScheme digestScheme = (DigestScheme) authScheme;
System.out.println("Nonce: " + digestScheme.getNonce() + "; count: " + digestScheme.getNounceCount());
}
}
}
}
}
}
use of org.apache.hc.core5.util.Args in project mercury by yellow013.
the class ProxyTunnelDemo method main.
public static final void main(final String[] args) throws Exception {
final ProxyClient proxyClient = new ProxyClient();
final HttpHost target = new HttpHost("www.yahoo.com", 80);
final HttpHost proxy = new HttpHost("localhost", 8888);
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd".toCharArray());
try (final Socket socket = proxyClient.tunnel(proxy, target, credentials)) {
final Writer out = new OutputStreamWriter(socket.getOutputStream(), StandardCharsets.ISO_8859_1);
out.write("GET / HTTP/1.1\r\n");
out.write("Host: " + target.toHostString() + "\r\n");
out.write("Agent: whatever\r\n");
out.write("Connection: close\r\n");
out.write("\r\n");
out.flush();
final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.ISO_8859_1));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
}
}
use of org.apache.hc.core5.util.Args in project skywalking-java by apache.
the class HttpClientDoExecuteInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
if (allArguments[0] == null || allArguments[1] == null) {
// illegal args, can't trace. ignore.
return;
}
final HttpHost httpHost = (HttpHost) allArguments[0];
ClassicHttpRequest httpRequest = (ClassicHttpRequest) allArguments[1];
final ContextCarrier contextCarrier = new ContextCarrier();
String remotePeer = httpHost.getHostName() + ":" + port(httpHost);
String uri = httpRequest.getUri().toString();
String requestURI = getRequestURI(uri);
String operationName = requestURI;
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, remotePeer);
span.setComponent(ComponentsDefine.HTTPCLIENT);
Tags.URL.set(span, buildURL(httpHost, uri));
Tags.HTTP.METHOD.set(span, httpRequest.getMethod());
SpanLayer.asHttp(span);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
httpRequest.setHeader(next.getHeadKey(), next.getHeadValue());
}
}
use of org.apache.hc.core5.util.Args in project log-helper by Redick01.
the class HttpClient5Example method main.
public static void main(String[] args) {
String url = "http://127.0.0.1:8081/order/getPayCount?orderNo=1";
CloseableHttpClient client = HttpClientBuilder.create().addRequestInterceptorFirst(new TraceIdIdHttpClient5Interceptor()).build();
HttpGet get = new HttpGet(url);
try {
CloseableHttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.hc.core5.util.Args in project lobster by lundylizard.
the class PlayCommand method action.
@Override
public void action(String[] args, @NotNull MessageReceivedEvent event) {
var link = new StringBuilder();
var channel = event.getTextChannel();
var self = Objects.requireNonNull(event.getMember()).getGuild().getSelfMember();
var selfVoiceState = self.getVoiceState();
var member = event.getMember();
var memberVoiceState = member.getVoiceState();
var spotify = new SpotifyToYoutubeInterpreter();
var top = false;
assert memberVoiceState != null;
if (!memberVoiceState.inVoiceChannel()) {
channel.sendMessage(":warning: You are not in a voice channel.").queue();
return;
}
assert selfVoiceState != null;
if (!selfVoiceState.inVoiceChannel()) {
var audioManager = event.getGuild().getAudioManager();
var memberChannel = Objects.requireNonNull(event.getMember().getVoiceState()).getChannel();
audioManager.openAudioConnection(memberChannel);
assert memberChannel != null;
event.getChannel().sendMessage(":loud_sound: Connecting to voice channel `\uD83D\uDD0A " + memberChannel.getName() + "`").queue();
}
if (args[0].equalsIgnoreCase("top")) {
top = true;
}
for (var i = top ? 1 : 0; i < args.length; i++) {
link.append(args[i]).append(" ");
}
if (!isUrl(link.toString())) {
link.insert(0, "ytsearch:");
}
if (!event.getMessage().getAttachments().isEmpty()) {
link.delete(0, link.length());
link.append(event.getMessage().getAttachments().get(0).getUrl());
}
if (link.isEmpty()) {
channel.sendMessage(":warning: Please provide a file or an URL.").queue();
return;
}
// Spotify doesn't allow direct playback from their API, so it's getting the data from the song and searches it on YouTube
if (spotify.isSpotifyLink(link.toString())) {
if (Lobsterbot.DEBUG)
System.out.println(spotify.isSpotifyPlaylist(link.toString()));
if (Lobsterbot.DEBUG)
System.out.println(link.toString().replace("\\?si=.*$", "").replace("https://open.spotify.com/", ""));
if (!spotify.isSpotifyPlaylist(link.toString())) {
var spotifyId = spotify.getSpotifyIdFromLink(link.toString());
link.delete(0, link.length());
try {
link.append("ytsearch:").append(spotify.getArtistFromSpotify(spotifyId)).append(" ").append(spotify.getSongNameFromSpotify(spotifyId));
} catch (IOException | ParseException | SpotifyWebApiException e) {
e.printStackTrace();
}
} else {
channel.sendMessage("Spotify Playlists may be a little buggy, gonna fix that sooner or later.").queue();
var spotifyId = spotify.getSpotifyIdFromLink(link.toString());
Playlist playlist = null;
try {
playlist = spotify.getSpotifyPlaylist(spotifyId);
} catch (IOException | ParseException | SpotifyWebApiException e) {
e.printStackTrace();
}
assert playlist != null;
for (PlaylistTrack playlistTrack : playlist.getTracks().getItems()) {
try {
if (playlistTrack.getTrack().getId() != null) {
PlayerManager.getInstance().loadAndPlay(event, ("ytsearch:" + spotify.getArtistFromSpotify(playlistTrack.getTrack().getId()) + " " + spotify.getSongNameFromSpotify(playlistTrack.getTrack().getId())).trim(), top, true);
}
} catch (IOException | SpotifyWebApiException | ParseException e) {
e.printStackTrace();
}
}
event.getChannel().sendMessage(":arrow_forward: Added " + playlist.getTracks().getTotal() + " songs to the queue.").queue();
}
}
PlayerManager.getInstance().loadAndPlay(event, link.toString().trim(), top, false);
}
Aggregations