#StackBounty: #java #spring #tomcat #ubuntu-12.04 #tomcat9 After a while, Tomcat ceases working with other APIs

Bounty: 50

I’m trying to make the project more stable. The problem is that at some point there is a situation in which all the code that uses communication with other APIs ceases to work. Until I reboot the tomcat, what I have to do every few hours (from 4 hours to several minutes, it seems to depend on the number of users). At the same time, the code that accepts GET (or any other) request and does not contact other servers during its activity – it continues to work. Communication with other servers is lost and other projects on this server.

The server Ubuntu 12.04, nginx 1.12.0, tomcat 9.0.0.M26.
The server has 12 small projects on java.
Spring 5.0.4.RELEASE, hibernate 5.2.16.Final, (PostgreSQL) 9.6.3

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

I also get many other errors in different places and different types, most often NPE (because due to lack of communication the object I wanted from another server = null), sometimes I get an HttpClientErrorException and status 400, although the remote server always responds on similar requests by the status of 200.
On my local tomcat, I never got a similar situation. I have been suffering for a long time with this problem, the situation is getting worse (more users – it breaks faster), I will be grateful for any advice. I apologize for Google translate.

Thread dump from jstack –
threaddumps.log

jvisualvm

Below is jvisualvm threads at the time the code does not work

jvisualvm threads

jvisualvm threads

jvisualvm threads

Thread dump a few seconds before everything breaks

Thread dump at the time the code does not work


Get this bounty!!!

#StackBounty: #java #symlink How to run a process in Java inside a symlink directory?

Bounty: 50

I need to run a native process from Java inside a symlink directory. Let’s have following directory structure:

guido@Firefly:~/work$ tree
.
└── path
    └── to
        └── symlink -> /home/guido/work

3 directories, 0 files

I’m starting the Java application from the ~/work directory and want to run the native process in the ~/work/path/to/symlink directory.

However, if I use following Java code, the symlink working directory resolves to the real path. Instead, I would like to run the command in the absolute path.

(Please mind, that pwd command is just for illustration and should be replaced with the “real” one (e.g. go build in my case)).

File baseDir = new File("/home/guido/work");
File link = new File(baseDir, "path/to/symlink");
Files.createSymbolicLink(link.toPath(), baseDir.toPath());

Process process = new ProcessBuilder()
            .command("pwd")
            .directory(link)
            .start();

String output = getOutput(process);
System.out.println(output); // Prints: /home/guido/work

I was able to meet my needs with following workaround, but it looks stupid to start a shell just to be able to trigger a simple process in a specific directory. Plus, I lose platform independence.

String[] cmd = {"/bin/sh", "-c", "cd " + link + " && pwd"};
Process process = Runtime.getRuntime().exec(cmd);

String output = getOutput(process);
System.out.println(output); // Prints: /home/guido/work/path/to/symlink

Here, you can find a full example as a unit test gist with both solutions.


Get this bounty!!!

#StackBounty: #java #android #google-fit #donut-chart android donut chart fill multi color based on timestamp

Bounty: 50

I am looking for chart which will show one circle around that time like 12:00, 01:00 like. Which feels with some colors based on time of activity.
I found this link Create Doughnut Chart Similar to Google Fit but it isn’t fit for my requirements.

Please find below image. This is how I am expecting the chart.

enter image description here

Here these colors represent some activity based on timings. I have set of data with timestamp and it’s activity type.

Can anyone suggest me how can I draw this chart? Is there any example for this?


Get this bounty!!!

#StackBounty: #java #xml How to validate SAML EntitiesDescriptor Signature with Apache Santuario

Bounty: 50

The aim is to validate a saml EntitiesDescriptor signature using a stux processor to ensure the amount of memory used is low.

I have been using the following code with an example from Apache Santuario without any luck.

Please can someone advise on how to use Apache Santuario with SAML Entity Descriptor files.

SignatureUtils can be found here

