Mike Tabak

Ranch Hand
+ Follow
since Mar 31, 2012
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Tabak

I am looking at an example from Wall's Spring Boot In Action, chapter 3. This is a simple Boot MVC project using Spring Security. The default security configuration is overridden by the following class:



This class defines a custom UserDetails implemneted by the Reader class.The Reader class looks like:



There is one controller, ReadingListController:



The SecurityConfig class obtains the Reader from the injected readerRepository which is a JpaRepository<Reader, String>. When you boot up the application and go to localhost:8080/ you are presented with the login page. When you log in, the ReadingListController.readersBooks(Reader reader, Model model) method is called. This is passed a Reader object populated via the username used in logging in. Spring is passing the Reader object, looked up in the database, to the controller. I'm wondering why this happens. I have seen Principal passed to a controller annotated with @AuthenticationPrincipal, and have seen controllers access the SecurityContext to retrieve the principal, but have not seen it done this way. My question is, is Spring passing in Reader because it implements UserDetails? if not, why is Spring passing in the correct Reader object?
3 years ago

Bear Bibeault wrote:So what's your question?

Also, it's best to show the client-side markup in this forum, rather than the server-side source.



My question is I was able to align the <input>s and <labels>s, but now the form shifted to left justification. I want
to keep the form centered as in the first image.
I have a Spring MVC project using Thymeleaf. I have a submission given by the following file:



The css file is



I want to align the <label>s and <input>s and center them, so I modified the form to be a CSS table. I changed the
HTML file to enclose the <label>s and <input>s with <p></p> as follows:



Then I added the following to my CSS file:


This aligned the <label>s and <input>s, but does not center them. The before and after shots look like:


I'm modifying a project from Spring In Action by Walls. The project is chapter six's thymeleaf mvc project. I'm adding a confirm password field to the registration form which is backed by a Spitter Object. I add validation to the project to check for the length of the password field and to check that the password and confirmPassword fields match. The Spitter form backing object is



The SpitterController is



The registrationForm is



I have a message resource bundle for Spring-manage messages, messages.properties:



And a ValidationMessages.properties for the JSR 303 and Hibernate Validator messages:



The message validation seems to work well except for one issue. When I force a password mismatch, I see something like the following (see attached png file):

Register

Please fix the following error(s)

spitter.password.mismatch.message
Your passwords don't match. Please try again
....

Instead of the single "Your passwords don't match. Please try again." message, I also see "spitter.password.mismatch.message" as a message and can't figure out why.
3 years ago

Simon Roberts wrote:Because backslash in a String literal is special. It introduces special character sequences that represent other characters, most well known being \n that represents newline. Since backslash is special, it cannot stand alone; if you try it, the compiler will assume that the immediately following character is to be interpreted as special. So, if you want a backslash in a String or a char literal, you must use two, which creates a "special character sequence" that represents the single backslash.



That seems to imply what the pattern is looking for is something of the form "\@name", but this isn't the case. Note the test string I am using, it contains "@name...." not "\@name...".
3 years ago
I'm looking at some code that extracts a username from some text of the form "@name - this is a message". The code is:



When run, the above prints out: "Found: name". I understand most of what is going on, except for the '\\@' portion of the regex. I'm not sure why there are two backslashes here. This will yield the same result if I remove those two backslashes.
3 years ago
I was able to get this project to run with the following XML configuration file



and the following jars on the classpath
activemq-all-5.7.0.jar
activemq-core-5.7.0.jar
activemq-spring-5.7.0.jar
commons-logging-1.2.jar
spring-aop-4.0.7.RELEASE.jar
spring-beans-4.0.7.RELEASE.jar
spring-context-4.0.7.RELEASE.jar
spring-core-4.0.7.RELEASE.jar
spring-expression-4.0.7.RELEASE.jar
spring-jms-4.0.7.RELEASE.jar
spring-tx-4.0.7.RELEASE.jar
xbean-spring-3.7.jar
3 years ago
The spring-core is the in compile dependencies and on the classpath when I run. I think there is something more fundamentally wrong with this project. I removed all dependency on the amq namespace by declaring the queue, topic and connection factory beans directly as follows:



I then removed the declaration of the amq namespace from messaging.xml. I ran this and got the following exception:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/jms]
Offending resource: class path resource [META-INF/spring/messaging.xml]

I suspect this problem isn't a jms or amq namespace declaration problem, but something more fundamental, but I'm not sure what. I then went and added the amq namespace to my older JMS project and added a queue as a test, here is what that XML config file looks like:



