i hate SQL so much its unreal
i hate SQL so much its unreal
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 2/19/2025 in #java-help
whats the point of OOP encapsulation?
hey guys. i was wondering if smb could help me out? im tired of reading countless articles that are copy pasted from each other so maybe a person and not a bot can explain stuff to me. in all the textbooks its said that "muh encapsulashun" is data hiding (whatever that means), using private fields, getters and setters. so now i have some questions: 1. who are we hiding the data from? lets say i have this:
class Book {
public String author;
public int isbn;
}
class Book {
public String author;
public int isbn;
}
so? from who i need to hide the "data"? 2. lets say i want to hide "data", shouldnt i put it somewhere more safe? i.e. database, vault, etc? 3. whats the point of having private fields if u can just call the getter/setter? book.author is the same as book.getAuthor(). so why overcomplicate everything? thanks in advance. im trying to understand whats the point of this stuff.
8 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 2/19/2025 in #java-help
how does open-closed principle really work?
hey guys. i have a question an id like to hear other opinions. lets say i have this.:
public class MyService{
//class fields, getters, setters
public myServiceMethod(Car car){
if(car.getColor()=="Red"){
Print("Red car");
}
if(car.getColor()=="Green"){
Print("Green car");
}
//do other business logic
}
}
public class MyService{
//class fields, getters, setters
public myServiceMethod(Car car){
if(car.getColor()=="Red"){
Print("Red car");
}
if(car.getColor()=="Green"){
Print("Green car");
}
//do other business logic
}
}
it works fine. but then there comes a point when i need to check if the car is Yellow and Blue. then it means i have to add more if statements:
public class MyService{
//class fields, getters, setters
public myServiceMethod(Car car){
if(car.getColor()=="Red"){
Print("Red car");
}
if(car.getColor()=="Green"){
Print("Green car");
}
if(car.getColor()=="Yellow"){
Print("Yellow car");
}
if(car.getColor()=="Blue"){
Print("Blue car");
}
//do other business logic
}
}
public class MyService{
//class fields, getters, setters
public myServiceMethod(Car car){
if(car.getColor()=="Red"){
Print("Red car");
}
if(car.getColor()=="Green"){
Print("Green car");
}
if(car.getColor()=="Yellow"){
Print("Yellow car");
}
if(car.getColor()=="Blue"){
Print("Blue car");
}
//do other business logic
}
}
now the questions arise: 1. is adding more if statements considered to be extension or modification? In my understanding its both. You modify code all the time. You changed variable name? Its modification. In Cambridge dictionary modification is described as a change to something. Refactoring is modification too. You cant write excellent code from the first try. 2. does the first and second pieces of code follow open-closed principle? why?
24 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 2/7/2025 in #java-help
can request be validated before reaching the controller?
hey guys. im talking with a friend of mine and he mentioned that in php language you usually validate the data BEFORE it reaches the controller. i was wondering if this can be done in Java Spring app? as i understand this idea cant be done in Java Spring app. the controller in Spring app is the entry point to the application. and you cant really do much in Dispatcher servlet. what do you guys think? thanks in advance.
16 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 1/22/2025 in #java-help
why my spring app cant connect to DB?
hi guys. im using intellij idea to run my java spring app. i connected my db to the intellij idea.
host: localhost
port:5432
user:us3r
password:p4ss
URL:jdbc:postgresql://localhost:5432/postgres
host: localhost
port:5432
user:us3r
password:p4ss
URL:jdbc:postgresql://localhost:5432/postgres
im using ssh tunnel to connect to database. when i test the connection everything is fine. but the problem arises when i try to start my java spring app. in application.yaml i have this piece of configuration:
spring:
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/lms_dev2
username: us3r
password: p4ss
spring:
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/lms_dev2
username: us3r
password: p4ss
and when i start the app i get org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. whats wrong? can smb help me out pls? thanks in advance
7 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 1/22/2025 in #java-help
why do i get redirected to /login?
hey guys. i have java spring app. it has this websecurity config chain:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/sol/createPaymentInformation").permitAll()
.antMatchers("/sol/createPaymentConfirmation").permitAll()
.antMatchers("/sol/createPaymentReversal").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/sol/createPaymentInformation").permitAll()
.antMatchers("/sol/createPaymentConfirmation").permitAll()
.antMatchers("/sol/createPaymentReversal").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
1. when i launch my app on computer, my endpoints are called fine. 2. when i deploy my app to the server, the endpoints arent being called - i get 404 i have nginx on the server. i opened nginx access log:
"POST /bgw/sol/createPaymentInformation HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0"
"GET /login HTTP/1.1" 404 146 "http://myserver.lv/bgw/sol/createPaymentInformation" "PostmanRuntime/7.43.0"
"POST /bgw/sol/createPaymentInformation HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0"
"GET /login HTTP/1.1" 404 146 "http://myserver.lv/bgw/sol/createPaymentInformation" "PostmanRuntime/7.43.0"
i dont understand why its being redirected to /login. can smb help me out? as i understand its smth with nginx, not the java app itself.
23 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 11/26/2024 in #java-help
can smb explain what is the difference between bitwise and logical operators?
i dont understand at all. and the more i google the less i get it.
12 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 11/4/2024 in #java-help
how to properly config my application logging?
hey guys. i have java spring app. and on the server its running as a service. heres my application123.service:
[Unit]
Description=application123
After=syslog.target
[Service]
User=appl
Environment="JAVA_OPTS=-Xmx128m"
ExecStart=/usr/local/bin/application123-1.0.jar --spring.config.location=/etc/spring/ --spring.config.name=application123
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
[Unit]
Description=application123
After=syslog.target
[Service]
User=appl
Environment="JAVA_OPTS=-Xmx128m"
ExecStart=/usr/local/bin/application123-1.0.jar --spring.config.location=/etc/spring/ --spring.config.name=application123
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Now when this service runs on the server, everything is logged to syslog. And the thing is that id want to log everything to separate file. smth like application123.log. so my question is should i edit my application123.service file, or should i edit application.yaml file? thanks
8 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 10/14/2024 in #java-help
Soap request gives me 404 and "No endpoint mapping" even if everything is correct
Hello everyone. Its been almost a week and I still cant find an error and the reason why I am getting this kind of error. The thing is that my endpoint is correct, everything is set up fine. Earlier this endpoint had different name and everything worked fine. And now after changing the endpoint name everything just broke. Things I tried: asking chat gpt and gemini, asking for help on different discord servers, googling and browsing stackoverflow. The thing is that I cannot change the request body and I just need to use this request body. This is my Java code: https://pastecode.io/s/antg289v xsd and wsdl: https://pastecode.io/s/7142nmnr request body: https://pastecode.io/s/ng61346m console log: https://pastecode.io/s/1wg2oi2f Could somebody take a look and help me out? Huge thanks
6 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 10/9/2024 in #java-help
No endpoint mapping found for [SaajSoapMessage idcheck]
hi guys. im developing soap service in java spring and i keep getting No endpoint mapping found for [SaajSoapMessage idcheck] erro. can smb pls help me out? My java code: https://pastecode.io/s/antg289v xsd and wsdl: https://pastecode.io/s/7142nmnr request body: https://pastecode.io/s/ng61346m thanks alot
5 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 10/7/2024 in #java-help
java variables need to have the same name like in SOAP request?
hi guys. i have soap service in java spring. i have this dto class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"userid",
"trans_id"
})
@XmlRootElement(name = "idCheckRequest", namespace = "http://mycompany.lt/soap-web-service")
@Data
public class PerlasCheckIdRequestDTO {
@NotNull(message = "userId cant be null")
@Size(max = 32, message = "userId too long")
@XmlElement(name = "userid", required = true, namespace = "http://mycompany.lt/soap-web-service" )
private String userId;

@NotNull(message = "transactionId cant be null")
@Size(max = 100, message = "transactionId too long")
@XmlElement(name = "trans_id", required = true, namespace = "http://mycompany.lt/soap-web-service")
private String transactionId;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"userid",
"trans_id"
})
@XmlRootElement(name = "idCheckRequest", namespace = "http://mycompany.lt/soap-web-service")
@Data
public class PerlasCheckIdRequestDTO {
@NotNull(message = "userId cant be null")
@Size(max = 32, message = "userId too long")
@XmlElement(name = "userid", required = true, namespace = "http://mycompany.lt/soap-web-service" )
private String userId;

@NotNull(message = "transactionId cant be null")
@Size(max = 100, message = "transactionId too long")
@XmlElement(name = "trans_id", required = true, namespace = "http://mycompany.lt/soap-web-service")
private String transactionId;
}
i send this request body:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<soap:idcheck>
<soap:trans_id>903</soap:trans_id>
<soap:userid>903</soap:userid>
</soap:idcheck>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<soap:idcheck>
<soap:trans_id>903</soap:trans_id>
<soap:userid>903</soap:userid>
</soap:idcheck>
</soapenv:Body>
</soapenv:Envelope>
but i get:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">4 counts of IllegalAnnotationExceptions</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring xml:lang="en">4 counts of IllegalAnnotationExceptions</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i noticed that if i name my java vars the same like they are named in request xml, everything is fine. But the thing is that my code gets messy. Is there a fix for this scenario?
4 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 10/7/2024 in #java-help
soap request give me 400 bad request
hi guys. i have soap service in java spring. i have this dto class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"userid",
"trans_id"
})
@XmlRootElement(name = "idCheckRequest", namespace = "http://mycompany.lt/soap-web-service")
@Data
public class PerlasCheckIdRequestDTO {
@NotNull(message = "userId cant be null")
@Size(max = 32, message = "userId too long")
@XmlElement(name = "userid", required = true, namespace = "http://mycompany.lt/soap-web-service" )
private String userId;

@NotNull(message = "transactionId cant be null")
@Size(max = 100, message = "transactionId too long")
@XmlElement(name = "trans_id", required = true, namespace = "http://mycompany.lt/soap-web-service")
private String transactionId;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"userid",
"trans_id"
})
@XmlRootElement(name = "idCheckRequest", namespace = "http://mycompany.lt/soap-web-service")
@Data
public class PerlasCheckIdRequestDTO {
@NotNull(message = "userId cant be null")
@Size(max = 32, message = "userId too long")
@XmlElement(name = "userid", required = true, namespace = "http://mycompany.lt/soap-web-service" )
private String userId;

@NotNull(message = "transactionId cant be null")
@Size(max = 100, message = "transactionId too long")
@XmlElement(name = "trans_id", required = true, namespace = "http://mycompany.lt/soap-web-service")
private String transactionId;
}
i send this request body:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
<soapenv:Body>
<idcheck soapenv:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/>
<userid xsi:type="xsd:string">903</userid>
<trans_id xsi:type="xsd:string">903</trans_id>
</idcheck>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance>
<soapenv:Body>
<idcheck soapenv:encodingStyle=http://schemas.xmlsoap.org/soap/encoding/>
<userid xsi:type="xsd:string">903</userid>
<trans_id xsi:type="xsd:string">903</trans_id>
</idcheck>
</soapenv:Body>
</soapenv:Envelope>
but i just get 400 bad request. can smb help me out? chatgpt doesnt help at all
9 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 10/3/2024 in #java-help
how to find WSDL file location in my SOAP webservice?
hey guys. i have soap webservice that is running on my server. i can call it with postman: http://dev.mycompany.lt/bgw/perlas then i add needed body and receive expected response. everythings fine. but i was wondering what is the location of my wsdl file? can smb help me out? thx
8 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/27/2024 in #java-help
WebSecurityConfig in java spring app doesnt work
hey guys. can smb help me out? i have java spring app runing on my server dev2. on the server i also have nginx basic auth and proxy configured. now when i do the request to http://dev2.mysite.lt/bgw/perlas i get asked for my nginx basic auth credentials. i enter them, and later im prompted with another login page thats comming from my app. my WebSecurityConfig looks like this:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private MyUserDetailsService userDetailsService;

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/perlas").permitAll()