URL url = new URL(“http://metadata.ukfederation.org.uk/ukfederation-metadata.xml“);

// Validation
List<QName> namesToSign = new ArrayList<QName>();
namesToSign.add(new QName("urn:oasis:names:tc:SAML:2.0:metadata", "EntitiesDescriptor"));

try (InputStream stream = url.openStream()) {
  X509Certificate cert = getCertificate();
  SignatureUtils.verifyUsingStAX(stream, namesToSign, cert);
}


Get this bounty!!!

#StackBounty: #java #maven #javadoc #maven-javadoc-plugin #java-10 Can't link to JDK10 in Javadoc comments

Bounty: 50

After upgrading from Java 9 to 10, links to the JDK no longer work when generating documentation with the Javadoc tool (e.g., for a file importing java.util.Optional, {@link Optional} renders as Optional instead of as Optional; same issue with @see, @param, @return, and anywhere else you normally see Javadoc links).

I have a simple modularized project, and I’m using Maven with the Javadoc plugin (source and target for the compiler plugin are set to 10). My understanding is that by default it passes -link https://docs.oracle.com/javase/10/docs/api/ to the Javadoc tool. It’s also my understanding that, historically, the Javadoc tool expected a text file named package-list to be present at the URL where it was told to find external docs. Java 8 has one. Java 9 has one. Java 10 does not. Apparently, the Javadoc tool now outputs a text file named element-list instead of package-list for modularized projects, but it seems like that isn’t provided either (nor for Java 9, but it is available for early-access builds of Java 11).

Generating Javadoc through IntelliJ with the option Link to JDK documentation enabled produces the same result. It says it’s passing -link https://docs.oracle.com/javase/10/docs/api/ to javadoc.exe, and it reports javadoc: error - Error fetching URL: https://docs.oracle.com/javase/10/docs/api/. Despite the error, it does output the Javadoc, but as with Maven, no JDK links are present.

How is this supposed to work? Did Oracle just screw up when they put the JDK docs online?

The relevant bits of my pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>10</source>
                <target>10</target>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>6.1</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Output of mvn -version:

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T12:49:05-07:00)
Maven home: C:Program Filesapache-maven-3.5.3bin..
Java version: 10, vendor: Oracle Corporation
Java home: C:Program FilesJavajdk-10
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"


Get this bounty!!!

#StackBounty: #java #android #mvc #client Writing service/network layer for mobile apps

Bounty: 100

I have an app that gets and posts blog posts to and from a server.

Right now I have a network client object which is passed into a service object. The service object is created and called from an Android Activity (though my question could apply to iOS also). Success and failure callbacks are passed from the Activity to the Service object to the Client object.

I’m starting to think that I’m doing something very wrong here, because

  1. I think this violates MVC, because business logic is being done in the activity.
  2. This is becoming difficult to test due to the callbacks being passed from object to object, and I’ve read that if code is difficult to test, that is a sign of bad design.

Here is my service class

public class PostService implements Service<Post>{

    NetworkClient client;

    PostService(NetworkClient client){
        this.client = client;
    }

    @Override
    public void getAll(Response.Listener<JSONArray> onSuccess, Response.ErrorListener onError){
        client.getList(endpoint(), onSuccess, onError);
    }

    @Override
    public void get(int id, Response.Listener<JSONObject> onSuccess, Response.ErrorListener onError) {
        client.get(endpointForPostNumber(id), onSuccess, onError);
    }