That project will start up without any exceptions. I compared the dependencies between the two projects and aside from the older project containing jars for webmvc and spring security (it is a web project), I can't see anything significant such as an obviously missing dependency. I'm kind of stumped at this point. I've posted this problem to the books webiste, and sent the author a tweet on this problem, but no response so far.
3 years ago
The original messaging.xml is



This produces the exception:

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://activemq.apache.org/schema/core]
Offending resource: class path resource [META-INF/spring/messaging.xml]
...
at spittr.JMSMain.main(JMSMain.java:9)

When I change to use explicit version of schema (5.7.0):



I still get the above exception. Note this is not the exception I reported earlier, it is the same exception in both cases, so at some point, something different
happened the last time I tested, I'm not sure what. But I retested both versions of messaging.xml this time.
3 years ago
Yes, I read the documentation, though I find it confusing. I am using ActiveMQ 5.7, accordingly:



I used this with http://activemq.apache.org/schema/core/activemq-core-5.7.0 for version 5.7. This results in the following exception:

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 7 in XML document from class path resource [META-INF/spring/messaging.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://activemq.apache.org/schema/core/activemq-core-4.1.2.xsd; lineNumber: 7; columnNumber: 55; TargetNamespace.1: Expecting namespace 'http://activemq.apache.org/schema/core', but the target namespace of the schema document is 'http://activemq.org/config/1.0'.

Which is confusing as the exception references activemq.apache.org/schema/core/activemq-core-4.1.2.xsd. I find the following confusing:

" Expecting namespace 'http://activemq.apache.org/schema/core', but the target namespace of the schema document is 'http://activemq.org/config/1.0'."

I'm not sure what this is saying, is it saying the file has "http://..../schema/core", but should have "http://..../config/1.0? or vice versa? At any rate, changing to http://..../config/1.0 results in a similar exception, only with the expected and target namespaces reversed. Something else here is missing.
3 years ago

g tsuji wrote:I would advance that start by scripting a definitive and explicit version of activemq-core schema xsd to test the project, do you think not?....



I'm not sure what you mean by this?
3 years ago

which is your case (as you include the xbean dependency in the gradle build. Now, if you look at the left column, you will see the it starts documenting from xbean 4.1 upward. Yours is specifying 3.7... which means if you want to use properly that documentation, you need to change to at least 4.1. _But_, that is not enough, as you are using the namespace http://activemq.apache.org/schema/core, and you look at the right column for the namespace for a match up, you would therefore have to change the xbean version to at least 5.1 or up. After that, the application would begin in good shape.



Thanks much. The latest version I can find of xbean-spring is 4.3 (Maven Central). It is dated May 2015. I tried using it for giggles and had the same error.

It is interesting to note that I have an earlier project I did which performed some basic sending and receiving of JMS text and object messages. I looked at the configuration of that project. It is an Eclipse Maven project. The JMS config file in that project is



Notice it does not call out a specific version of the activemq-core.xsd like the Gradle project. This project uses ActiveMQ 5.8. The pom contains xbean-spring-3.7.jar. This appears to be a similar configuration to the Gradle project and the Eclipse project runs fine. Also note for the Eclipse project I did not have to do anything special to Eclipse for that project.
3 years ago
I am looking at another project from Spring In Action Volume 4 by Craig Walls. In chapter 17 there is a simple jms project that sets up a
sender and a Message Listener. This is a Gradle project. The build.gradle file is



The project has a main class:


The jms configuration file (messaging.xml) is:



When I build the jar file and execute it, I get the following exception:



I looked at the following ActiveMQ page, which seems to address this, but could not resolve the issue ActiveMQ XML Reference
Would appreciate help to resolve this.
3 years ago
I believe the XML files are there for information only, to show how some of the config would be done for an application using XML configuration. As far as AbstractAnnotationConfigDispatcherServletInitializer vs. WebApplicationInitializer go, this may help: AbstractAnnotationConfigDispatcherServletInitializer and WebApplicationInitializer
3 years ago
I'm looking at a Spring MVC Java configuration file from Craig Walls' Spring In Action volume 4:



The addResourceHandlers(...) method is equivalent to the XML configuration element <mvc:resources.../> element. I'm use to seeing something like
<mvc:resources mapping="/resources/**" location="/resources"/> for static resources located in /webapp/resources/, as is the case in the book's projects. In this case, the call above should equate to



according to my understanding of the Spring documentation. I'm wondering why the call in the WebConfig.java file above seems to work?
3 years ago