Android Question SLC compiler with java 11

Status
Not open for further replies.

Angelo Messina

Active Member
Licensed User
Longtime User
Salve,
a simple java class that runs will make a library but report an error in compilation,
while if I use java 11 with netbeans 10 it compiles well.

this is the code:

B4X:
package com.angelomessina.weather;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DontInheritEvents;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.objects.ViewWrapper;
import anywheresoftware.b4a.AbsObjectWrapper;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

@BA.ShortName("Weather")
@BA.Version(1.1F)

public class weather
{

    private static final String WEATHER_SERVICE_BASE_URL = "https://query.yahooapis.com/v1/public/yql";
    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;   
    
  
    public static String CheTempoFa(String appId,String consumerKey,String consumerSecret,String Code,String Tipo) throws UnsupportedEncodingException, IOException, InterruptedException
    {
        final String url = "https://weather-ydn-yql.media.yahoo.com/forecastrss";
        
        long timestamp = new Date().getTime() / 1000;
        byte[] nonce = new byte[32];
        Random rand = new Random();
        rand.nextBytes(nonce);
        String oauthNonce = new String(nonce).replaceAll("\\W", "");
        
        List<String> parameters = new ArrayList<>();

        parameters.add("oauth_consumer_key=" + consumerKey);
        parameters.add("oauth_nonce=" + oauthNonce);
        parameters.add("oauth_signature_method=HMAC-SHA1");
        parameters.add("oauth_timestamp=" + timestamp);
        parameters.add("oauth_version=1.0");
        // Make sure value is encoded
        parameters.add("u="+Tipo);
        parameters.add("woeid=" + URLEncoder.encode(Code, "UTF-8"));
        parameters.add("format=json");
        Collections.sort(parameters);

        StringBuffer parametersList = new StringBuffer();
        for (int i = 0; i < parameters.size(); i++)
        {
            parametersList.append(((i > 0) ? "&" : "") + parameters.get(i));
        }
        String signatureString = "GET&" + URLEncoder.encode(url, "UTF-8") + "&" + URLEncoder.encode(parametersList.toString(), "UTF-8");
        String signature = null;
        try
        {
            SecretKeySpec signingKey = new SecretKeySpec((consumerSecret + "&").getBytes(), "HmacSHA1");
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(signingKey);
            byte[] rawHMAC = mac.doFinal(signatureString.getBytes());
            Base64.Encoder encoder = Base64.getEncoder();
            signature = encoder.encodeToString(rawHMAC);
        //  System.out.println("signature " + signature);
        }
        catch (Exception e)
        {
            BA.Log("Unable to append signature");
            System.exit(0);
        }
            String authorizationLine = "OAuth " +
            "oauth_consumer_key=\"" + consumerKey + "\", " +
            "oauth_nonce=\"" + oauthNonce + "\", " +
            "oauth_timestamp=\"" + timestamp + "\", " +
            "oauth_signature_method=\"HMAC-SHA1\", " +
            "oauth_signature=\"" + signature + "\", " +
            "oauth_version=\"1.0\"";
            
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(url + "?woeid=" + Code + "&u="+Tipo+"&format=json"))
            .header("Authorization", authorizationLine)
            .header("X-Yahoo-App-Id", appId)
            .header("Content-Type", "application/json")
            .build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
        return response.body().toString();
      
    }
}
 
Status
Not open for further replies.
Top