All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.carlosthe19916.webservices.utils.Util Maven / Gradle / Ivy

There is a newer version: 1.3.4.Final
Show newest version
package io.github.carlosthe19916.webservices.utils;

import javax.xml.soap.SOAPFault;
import javax.xml.ws.soap.SOAPFaultException;
import java.util.Optional;

public class Util {

    private Util() {
        // Just static methods
    }

    public static Optional getErrorCode(SOAPFaultException exception) {
        String errorCode = "";

        SOAPFault fault = exception.getFault();
        if (fault != null) {
            String faultCode = fault.getFaultCode();
            if (faultCode != null) {
                errorCode = faultCode.replaceAll("soap-env:Client.", "");
            }
        }

        if (!errorCode.matches("-?\\d+")) {
            String exceptionMessage = exception.getMessage();
            if (exceptionMessage != null) {
                errorCode = exceptionMessage.replaceAll("soap-env:Client.", "");
            }
        }

        if (!errorCode.matches("-?\\d+")) {
            return Optional.empty();
        }

        return Optional.of(Integer.parseInt(errorCode));
    }

    public static String getFileNameWithoutExtension(String fileName) {
        int index = fileName.lastIndexOf('.');
        if (index != -1) {
            return fileName.substring(0, fileName.lastIndexOf('.'));
        }
        return fileName;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy