Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To call a SOAP or REST service securely from Java, keep the application protocol and the TLS setup separate: use a SOAP client for a WSDL-based SOAP contract or a REST client for URI-based resources, then configure HTTPS with an SSLContext and trusted certificates. If the server requires client-certificate authentication, configure client credentials as well. Keep hostname verification enabled so Java checks that the server certificate matches the host in the URL.

Choose SOAP or REST from the service contract

The HTTPS layer is shared; the service’s contract determines the client API. SOAP exchanges XML messages in SOAP envelopes and is commonly described by a WSDL. REST clients address resources by URI and use HTTP methods, headers, and representations such as JSON or XML.

Decision point SOAP REST
Start from The service WSDL and its operations Resource URIs, HTTP methods, and representation formats
Typical client approach Generate client artifacts from the WSDL, then call the generated operations Build requests for target URIs and handle responses in the selected media types
Use when The service contract or integration requires SOAP, or depends on enterprise WS-* features The service exposes resource-oriented HTTP endpoints and direct HTTP integration fits its contract
HTTPS security TLS, trusted server certificates, and hostname verification; client credentials too if mutual TLS is required

Jakarta’s web-services guidance describes SOAP calls as SOAP messages sent over HTTP. Its Enterprise Web Services specification includes SOAP 1.1 and SOAP 1.2 bindings over HTTP 1.1 and HTTPS. Jakarta REST defines a Java client API for accessing web resources.

Prepare the Java runtime and APIs

Check which Java and Jakarta APIs your application actually provides before writing client code. JAX-WS was part of Java SE 8 but was removed after Java SE 8; it is not bundled with Java SE 11 or later. A standalone application on those releases needs a JAX-WS implementation and APIs from an external provider, or a Jakarta EE runtime that supplies them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

REST clients also need a Jakarta REST implementation when they run outside a full Jakarta EE container. Jakarta REST 4.0.0 is the Jakarta EE 11 release and requires Java SE 17 or higher. Match the API and implementation to the runtime rather than assuming that importing a Jakarta API makes its implementation available.

Set up TLS trust and, if required, client identity

HTTPS first establishes a TLS channel and then verifies the peer’s identity, as described in Oracle’s JSSE Reference Guide. The truststore supplies certificates Java can trust when validating the server’s certificate chain. A keystore supplies the client’s private key and certificate when the server requires client-certificate authentication (mutual TLS).

Use the default truststore or configure a dedicated one

Oracle documents Java’s default trust-material search as the javax.net.ssl.trustStore system property, followed by jssecacerts and then cacerts if the property is not set. The JDK’s shipped root certificates are not a guarantee that every private or enterprise certificate authority is trusted. The service operator must ensure the truststore contains the appropriate trusted certificates.

For a process-wide truststore, supply its path and password through protected runtime configuration, not source code or a committed configuration file. For example, the JVM accepts -Djavax.net.ssl.trustStore=/secure/path/truststore.p12 and -Djavax.net.ssl.trustStorePassword=.... Restrict access to the file and secret, and use the store type appropriate to the file. A process-wide setting affects more than one service client; use client-scoped configuration where separate integrations need different TLS policies.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create an SSLContext for client-scoped configuration

When an application needs to provide trust material directly to a client, initialize a trust manager from a truststore and use it to create an SSLContext. This Java pattern leaves the truststore password as runtime configuration:

KeyStore trustStore = KeyStore.getInstance(storeType); // for example, PKCS12 or JKS
try (InputStream in = Files.newInputStream(trustStorePath)) {
    trustStore.load(in, trustStorePassword);
}

TrustManagerFactory trustManagers = TrustManagerFactory.getInstance(
        TrustManagerFactory.getDefaultAlgorithm());
trustManagers.init(trustStore);

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers.getTrustManagers(), null);

For mutual TLS, initialize a KeyManagerFactory from the client keystore and pass its key managers as the first argument to SSLContext.init. Keep private-key passwords and store passwords out of code and logs. The exact certificate chain and credential format depend on what the service operator requires.

Build a SOAP client over HTTPS

  1. Obtain the service WSDL. Confirm the HTTPS endpoint, SOAP version, and any authentication requirements with the service owner.
  2. Generate or obtain the client artifacts. Jakarta’s tutorial describes using the wsimport Maven goal to generate and compile web-service artifacts from the WSDL. On modern Java releases, ensure the selected JAX-WS tooling and runtime are provided by your dependencies or Jakarta EE environment rather than expecting them in the JDK.
  3. Compile and configure the client. Use the generated service and port classes, and configure the TLS material through the JAX-WS implementation or runtime you selected. SOAP stacks differ in how they expose their HTTP transport and TLS settings; there is no single provider-independent TLS property established here. Consult that implementation’s documentation for client-scoped SSL configuration.
  4. Invoke the operation and inspect failures safely. A successful HTTPS connection does not guarantee a valid SOAP request or response: verify the operation, namespace, payload, and SOAP fault handling separately from TLS.

In a Jakarta EE environment, the tutorial’s starting point for a web service is a Java class annotated with jakarta.jws.WebService. For a client, the practical starting point is the service’s WSDL and compatible generated artifacts.

Build a REST client over HTTPS

Jakarta REST’s ClientBuilder bootstraps a client. The client targets a URI, then creates an invocation builder for request headers, media types, entities, and HTTP methods. Attach the SSL context when building the client so the TLS policy is scoped to that client:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Client client = ClientBuilder.newBuilder()
        .sslContext(sslContext)
        .build();

try {
    Response response = client.target(URI.create("https://api.example.test/items"))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get();
    // Check the status and process the response representation.
} finally {
    client.close();
}

Replace the example URI and media type with the service’s actual endpoint and contract. A REST response may be JSON, XML, text, PDF, or another representation; request the format the endpoint supports and handle its HTTP status codes. The client API also offers keyStore, trustStore, and hostnameVerifier configuration methods. Prefer configuring SSL material on the specific client rather than changing global TLS behavior for unrelated calls.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep hostname verification enabled

Trust-chain validation and hostname verification answer different questions. The truststore helps determine whether the certificate chain is trusted; hostname verification checks whether the certificate identity matches the host in the URL. A mismatch can indicate a wrongly configured endpoint or a spoofed server, and failed verification should close the connection.

Do not disable certificate validation or install a permissive hostname verifier to make a failing request succeed. Correct the endpoint name, install the legitimate issuing certificate or chain in the relevant truststore, or ask the service operator to fix its certificate and TLS configuration.

Troubleshoot HTTPS client failures

  • Untrusted certificate or certificate-path error: Check which truststore the process or client actually uses, whether it contains the correct issuing CA or required certificate chain, and whether the server presents that chain. Confirm the truststore path, type, and password.
  • Hostname or peer-identity failure: Compare the URL host with the identity on the server certificate. Use the correct service hostname or have the certificate corrected; do not bypass verification.
  • Handshake failure: Check the server’s TLS configuration and the client and runtime configuration for compatibility. The available evidence does not establish a universal protocol setting or fix; the specific exception and chosen Java provider matter.
  • Mutual TLS rejection: Confirm that the server requires a client certificate, that the configured keystore contains the expected client credentials, and that the service accepts the corresponding certificate chain.
  • SOAP call fails after TLS connects: Check WSDL compatibility, SOAP version, operation, and SOAP fault details. A transport connection alone does not validate the SOAP exchange.
  • REST call fails after TLS connects: Check the URI, HTTP method, request headers, media type, response status, and representation expected by the resource.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.