    @Override
    public void create(Post post, Response.Listener onSuccess, Response.ErrorListener onError) {
        JSONObject params = new JSONObject();
        try {
            params.put(ServiceContracts.PostServiceContract.Fields.TEXT, post.getText());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        client.post(endpoint(), params, onSuccess, onError);
    }

    @Override
    public void update(Post post, int id, Response.Listener onSuccess, Response.ErrorListener onError) {
        JSONObject params = new JSONObject();
        try {
            params.put(ServiceContracts.PostServiceContract.Fields.TEXT, post.getText());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        client.patch(endpointForPostNumber(id), params, onSuccess, onError);
    }

    @Override
    public void delete(int id, Response.Listener onSuccess, Response.ErrorListener onError) {
        client.delete(endpointForPostNumber(id), onSuccess, onError);
    }

    // Endpoints
    private static final String ENDPOINT = "/post/";

    private static String endpoint(){
        return Utils.URLS.SERVER_ADDRESS + ENDPOINT + "/";
    }

    private static String endpointForPostNumber(int id){
        return Utils.URLS.SERVER_ADDRESS + ENDPOINT + String.valueOf(id) + "/";
    }
}

Here is my network client class

public class NetworkClient {

    private RequestQueue requestQueue;

    public NetworkClient(RequestQueue requestQueue){
        this.requestQueue = requestQueue;
    }

    public void getList(String endpoint, Response.Listener<JSONArray> onSuccess, Response.ErrorListener onError) {
        JsonArrayRequest jsArrayRequest;
        if (CurrentUser.isLoggedIn()) {
            jsArrayRequest = new JsonArrayRequest(endpoint, onSuccess, onError){
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put(ServiceContracts.Headers.AUTHORIZATION, "Token " + CurrentUser.getToken());
                    return headers;
                }
            };
        }
        else {
            jsArrayRequest = new JsonArrayRequest(endpoint, onSuccess, onError);
        }

        requestQueue.add(jsArrayRequest);

    }

    public void get(String endpoint, Response.Listener<JSONObject> onSuccess, Response.ErrorListener onError){
        JsonObjectRequest jsObjRequest;
        if (CurrentUser.isLoggedIn()) {
            jsObjRequest = new JsonObjectRequest(Request.Method.GET, endpoint, null, onSuccess, onError){
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put(ServiceContracts.Headers.AUTHORIZATION, "Token " + CurrentUser.getToken());
                    return headers;
                }
            };
        }
        else {
            jsObjRequest = new JsonObjectRequest(Request.Method.GET, endpoint, null, onSuccess, onError);
        }

        requestQueue.add(jsObjRequest);
    }

    public void post(String endpoint, JSONObject params, Response.Listener<JSONObject> onSuccess, Response.ErrorListener onError){
        JsonObjectRequest jsObjRequest;
        if (CurrentUser.isLoggedIn()) {
            jsObjRequest = new JsonObjectRequest(Request.Method.PUT, endpoint, params, onSuccess, onError) {
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put(ServiceContracts.Headers.AUTHORIZATION, "Token " + CurrentUser.getToken());
                    return headers;
                }
            };
        }
        else {
            jsObjRequest = new JsonObjectRequest(Request.Method.PUT, endpoint, params, onSuccess, onError);
        }

        requestQueue.add(jsObjRequest);
    }

    public void patch(String endpoint, JSONObject params, Response.Listener<JSONObject> onSuccess, Response.ErrorListener onError){
        JsonObjectRequest jsObjRequest;
        if (CurrentUser.isLoggedIn()) {
            jsObjRequest = new JsonObjectRequest(Request.Method.PATCH, endpoint, params, onSuccess, onError) {

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put(ServiceContracts.Headers.AUTHORIZATION, "Token " + CurrentUser.getToken());
                    return headers;
                }
            };
        }
        else {
            jsObjRequest = new JsonObjectRequest(Request.Method.PATCH, endpoint, params, onSuccess, onError);
        }

        requestQueue.add(jsObjRequest);
    }

    public void delete(String endpoint, Response.Listener<JSONObject> onSuccess, Response.ErrorListener onError) {
        JsonObjectRequest jsObjRequest;
        if (CurrentUser.isLoggedIn()) {
            jsObjRequest = new JsonObjectRequest(Request.Method.DELETE, endpoint, null, onSuccess, onError) {
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();
                    headers.put(ServiceContracts.Headers.AUTHORIZATION, "Token " + CurrentUser.getToken());
                    return headers;
                }
            };
        }
        else {
            jsObjRequest = new JsonObjectRequest(Request.Method.DELETE, endpoint, null, onSuccess, onError);
        }

        requestQueue.add(jsObjRequest);
    }
}

