Wednesday, March 23, 2022

Shutdown Spring Boot Command Line Application

You can use ConfigurableApplicationContext to shutdown/closes all resources used by application as follows.

 public static void main(String[] args) {

        ConfigurableApplicationContext ctx=SpringApplication.run(Application.class, args);

        ctx.close();

    } 

    @Bean

    public CommandLineRunner commandLineRunner(RestTemplate restTemplate) {

        return args -> {

}

    }


Monday, March 14, 2022

Remove the <return> tag from SOAP response in JAVA

 Following JAVA annotation can be used to avoid <return> tag from SOAP web service response.

@WebService(serviceName = "Operations")

public class Service {

    @WebMethod(operationName = "processUser")

    @SOAPBinding(parameterStyle=ParameterStyle.BARE)

    public Result processUser(@WebParam(name = "userName")String userName) {

        Result result = new Result();

        result.setResultCode("1");

        result.setResultDesc("success");

        return result;

    }

}

ParameterStyle.BARE will return SOAP response with your defined object attributes.


Tuesday, November 23, 2021

List directories with sizes in Linux

du -sh *

Above command can be used to grep directory sizes in Linux. Go to required directory and execute above command.

Thursday, August 26, 2021

JSCH "Algorithm negotiation fail" error

It was received the following error when creating SSH session using JSCH client. I was able to resolve this after updating JSCH version to 0.1.54.

com.jcraft.jsch.JSchException: Algorithm negotiation fail

        at com.jcraft.jsch.Session.receive_kexinit(Session.java:583)

        at com.jcraft.jsch.Session.connect(Session.java:320)

        at com.jcraft.jsch.Session.connect(Session.java:183)

<!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
<dependency>
    <groupId>com.jcraft</groupId>
    <artifactId>jsch</artifactId>
    <version>0.1.54</version>
</dependency>

Saturday, July 17, 2021

Kill processes created under specific user in Linux

 You can use following commands to kill processes created under specific user in Linux.

for k in `ps -ef | grep usr01| grep ssh | awk '{print $2}'` ; do kill -9 $k ; done

Here, it is killing ssh sessions created by usr01 user.


Friday, April 9, 2021

Edit XSD files to resolve AXIS web service invalid element error

 When executing webservices using AXIS, you can receive following error due to invalid elements.

                {http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Invalid element in com.mobitel.axis.AdjustmentResult - AdjustmentSerialNo

You can edit XSD file for this WSDL and add AdjustmentSerialNo element to AdjustmentResult element to resolve this. You have to download XSD files and generate webservice clients.



Monday, March 8, 2021

Retrieve few minutes older records from SQL in Oracle

You can use following SQL syntax to retrieve data in 5 minute interval in Oracle database. 

select * FROM test_table where added_time <= systimestamp - numtodsinterval(5,'MINUTE')

Above SQL returns values which are older than 5 minutes  than system time in added_time column.