This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Anirudh Gupta

Ranch Hand
+ Follow
since Dec 08, 2010
Anirudh likes ...
Java
India
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anirudh Gupta

I am trying to figure out ExpectedException's expectCause utility but can't get past 1 little detail. May be I am missing something trivial. A hint would be helpful.
Attaching code,



The above code keeps throwing an AssertionError like below,


java.lang.AssertionError:
Expected: exception with cause is <come.lets.learn.junit.tests.MyCustomException: java.lang.StringIndexOutOfBoundsException>
but: cause was <java.lang.StringIndexOutOfBoundsException>
Stacktrace was: come.lets.learn.junit.tests.MyCustomException: java.lang.StringIndexOutOfBoundsException
at come.lets.learn.junit.tests.ClassToTestExceptionsWithRule.letsThrowASubException(ExpectedExceptionRule.java:77)
at come.lets.learn.junit.tests.ExpectedExceptionRule.testSub(ExpectedExceptionRule.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.StringIndexOutOfBoundsException
... 30 more

at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at org.junit.Assert.assertThat(Assert.java:865)
at org.junit.Assert.assertThat(Assert.java:832)
at org.junit.rules.ExpectedException.handleException(ExpectedException.java:198)
at org.junit.rules.ExpectedException.access$500(ExpectedException.java:85)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:177)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)




Can someone please throw some light on what I am doing wrong?

Thanks.
5 years ago
Is it not entirely possible that the ReceivingThread never gets a chance to execute and the SendingThread KEEEEEEPPPSSS....... on executing without leaving the lock on the Semaphore object at all?
I got this example from Jakob Jenkov - Concurrency tutorial.
Can some one please elaborate and explain the example below about how the Semaphore is actually behaving like a Semaphore?



Thanks.
Oh shoot!

Done, and now it is atleast giving me a bunch of other exceptions. But this is resolved. Got the bad habit of trusting the IDE too much.

Thanks so much. Will mark this as resolved.
5 years ago
Hi again,

This is what my eclipse project and file structure looks like. I did what you suggested. Still does not work.
PLease refer the file attached. It is a screen shot, left side of vertical line is eclipse and right side is deskop explorer screen.

Regards.
5 years ago
Jayesh,

In my Maven project there was no META-INF folder that got created. I am using Eclipse. I intentionally did not convert the project into a faceted project.
I learnt about this META-INF requirement and manually created the META-INF folder into the src folder and added the persistence.xml file there. That did not help.
I kept it directly in the src folder, that didn't work either. I kept in both locations, that didnt work either.

Any other input/advice?

Thanks.
5 years ago
While trying to integrate Spring 4.0.6 with JPA2.1(EclipseLink 2.5.1) on JDK1.7 simple
J2se application(no J2ee container involved) I a facing the below error. I do not want to use Hibernate at all for this. Where and how do I have to declare the Provide? All units are given below.


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in class path resource [SpringJpaTemplate.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named spitterPU
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:549)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:515)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:682)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:655)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:353)
... 13 more
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named spitterPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:94)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 26 more





**Dao Class**


**Test Class**


**SpringConfig XML file**


**Persistence XML file**

5 years ago
Abhay,

The 2nd code item listing IS that very class - DemoParamConverter.class.

Thanks.
Anirudh.
6 years ago
Hi All,

While attempting to write a custom ParamConverterProvider I am facing a compile error which is a little strange. I am quiet sure it is trivial but am not able to quiet point it out.
The error is in the provider class on the return statement. "Type mismatch: cannot convert from DemoParamConverter to ParamConverter<T>"


Attaching the 3 artifacts of concern,

1. Provider


2. ParamConverter


3. The type to be converted
6 years ago
Ron,

Thanks again.

I was hoping, some one could throw some light from a holistic point of view on this particular behavior with JAX-RS, Jersey2.4, JDK1.7, and the URI mismatch scenario posed.

Right from,
1. How is HTTP supposed to work?
2. How a Java based HTTP container(eg. Tomcat) expected to behave under the circumstances?
3. What does the JAX-RS spec say about it, and
4. Is there some anomaly (specified or unspecified) by the Jersey reference implementation?

I would be grateful for the information/answers to the questions posed above or even a re-direction to any literature/blog/online learning tutorial etc.

Again, thanks in advance.

Regards,
Anirudh.
6 years ago
Ron,

Look at line 14 in the client code. Clearly using the OPTIONS method there. That is what I am referring to.

Thanks & Regards,
Anirudh
6 years ago
Hi All,

Bill Burke's book RESTful Java with JAX-RS2.0, Pages 53,54 suggest that the below code should throw a HTTP error 405.
Instead I keep getting response code 200.

Is it something I am doing wrong or is the book not in congruence with the specification?



Client Code:

6 years ago
Hi All,

I am trying to learn how to use MatrixParams in JAX-RS(Jersey 2.x). Everytime I pass a matrix param in my request, using a JAX-RS Client, the value in the server appears as "null".
Can some one please explain why this might be happening?
Below is the code snippet,

Server Code :-


Client :-

6 years ago
Hi German,

Thanks for that URL. The discussion there was quiet comprehensive.
I had been looking for something like that so I could raise a bug/issue.

How did you come across it? I guess it takes a Java Net Id to raise bugs/issues there.
6 years ago
Hi Tim,

Nailed it! Very lucid. That is precisely what I was looking for, "a scenario".

Thanks so very much again.
6 years ago
Hi Tim,

Thanks for taking the time to respond. I agree with your point and understand it.

However my doubt was more to do with ONLY the session object. An object which would anyway be created by the 1 thread that is serving the current request, if so required.

For this very session object to come into play again, a new request(being served by another thread-from pool or new Thread object, as you rightly pointed out) must contain
the JSESSIONID cookie associated for this very session object. It is my understanding that a client(browser or even a Java HTTP Client or any other) must set this header
to make a statefull call to an otherwise stateless protocol.

Now given the above scenario where and how can there be multiple threads wanting to access the same session object?

Mind you I agree with the fact that all objects in the J2ee environment must be stateless for threads.

Thanks.


6 years ago