pari Nagda

Ranch Hand
+ Follow
since Jun 03, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
18
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by pari Nagda

Tim Holloway wrote:I worked with someone who'd been brought up on COBOL. COBOL, as originally designed, had source programs that were generally one enormous procedure. When he first started working with more modern languages such as Pascal, he got a little frustrated because enormous monolithic procedures often wouldn't even compile - the resource allocation and optimization schemes used in these languages was oriented towards smaller units.

A common complaint about Java is over-abstraction: defining an Interface and concrete classes for virtually everything and that's really just another case of the famous small-child-with-hammer syndrome. But in OOP languages it is true that a single program code unit should normally be something you can print on a single piece of paper. Anything  larger is probably trying to do too much.

More important than the number of classes is how you organize class packages. Here again, the key is that a package should do one thing and do it well. Packages enhance code re-usability and help hide internals from mis-use by outsiders. Java Modules, of course, take that one step further. But that's another topic.



I understand a better structure and organization can help with readability and testability  but I was trying to understand how efficient it is in terms of JVM performance.
2 years ago
Following the SOLID Principle , we end up adding  many classes in the object oriented based app . is it a concern or completely fine  to add up numerous classes in the code ?  
2 years ago
Can you elaborate it "So you could log to catalina.out by setting up log4j to channel to stdout" . I would be interested to know how to do it using log4j.properties file.
3 years ago
I am trying to implement logging using the log4j in the web app running on tomcat at AWS beanstalk environment. I need to write the logs into catalina.out file situated at "/var/log/tomcat" path.  
Can anyone please let me know how to set the path in log4j.properties. I am actually looking for the value of  the line 3 "log4j.appender.file.File".

log4j.rootLogger=${tomcat.server.log.threshold},file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p %-4L %C{5} %m%n
log4j.logger.com.ptc=${tomcat.server.log.threshold},file
3 years ago

Stephan van Hulst wrote:Looks like you have an application that uses JAX-B annotations. Is it a Maven application? Can you show us the POM? Can you show us an example of where you use the JAX-B annotations?



Thank you for the response . I have solved it now. Its the jaxws-ri artifact in the pom which was downloading the eclipselink.jar 2.6 version . This version was not supporting the java 11 and causing the issue.
Upgrading the version of jaxws-ri has solve the problem as the new version of it downloading 2.7+ version of eclipselink .
3 years ago
Guys,

I am facing below error when I start up my tomcat instance on local system with java version 11.0.8.
Tomcat version - 8.55.56

Can any please help to learn work around .

java.lang.ExceptionInInitializerError
at org.eclipse.persistence.internal.helper.ClassConstants.<clinit>(ClassConstants.java:64)
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.createElementsForTypeMappingInfo(AnnotationsProcessor.java:361)
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:305)
at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:158)
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:1131)



java.lang.NullPointerException
at org.eclipse.persistence.indirection.IndirectCollectionsFactory.getProvider(IndirectCollectionsFactory.java:202)
at org.eclipse.persistence.indirection.IndirectCollectionsFactory.<clinit>(IndirectCollectionsFactory.java:45)
at org.eclipse.persistence.internal.helper.ClassConstants.<clinit>(ClassConstants.java:64)
3 years ago
I trying to hit Spring Controller service using the mockmvc test but every time I am getting "org.springframework.web.HttpMediaTypeNotSupportedException" . I appreciate if any one refer  below details and try to suggest me .

Controller : -
@PostMapping(value="/textTranslation",consumes = MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseBody>  translateText(@RequestBody TranslationRequest tranaTranslationRequest) throws Exception {
ResponseBody responseBody = new ResponseBody();
try {
System.out.println("In side Controller");
responseBody.setTest("test");
}
catch(Exception e) {
e.printStackTrace();
}
return new ResponseEntity<ResponseBody>(responseBody, HttpStatus.OK);
  }

Test : -

       @Test
public void testRequestBodyInput() throws Exception {

TranslationRequest translationRequest = new TranslationRequest("english","french","test");

MockHttpServletRequestBuilder request = post("/textTranslation");
request.content(asJsonString(translationRequest));
request.accept(MediaType.APPLICATION_JSON_UTF8_VALUE);
request.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
mockMvc.perform(request)
   .andDo(print())
   .andExpect(status().isOk());

/*
* mockMvc.perform(post("/textTranslation").
* content(asJsonString(translationRequest)).contentType(MediaType.
* APPLICATION_JSON_UTF8_VALUE).accept(MediaType.APPLICATION_JSON_UTF8_VALUE)).
* andDo(print()) .andExpect(status().isOk()).
* andExpect(MockMvcResultMatchers.jsonPath("$.test").value("test"));
*/

}


    public static String asJsonString(final Object obj) {
   try {
       return new ObjectMapper().writeValueAsString(obj);
   } catch (Exception e) {
       throw new RuntimeException(e);
   }
}

Spring Version - 5.0.1.RELEASE

Test Error - java.lang.AssertionError: Status expected:<200> but was:<415>
3 years ago

Rob Spoor wrote:That method was added in version 1.1 of the validation framework; see https://docs.oracle.com/javaee/7/api/javax/validation/Configuration.html#getDefaultParameterNameProvider--. Since you're using JBoss 6.1, which is ancient, it probably provides version 1.0.

I'm curious though - why are you a) using JBoss 6.1, which is ancient, and b) using Spring Boot inside a container, whereas one of its main selling points is to not have to depend on a container?



1) This is the app server my company is using to serve the customers hence all the web apps deployed here  . 2) I understand Spring boot app works with the embedded tomcat but to make this app available for customers I need to expose the services from this app using company's domain(support.xyz.com) using the App server(jboss) , Right ?  - This is the reason I am deploying it on jboss.
Please correct me if the approach i am using is not the recommended one.
3 years ago
While deploying the Spring boot app on jboss server I am facing below error on local. Can any one please help ?