The post service gets called from and activity like so

postService.getAll(
                    new Response.Listener<JSONArray>() {

                        @Override
                        public void onResponse(JSONArray response) {
                            ArrayList<Post> posts = new ArrayList<Post>();
                            for (int i = 0; i < response.length(); i++) {
                                JSONObject json = null;
                                try {
                                    json = response.getJSONObject(i);
                                    posts.add(new Post(json));
                                } catch (JSONException e) {
                                    popUpInvalidResponseError();
                                }
                                adapter = new WallAdapter(posts, getApplicationContext());
                                listView.setOnItemClickListener(onPostClickListener);
                                listView.setAdapter(adapter);
                            }
                        }
                    },
                    new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            popUpNetworkError(error);
                        }
                    }
            );

The problem is I don’t know how to refrain from passing the callbacks through multiple objects and keeping business logic in the Activity because I can’t get access the resources in the callback outside of the callback (in java). If I try it tells me I need to make the variable outside the callback final, and then I can’t re-assign it inside the callback. I also need to access UI elements in the onError callback.

Does this code follow best practices for the Network/Service layer of a mobile app? If not how can I fix it?


Get this bounty!!!

#StackBounty: #java #android #localization #currency Why Currency.defaultFractionDigits() for IDR is 0 for android?

Bounty: 50

For Indonesian currency (IDR), defaultFractionDigits() gives me 0 in Android app.

Locale locale = new Locale("in", "ID");
Currency currency = Currency.getInstance(locale);
Log.d("TEST",String.format(locale, "Currency - %s ( %s )  Decimal - %s ",
        currency.getSymbol(locale),
        currency.getSymbol(),
        currency.getDefaultFractionDigits()));

D/TEST: Currency – Rp ( IDR ) Decimal – 0

Same gives me 2 when I’m testing it in my eclipse (also in RexTester)

Locale.setDefault(new Locale("in","ID"));
Currency c = Currency.getInstance("IDR");
System.out.println("Symbol: " + c.getSymbol());
System.out.println("Default fractional digits: " + c.getDefaultFractionDigits());

Symbol: Rp

Default fractional digits: 2

Documentation of both Android & Java states that it’s ISO 4217 (ISO 4217:2015 lists the IDR with two-digit decimal points)

Why it’s 0 for Android App?


Get this bounty!!!

#StackBounty: #java #android #json JSONObject don't Get data from QR code

Bounty: 50

When i scan qr code it’s get a data on result.getgetContents but didnt pass the data on JSONObject obj just directing go on Catch block

data get pass to this line JSONObject obj = new JSONObject(result.getContents()); but when start to Debug then its not pass the data on ‘obj’ in above line.