.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
auth.authenticationProvider(authProvider());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new CryptEncoder();
}
@Bean
public DaoAuthenticationProvider authProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
}
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private MyUserDetailsService userDetailsService;

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/perlas").permitAll()

.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
auth.authenticationProvider(authProvider());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new CryptEncoder();
}
@Bean
public DaoAuthenticationProvider authProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
}
can smb help me out? thx
6 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/24/2024 in #java-help
what password to enter when doing git push?
hey guys. can smb help me out with git? I tried googling but theres no normal and simple answer. the more i read the less i understand. i did git commit -m "my message". then when i try to do git push i get:
banana@dev2:/var/www/lms2$ git push
[email protected]'s password:
banana@dev2:/var/www/lms2$ git push
[email protected]'s password:
what password do i need to enter? can smb explain?
63 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/23/2024 in #java-help
how to enable basic auth in java spring app?
hey guys. i have java spring app. in WebSecurityConfig i have this:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/perlas").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/perlas").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll()
.and().logout().permitAll()
.and().csrf().disable();
}
and i want to enable basic auth. i know that i can do it in nginx, but i was wondering if i can do it in my spring app config somehow. can smb help me out? thx
8 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/16/2024 in #java-help
how to test my scheduled methods locally?
hey guys. so i have java spring app. in the app i have a 2 methods annotated with @Scheduled and each method has 2 cron expressions (one for work days, one for weekend). i deploy my app to the server. and on the same server i have cron jobs and thats how my code is being scheduled. but my question is how to locally test if my cron jobs for these two methods work fine?
4 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/16/2024 in #java-help
how to properly update spring version?
hi guys. i have java project and current spring version is 2.2.6. i need to update the version to the newest. as i understand its 3.3.3. so i have a couple of questions; 1. since i use gradle, i just need to change the version here?
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
2. is there smth to look out for when updating spring version in my project? thanks in advance
5 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/12/2024 in #java-help
how to return multiple objects in SOAP webservice?
hey guys. im developing SOAP webservice in java and i have a question. there are two operations checkId and createSale. and there are CheckIdRequestDTO, CheckIdResponseDTO, CreateSaleRequestDTO, CreateSaleResponseDTO. when validating checkId request and there are some errors, i set needed CheckIdResponseDTO fields to needed values and return the DTO and everything is fine. so my endpoint returns CheckIdResponseDTO in both cases: if its ok, or theres an error. But now im having trouble with createSale request. im validating CreateSaleRequestDTO, and if theres an error i dont have anything to return. I was thinking about constructing something like CreateSaleRequestErrorDTO. but then my endpoint cant return it. this is my endpoint so far:
@Endpoint
@Validated
public class PerlasEndpoint {
@Autowired
PerlasService perlasService;
private static final String SOAP_NAMESPACE="http://mycompany.lt/soap-web-service";

@PayloadRoot(namespace = SOAP_NAMESPACE,localPart = "idCheckRequest")
@ResponsePayload
public PerlasCheckIdResponseDTO checkId(@Valid @RequestPayload PerlasCheckIdRequestDTO perlasCheckIdRequestDTO) {
Optional<PerlasCheckIdResponseDTO> validationResult=perlasService.validateCheckIdRequest(perlasCheckIdRequestDTO, "CHECK ID");

if (validationResult.isPresent()) {
return validationResult.get();
}

PerlasCheckIdResponseDTO perlasCheckIdResponseDTO = perlasService.checkId(perlasCheckIdRequestDTO);

return perlasCheckIdResponseDTO;
}

@PayloadRoot(namespace = SOAP_NAMESPACE, localPart = "saleRequest")
@ResponsePayload
public PerlasSaleResponseDTO createSale(@Valid @RequestPayload PerlasSaleRequestDTO perlasSaleRequestDTO) {
PerlasSaleResponseDTO perlasSaleResponseDTO=perlasService.createSale(perlasSaleRequestDTO);

return perlasSaleResponseDTO;
}
}
@Endpoint
@Validated
public class PerlasEndpoint {
@Autowired
PerlasService perlasService;
private static final String SOAP_NAMESPACE="http://mycompany.lt/soap-web-service";

@PayloadRoot(namespace = SOAP_NAMESPACE,localPart = "idCheckRequest")
@ResponsePayload
public PerlasCheckIdResponseDTO checkId(@Valid @RequestPayload PerlasCheckIdRequestDTO perlasCheckIdRequestDTO) {
Optional<PerlasCheckIdResponseDTO> validationResult=perlasService.validateCheckIdRequest(perlasCheckIdRequestDTO, "CHECK ID");

if (validationResult.isPresent()) {
return validationResult.get();
}

PerlasCheckIdResponseDTO perlasCheckIdResponseDTO = perlasService.checkId(perlasCheckIdRequestDTO);

return perlasCheckIdResponseDTO;
}

@PayloadRoot(namespace = SOAP_NAMESPACE, localPart = "saleRequest")
@ResponsePayload
public PerlasSaleResponseDTO createSale(@Valid @RequestPayload PerlasSaleRequestDTO perlasSaleRequestDTO) {
PerlasSaleResponseDTO perlasSaleResponseDTO=perlasService.createSale(perlasSaleRequestDTO);

return perlasSaleResponseDTO;
}
}
and idk what to do in this situation. can smb help me out? thx
9 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 9/12/2024 in #java-help
what data type to use for storing ids?
hi guys. in java code i will need to use/store ids, that look like 11000000035. what data type to use? long or just String? because int in my case doesnt have enough storage for symbols. thanks
12 replies
JCHJava Community | Help. Code. Learn.
Created by i hate SQL so much its unreal on 8/16/2024 in #java-help
exception handling in SOAP webservices
hey guys. i have a question about SOAP webservice. i have this piece of code in my service layer:
Optional<Customer> customer=customerRepository.findById(Long.valueOf(perlasIdCheckRequestDTO.getUserId()));
if (customer.isEmpty()) {
log.info("PerlasService.checkId.NoCustomerException.CustomerId:{}.TransactionId:{}",perlasIdCheckRequestDTO.getUserId(),perlasIdCheckRequestDTO.getTransactionId());

throw new NoCustomerException("No customer with customerId:"+perlasIdCheckRequestDTO.getUserId());
}
Optional<Customer> customer=customerRepository.findById(Long.valueOf(perlasIdCheckRequestDTO.getUserId()));
if (customer.isEmpty()) {
log.info("PerlasService.checkId.NoCustomerException.CustomerId:{}.TransactionId:{}",perlasIdCheckRequestDTO.getUserId(),perlasIdCheckRequestDTO.getTransactionId());

throw new NoCustomerException("No customer with customerId:"+perlasIdCheckRequestDTO.getUserId());
}
and i have this exception:
@Getter
public class NoCustomerException extends RuntimeException {
public NoCustomerException(String message) {
super(message);
}
}
@Getter
public class NoCustomerException extends RuntimeException {
public NoCustomerException(String message) {
super(message);
}
}
and the exception is later handled by the RestResponseEntityExceptionHandler. so i have a couple of questions: 1. can i use the same exception? or do i need to create a duplicate one that will only be used for SOAP service? can i reuse the exception from my REST service? 2. how to handle the exceptions in SOAP webservices? i tried googling but honestly didnt understand a thing. can smb help me out? thx
4 replies