Showing posts with label Spring Boot. Show all posts
Showing posts with label Spring Boot. Show all posts

Tuesday, 6 November 2018

502 Bad Gateway nginx error on Kubernetes docker instance

We have taken a JSON Web Token approach to handle authorization in our Spring Boot application. Everything was working fine up to a point when we started getting 502 Bad Gateway errors for no reason (or, that's what we thought).

We discovered that this happened due to the token size which increased as we progressed with the development of functionality, which in turn resulted in the generation of a larger token based on additional authorization information.

The question still remains, why are we getting a 502 Bad Gateway. The HTTP 502 occurred due to the size of the header and on response to the HTTP request coming in, the kubernetes proxy rejected the request due to its header size.

So, we had to add the following line to the ingress of our application's docker descriptor:

  • ingress.kubernetes.io/proxy-buffer-size: 16k
That solved it. Hope it is of help to someone. :-)

Wednesday, 10 October 2018

Oracle stored procedure with complex parameters - Array of structs and blobs

The following sniplet of code really helped me in implementing a procedure call containing an array of structs and array of blobs as part of its parameter signature: (I hope it will help you too)

import java.sql.Array;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import oracle.jdbc.OracleConnection;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.support.AbstractSqlTypeValue;

public class SqlBlobArrayValue extends AbstractSqlTypeValue {

    private List<byte[]> values;

    private String defaultTypeName;

    public SqlBlobArrayValue(List<byte[]> values) {
        this.values = values;
    }

    public SqlBlobArrayValue(List<byte[]> values, String defaultTypeName) {
        this.values = values;
        this.defaultTypeName = defaultTypeName;
    }

    protected Object createTypeValue(Connection conn, int sqlType, String typeName)
            throws SQLException {
        if (typeName == null && defaultTypeName == null) {
            throw new InvalidDataAccessApiUsageException(
                    "The typeName is null in this context. Consider setting the defaultTypeName.");
        }

        Blob[] blobs = new Blob[values.size()];
        for (int i = 0; i < blobs.length; ++i) {
            Blob blob = conn.createBlob();
            blob.setBytes(1, values.get(i));
            blobs[i] = blob;
        }

        Array array = conn.unwrap(OracleConnection.class).createOracleArray(typeName != null ? typeName : defaultTypeName, blobs);
        return array;
    }
}
With recognition to Luke Woodward on Stackoverflow. Thank you Luke!!