here is my code :

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null) {
            //if qrcode has nothing in it
            if (result.getContents() == null) {
                Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
            } else {
                //if qr contains data
                try {
                    //converting the data to json
                    JSONObject obj = new JSONObject(result.getContents());
                    //setting values to textviews

                    if(obj.has("FN")) {
                        etFirstName.setText(obj.getString("FN"));
                    }
                    if(obj.has("N")) {
                        etLastName.setText(obj.getString("LN"));
                    }
                    if(obj.has("TITLE")) {
                        etTitle.setText(obj.getString("TITLE"));
                    }
                    if(obj.has("STATUS")) {
                        etStatus.setText(obj.getString("STATUS"));
                    }
                    if(obj.has("EMAIL")) {
                        etEmail.setText(obj.getString("EMAIL"));
                    }
                    if(obj.has("TEL;TYPE=work")) {
                        etPhoneHome.setText(obj.getString("TEL;TYPE=work"));
                    }
                    if(obj.has("TEL;TYPE=cell")) {
                        etPhonePrimary.setText(obj.getString("TEL;TYPE=cell"));
                    }
                    if(obj.has("ADR;TYPE=work")) {
                        etAddressLine1.setText(obj.getString("ADR;TYPE=work"));
                    }
                    if(obj.has("Street")) {
                        etAddressLine2.setText(obj.getString("Street"));
                    }
                    if(obj.has("Street")) {
                        etCity.setText(obj.getString("Street"));
                    }
                    if(obj.has("zip")) {
                        etZip.setText(obj.getString("zip"));
                    }


                } catch (JSONException e) {

                    Log.e(TAG, "notification= error" + e.toString());
                    e.printStackTrace();

                    /*etFirstName.setText(result.getContents());
                    etLastName.setText(result.getContents());
                    etTitle.setText(result.getContents());
                    etEmail.setText(result.getContents());*/
                    //if control comes here
                    //that means the encoded format not matches
                    //in this case you can display whatever data is available on the qrcode
                    //to a toast
                    Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
                }
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

Logcat see below :

03-09 11:23:06.909 297-678/? E/SimpleSoftOMXComponent: 3
03-09 11:23:07.127 297-665/? E/audio_a2dp_hw: adev_set_parameters: ERROR: set param called even when stream out is null
03-09 11:23:12.899 26980-26980/com.example.crm E/AddContactActivity: notification= errororg.json.JSONException: Value BEGIN of type java.lang.String cannot be converted to JSONObject
03-09 11:23:13.040 297-8371/? E/SimpleSoftOMXComponent: 1
03-09 11:23:13.040 297-8371/? E/SimpleSoftOMXComponent: 2
03-09 11:23:13.041 297-8371/? E/SimpleSoftOMXComponent: 3

JSON Response Data like below code:

BEGIN:VCARD,
VERSION:2.1
FN:sss sss
N:sss;sss
TITLE:PHD
TEL;CELL:1111111111
TEL;WORK;VOICE:2222222222
TEL;HOME;VOICE:8888888888
EMAIL;HOME;INTERNET:abc@example.com
EMAIL;WORK;INTERNET:abc@example.com
URL:http://ABC@ABC.COM
ADR:;;sample address;ss;;102103;US
ORG:ss
END:VCARD

Search every where but i don’t get any result for this problem so plzzz help me:)

Thanks&Regards
Sandeep Patel


Get this bounty!!!

#StackBounty: #java #google-cloud-storage The account for bucket "XXX" has been disabled

Bounty: 50

Running the following code to create a new bucket on google storage, I got an error “StorageException: The account for bucket “my-new-bucket-abc” has been disabled“.

String SERVICE_ACCOUNT_JSON_PATH = "C:\gcpconfig\My First Project-6f9cff47c4f0.json";

Storage storage =
    StorageOptions.newBuilder()
        .setCredentials(
            ServiceAccountCredentials.fromStream(
                new FileInputStream(SERVICE_ACCOUNT_JSON_PATH)))
        .build()
        .getService();

String bucketName = "my-new-bucket-abc";

// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));

System.out.printf("Bucket %s created.%n", bucket.getName());

However, I could download the files from google storage by running the following code:

String SERVICE_ACCOUNT_JSON_PATH = "C:\gcpconfig\My First Project-6f9cff47c4f0.json";

Storage storage =
    StorageOptions.newBuilder()
        .setCredentials(
            ServiceAccountCredentials.fromStream(
                new FileInputStream(SERVICE_ACCOUNT_JSON_PATH)))
        .build()
        .getService();

BlobId blobId = BlobId.of("nmjcloud_jar_test","addons/simple-bean-1.0.jar");
Blob blob = storage.get(blobId);

Path path = Paths.get("D:\lib\simple-bean-1.0.jar");
blob.downloadTo(path);

System.out.printf("Download successfully%n");

The complete error message is as follows:

Exception in thread "main" com.google.cloud.storage.StorageException: The account for bucket "my-new-bucket-abc" has been disabled.
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:191)
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:221)
    at com.google.cloud.storage.StorageImpl$2.call(StorageImpl.java:112)
    at com.google.cloud.storage.StorageImpl$2.call(StorageImpl.java:109)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:89)
    at com.google.cloud.RetryHelper.run(RetryHelper.java:74)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)
    at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:108)
    at com.example.storage.QuickstartSample.main(QuickstartSample.java:58)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "location" : "Authorization",
    "locationType" : "header",
    "message" : "The account for bucket "my-new-bucket-abc" has been disabled.",
    "reason" : "accountDisabled"
  } ],
  "message" : "The account for bucket "my-new-bucket-abc" has been disabled."
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
    at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
    at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:219)
    ... 7 more