Error :
An attempt was made to call a method that does not exist. The attempt was made from the following location:

   org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.configureParameterNameProvider(LocalValidatorFactoryBean.java:315)

The following method did not exist:

   javax.validation.Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;

The method's class, javax.validation.Configuration, is available from the following locations:

   jar:file:/D:/WebDev/jbdevstudio/runtimes/jboss-eap/modules/system/layers/base/javax/validation/api/main/validation-api-1.0.0.GA-redhat-3.jar!/javax/validation/Configuration.class
   vfs:/D:/WebDev/jbdevstudio/runtimes/jboss-eap/standalone/deployments/demo-0.0.1-SNAPSHOT.war/WEB-INF/lib/jakarta.validation-api-2.0.2.jar/javax/validation/Configuration.class

It was loaded from the following location:

   jar:file:/D:/WebDev/jbdevstudio/runtimes/jboss-eap/modules/system/layers/base/javax/validation/api/main/validation-api-1.0.0.GA-redhat-3.jar!/


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.validation.Configuration
3 years ago
I have a Spring mvc based web app where in DAO layer many try and catch blocks are there. We guys are planning to do some DB logging whenever any exception occurred.  I found there is a Global Exception Handler(@ExceptionHandler) in Spring using which I can get rid of applying DB loggers in various catch blocks but unfortunately  Global Exception Handler do not work as every time exception occurs its handled by existing catch block . is there any way to by pass existing catch blocks and use the global one ?
4 years ago
HTTP doesn't need "broken connections". The HTTP standard is nothing but broken connections. A client makes an HTTP URL request, the server processes it, returns a response and the client/server connection is closed. End of sentence. If you want to make another request, the client must open another connection. Again. And again. And again.

A well-behaved web application will spend a minimum amount of time processing that request and returning the response. The web is not the place for long-running request/response cycles. The browser will, in fact, eventually time out and break the request on its own if a response doesn't come back soon enough.

If you need ReST (or any other HTTP request) to set off a long-running process, then you should use the HTTP request to queue up an out-of-band processor and either poll for completion (as successive periodic HTTP requests) or provide some sort of callback mechanism to notify anyone who wants to know when the long-running request is done. Email, for example.


The out-of-band processor might be some sort of batch system, but you can also spawn an engine thread(s) in your webapp ServletContextListener startup listener.

On no account should a servlet or JSP attempt to spawn threads themselves, either directly or via methods invoked by the servlet or JSP. This violates the J2EE specification and can potentially randomly crash the entire webapp server.

On the other hand, the ServletContextListener can safely spawn threads. So a servlet or JSP can use a shared synchronized resource to push processing requests to those threads.



Can JMS be a good solution here ?
4 years ago
I want to break the connection between browser and REST service immediately as soon as the client send the request and let the processing continue in background async way.
Any suggestion please.
4 years ago
Appreciate if you can suggest me how to secure REST web services exposed using Spring/Jax-rs. I would like to learn any ways to secure it excluding Spring Security.
4 years ago
Service A sitting on JBOSS want to talk to Service B on Tomcat . Here  Service B is supposed to  perform multiple operations say 4(Create a Directory,Write to a file(Few KBs) and save it to directory,Update a DB Table and send an email).

is it optimum to refactor service B in 4 small services  and trigger those 4 from Jboss ? or i should have only one service only doing 4 stuffs in one shot ?  

5 years ago
My application submits the requests to JMS queue continuously using Spring's JMSTemplate . There are chances that request is not submitted to JMS queue due to any error condition or request is submitted but not consumed successfully.
Is there any way I can keep record those cases .  I am not sure how to find which message is consumed successfully and which one is failed.

Environment - Spring . Jboss.
5 years ago