Showing posts with label problem and solutions. Show all posts
Showing posts with label problem and solutions. Show all posts

September 07, 2022

nested exception is org.springframework.core.io.buffer.DataBufferLimitException | Exceeded limit on max bytes to buffer : 262144 | org.springframework.web.reactive.function.client.WebClientResponseException

Hi, While trying to implement a NSE Ticker for stockmarket analysis we encountered the below error

reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.web.reactive.function.client.WebClientResponseException: 200 OK from GET https://www.bijusapp/query?f=DAILY&symbol=adhani&apikey=bijusapp; nested exception is org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
Caused by: org.springframework.web.reactive.function.client.WebClientResponseException: 200 OK from GET https://www.bijusapp/query?f=DAILY&symbol=adhani&apikey=bijusapp; nested exception is org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144


Solution


spring.codec.max-in-memory-size=50MB in application properties


Or


/**
 * 
 */


import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.WebFluxConfigurer;

/**
 * @author bijusapp
 *
 */
@Configuration
@EnableWebFlux
public class WebFluxConfig implements WebFluxConfigurer {
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.defaultCodecs().maxInMemorySize(16 * 1024 * 1024);
}

}

July 21, 2022

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

Problem

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

This issue happens due to version mismatch between swaggerfox and spring boot framework.


Solution




/**
 * @author aswathi sajeevan
 *
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}
}


Pom.xml



<!--  swagger  -->

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>


Spring boot version



<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>



Swagger url


http://localhost:9090/swagger-ui/index.html




April 28, 2022

Making entire row and column of matrix to zero if one element is zero | alternative approach


Given a matrix if an element in the matrix is 0 then you will have to set its entire column and row to 0 and then return the matrix.
 



/**
 * Given a matrix if an element in the matrix is 0 then you will have to set its entire column and row to 0 and then return the matrix.
 */
package com.striver.sde.practice;

import java.util.ArrayList;
import java.util.List;

/**
 * @author apple
 *
 */
public class MatrixZero {

/**
* @param args
*/
public static void main(String[] args) {

int[][] input = { { 1, 1, 1 }, { 1, 0, 1 }, { 1, 1, 1 } };

MatrixZero m = new MatrixZero();
// m.findSolution(input);
m.findSolution2(input);

}

private void findSolution2(int[][] input) {
int len = input.length;

List rows = new ArrayList<>();
List cols = new ArrayList<>();

for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if (input[row][col] == 0) {
rows.add(row);
cols.add(col);
}

}

}
for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if(rows.contains(row)) {
input[row][col] =0;
}
if(cols.contains(col)) {
input[row][col] =0;
}

}

}
System.out.println(input);
}

private void findSolution(int[][] input) {

int[][] output = input.clone();

int len = input.length;

for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if (input[row][col] == 0) {

modifyMatrix(row, col, output, len);

}

}

}

}

private void modifyMatrix(int row, int col, int[][] output, int len) {

if (row == 0) {
int r = row;
while (r < len) {
output[r][col] = 0;
r = r + 1;
}

} else if (row == len) {
int r = row;
while (r >= 0) {
output[r][col] = 0;
r = r - 1;
}

} else {

}

}

}

December 21, 2021

Find missing number in a sequence Minimum complexity | n Log n

/**
 * Find missing number in a sequence Minimum complexity (n Log n)
 * 
 * input : {1,2,3,5}
 * output : 4
 */
package com.codecreeks.solutions;

import java.util.Arrays;

/**
 * @author Consumerfed Information Technology Section
 *
 */
public class MissingNumberArray {
private static int loopCount = 0;
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int[] a = {1,2,3,4,6,7,8,9,10,11,12};
int len = a.length;
MissingNumberArray m = new MissingNumberArray();
int value = 0;
if(a[len-1]!=len) {
value = m.findMissingNumber(a, 0, len);
System.out.println(" The Missing number in the array :"+Arrays.toString(a)+" is "+value);
}else {
loopCount++;
System.out.println(" There is no missing number in the given array "+Arrays.toString(a));
}
System.out.println(" For "+len+" size array it tooks "+loopCount+" search to find the answer ");
System.out.println(" Complexity :"+len*Math.log(len));
System.out.println(" Time Taken : "+(System.currentTimeMillis() - startTime)+" ms");
}
private int findMissingNumber(int[] array, int startPstn, int endPstn) {
loopCount++;
int arraySize = endPstn - startPstn;
int position = startPstn + arraySize / 2;
if(arraySize==0) {
return position +1;
}else if (arraySize == 1) {
return array[position] + 1;
}
else if (array[position] != position + 1) {
return findMissingNumber(array, startPstn, position);
} else {
return findMissingNumber(array, position + 1, endPstn);
}
}
}

December 07, 2020

To developed a pricing engine for a cycle in java - coding test

CODING TEST ( Problem)

The module to be developed is a pricing engine for a cycle. A cycle can be thought of as high level components - 

1. frame 

2. handle bar with brakes 

3. seating, 

4. wheels, 

5. chain assembly 

Each of the above high level components will have parts, for instance, a wheel has spokes, rim, tube, tyre. 

The pricing module should be able to calculate the price of the cycle given its configuration. For example, price a cycle with tubeless tyres, steel frame, 4 gears. The pricing of the parts is time sensitive, means the cost of a tyre will change with time and the module should support this. A tyre can cost 200Rs from Jan 2016 - Nov 2016, and its price can change to Rs 230 from Dec 2016 onwards. 

The pricing module should be a command line executable, no graphical ui needed. It can take its input as command line parameters or as a json text file, whatever is convenient to specify in. The inputs to the module will be the list of constituent parts, date of pricing and it will output the price of the entire cycle and also price for each high level component - frame, wheels etc. 

Modular code and well thought out class/object model is expected as well as Junit tests for main classes. 

Calculate Pricing for 1000 cycles using multithread and blocking queue using a maximum of 10 threads. 



Solution



Facebook comments