Does it mean that the account I used doesn’t have permission to create buckets?

Some Settings about my Google Cloud Platform:

1. Billing account:
enter image description here

2. The service account key:

{
  "type": "service_account",
  "project_id": "ornate-shine-192301",
  "private_key_id": "6f9cff47c4f0f8b1263bbf515f7e3318dcc88487",
  "private_key": "-----BEGIN PRIVATE KEY-----nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHvLTQn5i0AhebnW9iUkaRpZiGACUrh694JAzckVPEdhDoLaV4ZBapnmYrJBqQIs8RFXRWajtOrjzbYnKJXWhOdtIim72fB0KVENjTRmq2m+wWf+ks19/eWakzYlXvsry61GT44UfccCOYbUnioyevhQtJ0mdpa7QtAtjWyFmNXHodLjHHiwhArRYRP4Mel0MkHKi64EZ5aDLEGernkjntqnDcni0giCQNcvJw8c9XBB64dDcldSc7ZZ8QGXgBwzqYCt1F7pjK8rg6CFBin8ZKmUaRpguG4pB229fuwTWwE++/WEUtmgvGV4iQ6u6Zzeiw8TPKzgYzrF7XmBu38nzHa+5wkJAgMBAAECggEAOwz7yhf9De72arx/LgFXAcArlE5rAJr6pGB6e3fPZyISnBRCsPKqTpBhdUyxu75GyK62m9vBV/QkUtlhdYDQftYCdpQd8UuNqLp76CIaR9073nv2hIb4DSUl5GaksH5/1J55kakM1UukAmsAycIUxh662LUpvKsLIiEcg9+hk/6XCenscbApZ+UEpl9RaxE4dTKO4PdKZkytc7sGbn7VFowEwWNqUcZ6cwIbQEFt6B1Bol1nI4xgcxnUNRzJjls4OJvN6aQRz2lVPgTdG8hfg20Uhc+Yaj7WbGTPDdOwowREDKrSnmdBAxm6Io264E5pz/4QWVSLR2SPMQfYxAkpkXhLxtwKBgQDyGSptLWucZFsWyIEGnUClv8ymY0gGOYuiqiZqYSlCWDJTycHrcMSk9DjHo5XAgXRXtnbwEVhsOUVH/9g7vnWJGR94smqRuVGpOJQPTniaPY7ewSMob+tDxKHu48XCFScXRUJnjunW0hnX6GwU91nsBk7wbu/hMJ8UAK+rO8WeB6RvwKBgQDTNNVRgcSCWDdN5FdF1fQFTiKZ5CT+jg3AnOqQD1FYadGzRB3FiFrpQ9pKLjW86RPQTYpAJ5dX+Vm0qWpzXMpq8IQX7FlZChJO9nZKa1zbuLD0whWENIjEIqt/nHvXQhdccoFq3aUdRRbye9OZ8kDcUWfPVZE64HJnTtnkQYYWQaHNwKBgQDF4z4jqam5VuqBz/hu8Z09TbRlntr4yO5HX1zHOI9wZu5k0P4Ln9/8uUekH5mrleVEQPgtOPBe3d08ger8wcuPiPUY3nqjWErgfy8GjdIVCLw/0u+pOnTYKuT2QKYIA4RFaC5kOZP4LRpEuk2GQb3YpypuPRIzJZrIjh1LdFVYAfPwKBgB/rnv0XXWAzfKlSiazJJ2NyoZ4Bcw96ZN6jS9BEEGZNb/0pEVrWde8Fa0uE2mhXzb/QynFFT6oLIU++DH2yaHJm3Ci/Xb9WOOSAn62Vtm4a5tvHLZtSmU0TdFoQG4N4ILG/OKnIfJ6JZ29MANgXxYC4sO4VRiGaen4vPlezs4FPoBXAoGAc/h3ep+m3okykKwqL6eanoBJJ6xMiSTgvHVb9gNlVeDvRiqT7sc7Y2i/UKF2UceLQTOWssGtg/LiqvEZlMI0snU2LuyU2vdT+7Thn3hT1EfBYTOEuGIgXijGA4aLNAx4HsRx2M6HeLE277syJxBNgUn3DsGix3gso9/jJjt4p5G5II=n-----END PRIVATE KEY-----n",
  "client_email": "gcsserviceaccountname1@ornate-shine-192301.iam.gserviceaccount.com",
  "client_id": "114270155500502944764",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gcsserviceaccountname1%40ornate-shine-192301.iam.gserviceaccount.com"
}

