<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Request on Micha Kops&#39; Tech Notes</title>
    <link>https://www.hascode.com/tags/request/</link>
    <description>Recent content in Request on Micha Kops&#39; Tech Notes</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>Copyright © 2010 - 2025 Micha Kops. #e9d956c0c0154a221ad83c925346a8fa0e72f866</copyright>
    <lastBuildDate>Tue, 02 Aug 2022 00:00:00 +0200</lastBuildDate>
    <atom:link href="https://www.hascode.com/tags/request/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Single Class Java HTTP Client with Proxy and SSL/TLS Keystore Settings</title>
      <link>https://www.hascode.com/single-class-java-http-client-with-proxy-and-ssl/tls-keystore-settings/</link>
      <pubDate>Tue, 02 Aug 2022 00:00:00 +0200</pubDate>
      <guid>https://www.hascode.com/single-class-java-http-client-with-proxy-and-ssl/tls-keystore-settings/</guid>
      <description>&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;Sometimes this is useful for the diagnosis of configuration and network problems of ones Java application.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;This is our single-class HTTP client example without the need for external dependencies:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;title&#34;&gt;HttpTest.java&lt;/div&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;

public class HttpTest {
    public static void main(String[] args)
        throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, IOException, CertificateException {
        String bodyPayload = &amp;#34;&amp;#34;&amp;#34;
            ourpayload, json, xml, ...
            &amp;#34;&amp;#34;&amp;#34;;

        String keyStorePath = &amp;#34;/opt/keystore.jks&amp;#34;;
        String keyStorePassword = &amp;#34;ABCDEFG&amp;#34;;

        String proxyHost = &amp;#34;ourproxy.proxy&amp;#34;;
        String uriString = &amp;#34;https://some-service/api&amp;#34;;
        int proxyPort = 8080;
        int timeoutInSeconds = 60;

        KeyStore keyStore = KeyStore.getInstance(&amp;#34;JKS&amp;#34;);
        keyStore.load(new FileInputStream(keyStorePath), keyStorePassword.toCharArray());

        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(&amp;#34;PKIX&amp;#34;);
        keyManagerFactory.init(keyStore, null);

        TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(&amp;#34;PKIX&amp;#34;); // using same keystore for both
        trustManagerFactory.init(keyStore);

        SSLContext sslContext = SSLContext.getInstance(&amp;#34;TLS&amp;#34;);
        sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

        HttpClient client = HttpClient.newBuilder()
                                      .proxy(
                                          ProxySelector.of(new InetSocketAddress(proxyHost, proxyPort)))
                                      .sslContext(sslContext)
                                      .build();
        URI uri = new URI(uriString);
        HttpRequest request = HttpRequest.newBuilder(uri)
                                         .POST(BodyPublishers.ofString(bodyPayload))
                                         .timeout(Duration.of(timeoutInSeconds, ChronoUnit.SECONDS))
                                         .build();
        System.out.printf(&amp;#34;Sending POST request to %s, timeout: %ds%n&amp;#34;, uri, timeoutInSeconds);
        try {
            HttpResponse response = client.send(request, BodyHandlers.ofString());
            System.out.println(&amp;#34;Response received...&amp;#34;);
            System.out.printf(&amp;#34;\tResponse-Status: %d%n&amp;#34;, response.statusCode());
            System.out.printf(&amp;#34;\tResponse-Body: %s%n&amp;#34;, response.body());
            System.out.println(&amp;#34;-------------------------------------%n&amp;#34;);

        } catch (IOException e) {
            System.err.printf(&amp;#34;IOException caught: %s%n&amp;#34;, e.getMessage());
            e.printStackTrace(System.err);
        } catch (InterruptedException e) {
            System.err.printf(&amp;#34;IOException caught: %s%n&amp;#34;, e.getMessage());
            e.printStackTrace(System.err);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <title>Implementing Reactive Client-Server Communication over TCP or Websockets with RSocket and Java</title>
      <link>https://www.hascode.com/implementing-reactive-client-server-communication-over-tcp-or-websockets-with-rsocket-and-java/</link>
      <pubDate>Sun, 25 Nov 2018 00:00:00 +0100</pubDate>
      <guid>https://www.hascode.com/implementing-reactive-client-server-communication-over-tcp-or-websockets-with-rsocket-and-java/</guid>
      <description>&lt;div id=&#34;preamble&#34;&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;Reactive design or reactive architecture has an impact on how modern software systems are implemented. RSocket is a project that aims to adapt the benefits of the patterns described in the Reactive Manifesto and resulting tools like Reactive Streams or Reactive Extensions  to a formal new communication protocol.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;RSocket works with TCP, WebSockets and Aeron transport layers and offers additional features like session resumption.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;In the following tutorial I’m going to demonstrate how to implement simple client-server communication over TCP and Websockets for different interaction models like request-response, request-stream, fire-and-forget and event subscription.&lt;/p&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <title>AWS Snippets</title>
      <link>https://www.hascode.com/aws-snippets/</link>
      <pubDate>Thu, 01 Mar 2018 00:00:00 +0100</pubDate>
      <guid>https://www.hascode.com/aws-snippets/</guid>
      <description>&lt;div class=&#34;sect1&#34;&gt;
&lt;h2 id=&#34;_aws_command_line_interface&#34;&gt;AWS Command Line Interface&lt;/h2&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;sect2&#34;&gt;
&lt;h3 id=&#34;_installation&#34;&gt;Installation&lt;/h3&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;$ curl &amp;#34;https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip&amp;#34; -o &amp;#34;awscliv2.zip&amp;#34;
unzip awscliv2.zip
sudo ./aws/install&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;ulist&#34;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html&#34;&gt;AWS Documentation&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;sect2&#34;&gt;
&lt;h3 id=&#34;_rds&#34;&gt;RDS&lt;/h3&gt;
&lt;div class=&#34;sect3&#34;&gt;
&lt;h4 id=&#34;_export_database_configuration&#34;&gt;Export Database Configuration&lt;/h4&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;title&#34;&gt;Export instance configuration&lt;/div&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;aws rds describe-db-instances --db-instance-identifier arn:aws:rds:eu-central-1:123456789:db:hascode-prd-db --no-paginate&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;title&#34;&gt;Export parameter group configuration&lt;/div&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;aws rds describe-db-parameters --db-parameter-group-name PARAM_GROUP_NAME &amp;gt;&amp;gt; param_group_conf.json&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;listingblock&#34;&gt;
&lt;div class=&#34;title&#34;&gt;Export option group configuration&lt;/div&gt;
&lt;div class=&#34;content&#34;&gt;
&lt;pre class=&#34;highlight&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;aws rds describe-option-groups --option-group-name OPT_GROUP_NAME &amp;gt;&amp;gt; option_group_conf.json&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;sect1&#34;&gt;
&lt;h2 id=&#34;_generate_signed_urls_with_linux_tools&#34;&gt;Generate Signed URLs with Linux Tools&lt;/h2&gt;
&lt;div class=&#34;sectionbody&#34;&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;e.g. for accessing a website behind a CloudFront distribution using a &lt;a href=&#34;https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-canned-policy.html&#34;&gt;canned policy&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;paragraph&#34;&gt;
&lt;p&gt;Write the policy file&lt;/p&gt;
&lt;/div&gt;</description>
    </item>
  </channel>
</rss>
