Download a file securely from oracle OCI , need help with java service, Please help

Experts,
Did any one downloaded a file from Oracle OCI environment through a secure link.

Here are the steps i need to perform:
• Generating an API Signing Key (already completed):
o **https://docs.cloud.oracle.com/iaas/Content/API/Concepts/apisigningkey.htm **
• Signing the HTTP requests:
o https://docs.cloud.oracle.com/Content/API/Concepts/signingrequests.htm ( need help with this java code to use it in webmethods)
o Request Signatures
• GetObject route to download the file:
o Oracle Cloud Infrastructure API Reference and Endpoints

Can someone from Java please help me to use this code in webmethods,
code (https://docs.cloud.oracle.com/Content/API/Concepts/signingrequests.htm ( need help with this java code to use it in webmethods)

here is sample code
/**

  • Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
  • This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl
  • or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
    */
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.nio.charset.StandardCharsets;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import com.google.common.net.UrlEscapers;

import com.oracle.bmc.http.signing.RequestSigningFilter;

public class RawRestCallExample {

public static void main(String args) throws Exception {
// TODO: fill this out
String instanceId = null;

String configurationFilePath = “~/.oci/config”;
String profile = “DEFAULT”;

// Pre-Requirement: Allow setting of restricted headers. This is required to allow the SigningFilter
// to set the host header that gets computed during signing of the request.
System.setProperty(“sun.net.http.allowRestrictedHeaders”, “true”);

// 1) Create a request signing filter instance
RequestSigningFilter requestSigningFilter =
RequestSigningFilter.fromConfigFile(configurationFilePath, profile);

// 2) Create a Jersey client and register the request signing filter
Client client = ClientBuilder.newBuilder().build().register(requestSigningFilter);

// 3) Target an endpoint. You must ensure that path arguments and query
// params are escaped correctly yourself
WebTarget target =
client.target(“https://iaas.us-phoenix-1.oraclecloud.com”)
.path(“20160918”)
.path(“instances”)
.path(UrlEscapers.urlPathSegmentEscaper().escape(instanceId));

// 4) Set the expected type and invoke the call
Invocation.Builder ib = target.request();
ib.accept(MediaType.APPLICATION_JSON);
Response response = ib.get();

// 5) Print the response headers and the body (JSON) as a string
MultivaluedMap<String, Object> responseHeaders = response.getHeaders();
System.out.println(responseHeaders);
InputStream responseBody = (InputStream) response.getEntity();
try (final BufferedReader reader =
new BufferedReader(new InputStreamReader(responseBody, StandardCharsets.UTF_8))) {
StringBuilder jsonBody = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
jsonBody.append(line);
}
System.out.println(jsonBody.toString());
}
}
}

HI Garu,

What’s the error you’re getting?
I would propose to

  1. develop simple java app for secure file download from Oracle OCI. Hope Oracle documentation is straight forward and it should be easy
  2. Once you have the code from 1) it should be easier to integrate it within webMethods

Hope that helps
NIkolay

Some forum participants might object to this suggestion, but one approach to consider is to not use Java, javax.ws.rs*, Jersey, etc as the core components. Do this in an “Integration Server” way, not a Java way. It is likely you can create the payload and headers directly without too much effort. You may need a Java service or 2 for a specific part, but certainly do not need a single Java service that does everything. Break it up into logical bits to create the payload, sign it, generate the headers, etc. then use pub.client:http for the HTTP call – there is no reason to be making the HTTP call using Java code. There are other built-in services that may help with payload signing and such. Leverage the tools IS provides.

We did something similar to this to put data to WebCenter Content (WCC) hosted on OCI, though it is SOAP-based, not JSON over HTTP. We found it much easier to create the payload using string-manipulation, var substitution, etc. rather than fighting with the WSD created from the WCC WSDL. Using string templates where appropriate and setting HTTP headers ourselves resulted in a far simpler/understandable approach. Not as flexible for future use/changes but we didn’t need that. You may find this approach is easier for your needs as well.