3. Permissions for project “My First Project” :
enter image description here

4. Google Cloud Storage API Library :
enter image description here

Supplement:
1. I’m able to create buckets either using gsutil command line or GCP console.
2. Java API could download files from GCS.

Reference Links:
1. APIs & Reference
2. Cloud Storage Client Libraries


Get this bounty!!!

#StackBounty: #java #apache-poi #xssf #sxssf SXSSF vs XSSF workbook createSheet() fails on linux environments

Bounty: 50

Was trying to implement an excel export feature on an app using apache POI 3.17.

All was working fine on my local tomcat server and on a windows dev environment. However, the SXSSFWorkbook workbook.createSheet() method fails on a linux tomcat server without throwing any kind of meaningful error (it’s just hanging).

Strangely, the same method on the XSSFWorkbook createSheet class works fine. Below are the snippets of code. Has anyone experienced a similar issue before?

    final SXSSFWorkbook workbook = new SXSSFWorkbook();
    workbook.setCompressTempFiles(true);
    SXSSFSheet sheet = workbook.createSheet("Sheet 1"); //this method fails

    final XSSFWorkbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("Sheet 1"); // this works fine

Edit

I created a custom TempFileCreationStrategy to ensure tomcat is writing the file to a directory it has full access to. I can see the file has been created but it’s hanging as it tries to write any data to the file.

I cannot figure this one out.

Edit2

I’ve enabled POI logging but it I’m still not getting anything meaningful that I can investigate. On my local server POI logging spits out the following as it begins to write the file:

[20:13:05,005]DEBUG (?:?) - Save core properties part
[20:13:05,005]DEBUG (?:?) - Save package relationships
[20:13:05,005]DEBUG (?:?) - Save content types part
[20:13:05,005]DEBUG (?:?) - Save part 'docProps/app.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'docProps/core.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/sharedStrings.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/styles.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/workbook.xml'
[20:13:05,005]DEBUG (?:?) - Save part 'xl/worksheets/sheet1.xml'

On the Linux box, it’s not even getting as far as the first log output. Need to find a way to get more detail about the failure!

Edit3

Is it possible to get more detailed logging beyond the default logging I have enabled below?

System.setProperty("org.apache.poi.util.POILogger", "org.apache.poi.util.SystemOutLogger" );

String tmpDir = System.getProperty("java.io.tmpdir")+File.separator+"excelfiles";
ExcelFileCreationStrategy tfcs = new ExcelFileCreationStrategy();

try {
    tfcs.createTempDirectory(tmpDir);
} catch (IOException e) {
    e.printStackTrace();
    LOG.error(e);
}

TempFile.setTempFileCreationStrategy(tfcs);

final SXSSFWorkbook workbook = new SXSSFWorkbook();
workbook.setCompressTempFiles(true);

LOG.debug("creating work sheet - next line fails");
Sheet sheet = workbook.createSheet(); //hangs here
LOG.debug("It's worked!!!!");


Get this bounty!!!