0

I'm trying to make my Azure instance use a proxy server for all the calls he makes. Im creating an azure instance: Azure azure = Azure.configure().withProxy(createProxy(hasProxy)).authenticate(credentials).withSubscription(subscriptionId)

My create proxy method:

    private static Proxy createProxy(String hostPort) throws ServiceWareException {
        String[] arr = hostPort.split(":");
        String host = arr[0];
        String port = arr[1];
        SocketAddress addr = new InetSocketAddress(host, Integer.parseInt(port));
        return new Proxy(Proxy.Type.HTTP, addr);
    }

After doing this I can see in my proxy server call to login.microsoftonline.com:443. The problem is this is the only time Azure making calls through my proxy.

Im listing VMs,networkWatchers, loadbalances and etc... everything with azure variable I've created before.

EDIT: to be more precise, I doesn't make sense to me that azure making only one request through my proxy server while I'm making the actions above, so I'm trying to figure out why.

Zamkie
  • 97
  • 1
  • 6

1 Answers1

0

Regarding the issue, please refer to the following code

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId,
                tenant,
                clientSecret,
                AzureEnvironment.AZURE);
        credentials.withProxy(createProxy());

        Azure azure = Azure.configure()
                .withProxy(createProxy())
                .withLogLevel(LogLevel.BODY_AND_HEADERS)
                .authenticate(credentials)
                .withSubscription(subId);

private static Proxy createProxy() {

        SocketAddress addr = new InetSocketAddress("", Integer.parseInt(""));
        return new Proxy(Proxy.Type.HTTP, addr);

    }
Jim Xu
  • 21,610
  • 2
  • 19
  • 39
  • Hi Jim Xu, can you please describe what's the benefits of writing the code this way? – Zamkie Jan 26 '21 at 09:17
  • @OmriMalka please refer to https://github.com/Azure/azure-sdk-for-java/issues/13720#issuecomment-682133066 – Jim Xu Jan 27 '21 at 02:01