Vertical separation in Spring MVC - spring

I am going to make a Spring MVC web application in which the application is separated vertically. Each module is going to encapsulate the functionalities related to the same feature.
Let consider an imaginary simple example:
feature-1: User can add/remove/edit Cartesian coordinate (x,y).
feature-2: Show the coordinates in a plane chart.
So the vertical separation that I considered here is one module for feature-1 and another module for feature-2.
Module 1: includes the entities, persistence and views for add/remove/edit
Module 2: includes the service to read coordination from persistence and a view for the chart.
I also considered another module that is just index page and a controller that loads that index page in which it is just a container for the other modules to load their view there. This index page will have a navigation bar for add coordinate and show chart. These navigation should hand over the control to another controller which is in another module.
I build this project structure:
─── project
│
├── add-coordinate
│ ├── src
│ │ └── main
│ │ ├── java
│ │ │ └── com.example.coordinate.add
│ │ │ ├── controller
│ │ │ │ └── CoordinateController.java
│ │ │ ├── persistence
│ │ │ │ └── CoordinateRepository.java
│ │ │ └── entity
│ │ │ └── coordinate.java
│ │ └── resources
│ │ └── static
│ │ ├── css
│ │ │ └── style.css
│ │ └── templates
│ │ └── coordinate.html
│ └── pom.xml
│
├── show-coordinate
│ ├── src
│ │ └── main
│ │ ├── java
│ │ │ └── com.example.coordinate.show
│ │ │ ├── controller
│ │ │ │ └── ShowCoordinateController.java
│ │ │ └── service
│ │ │ └── CoordinateService.java
│ │ └── resources
│ │ └── static
│ │ ├── css
│ │ │ └── style.css
│ │ └── templates
│ │ └── showCoordinate.html
│ └── pom.xml
│
├── index-coordinate
│ ├── src
│ │ └── main
│ │ ├── java
│ │ │ └── com.example.coordinate.index
│ │ │ ├── controller
│ │ │ │ └── IndexController.java
│ │ │ └── IndexApplication.java
│ │ └── resources
│ │ └── static
│ │ ├── css
│ │ │ └── style.css
│ │ └── templates
│ │ └── index.html
│ └── pom.xml
│
└── pom.xml
This is the parent pom.xml (unrelated parts are omitted):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.example</groupId>
<artifactId>coordinate</artifactId>
<version>${revison}</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
</parent>
<properties>
...
<!-- Project Version -->
<build.type>SNAPSHOT</build.type>
<variance.version>1.0.0</variance.version>
<revison>${variance.version}-${build.type}</revison>
</properties>
<modules>
<module>index-coordinate</module>
<module>add-coordinate</module>
<module>show-coordinate</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And this is add-coordinate pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>add-coordinate</artifactId>
<parent>
<groupId>com.example</groupId>
<artifactId>coordinate</artifactId>
<version>${revison}</version>
</parent>
<properties>
<start-class>com.example.coordinate.index.IndexApplication</start-class>
</properties>
<dependencies>
<dependency>-->
<groupId>com.example</groupId>
<artifactId>coordinate-index</artifactId>
<version>${revison}</version>
</dependency>
<!--other dependecies like Spring Boot, Sprong MVC, DB, ...-->
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is the controller for add-coordinate:
#Controller
public class CoordinateController {
#RequestMapping("/coordinate")
public String addCoordinatePage() {
return "coordinate";
}
}
Now, index page is loaded properly, but the problem is that when the nav bar for add coordinate is clicked and the request is sent to http://localhost:8080/coordinate, the page cannot be resolved. Which means the controller has not been started with my application. Does anyone know how I can resolve this problem?

The problem solved by adding the following annotation to IndexApplication
#SpringBootApplication
#ComponentScan(basePackages = {"com.example.coordinate.*"})
#EnableJpaRepositories(basePackages = {"com.example.coordinate.*"})
#EntityScan(basePackages = {"com.example.coordinate.*"})
public class IndexApplication {
public static void main(String args[]) {
SpringApplication.run(Application.class);
}
}
And added the

Related

Where store Tests (project structure - best practice)?

We have many different ways to implement project structure in GO.
My question is where the best way to store tests implementation:
separately (as Java Maven/Gradle standard)
├── pkg
│ ├── colocator
│ │ ├── some_impl.go
│ │ └── ...
│ ├── common
│ │ └── ...
│ └── dashboard
│ └── ...
├── test
│ │ └── internal
│ │ └── some_test_utils.go
│ ├── pkg
│ │ ├── colocator
│ │ │ ├── mocks
│ │ │ │ └── some_mock.go
│ │ │ └── some_impl_test.go
│ │ ├── ...
in place
├── pkg
│ ├── colocator
│ │ ├── mocks
│ │ │ └── some_mock.go
│ │ ├── some_impl.go
│ │ └── some_impl_test.go
etc...
?
Your second implementation is the 'correct' go way. Also you dont have to worry about those tests taking up space or something. The compiler ignores when you build the package.

Is there a way to generate static html pages with Microsoft.AspNet.WebApi.HelpPage?

Currently, thanks to Microsoft.AspNet.WebApi.HelpPage, I'm able to see API help page.
But I need to run (or publish and deploy to IIS) that ASP.NET Web application.
Does Microsoft.AspNet.WebApi.HelpPage provide any functionality to generate static API help html pages?
Not perfect solution, but using wget I was able to go through all help pages and save them all.
Example:
$ wget -r -k -E http://<ip_address>/Help/
$ tree
.
└── <ip_address>
├── Areas
│ └── HelpPage
│ └── HelpPage.css
├── Help
│ ├── Api
│ │ ├── DELETE-api-delivery-Data0-is
│ │ ├── DELETE-api-master-Data1-id
│ │ ├── DELETE-api-master-Data2-id
│ │ ├── DELETE-api-master-Data3-id
│ │ ├── DELETE-api-master-Data4-id
│ │ ├── DELETE-api-master-Data5-id
│ │ ├── GET-api-OtherApi1
│ │ ├── GET-api-OtherApi2
│ │ ├── GET-api-OtherApi3
│ │ └── GET-api-OtherApi4
│ ├── index.html
│ ├── ResourceModel#modelName=Data1
│ ├── ResourceModel#modelName=Data2
│ ├── ResourceModel#modelName=Data3
│ ├── ResourceModel#modelName=Data4
│ └── ResourceModel#modelName=Data5
└── Help.1

Using environment specific group/host_vars and mapping to var subdirectories in Ansible

I'm having issues finding good documentation for how to use environment specific (i.e. dev & test) group_vars and host_vars, then map down to subdirectories that are specific to large chunks of infrastructure (the wso2 directories).
Ideally, I should be able to say somewhere in my inventory or playbook dev or test and it should just route to dev or test then specify wso2 and have it look there.
.
├── group_vars
│ ├── dev
│ │ └── wso2
│ │ ├── apim-analytics.yml
│ │ ├── apim-is-as-km.yml
│ │ └── apim.yml
│ └── test
│ └── wso2
│ ├── apim-analytics.yml
│ ├── apim-is-as-km.yml
│ └── apim.yml
├── host_vars
│ ├── dev
│ │ └── wso2
│ │ ├── apim-analytics-dashboard_1.yml
│ │ ├── apim-analytics-worker_1.yml
│ │ ├── apim-gateway_1.yml
│ │ ├── apim-is-as-km_1.yml
│ │ ├── apim-km_1.yml
│ │ ├── apim-publisher_1.yml
│ │ ├── apim-store_1.yml
│ │ ├── apim-tm_1.yml
│ │ ├── wso2-apim-01.yml
│ │ └── wso2-apim-02.yml
│ └── test
│ └── wso2
│ ├── apim-analytics-dashboard_1.yml
│ ├── apim-analytics-worker_1.yml
│ ├── apim-gateway_1.yml
│ ├── apim-is-as-km_1.yml
│ ├── apim-km_1.yml
│ ├── apim-publisher_1.yml
│ ├── apim-store_1.yml
│ ├── apim-tm_1.yml
│ ├── wso2-apim-01.yml
│ └── wso2-apim-02.yml
There is great documentation about all other subjects around ansible... just not this, so any help is appreciated.
Thanks all :)

JBoss + Maven: Error building POM

I am trying to launch JBoss application server - my goal is to launch it and deploy some very simple project (I'm trying to do this with "helloworld" from the original quickstarts). The problem is that I have no experience with JBoss or Maven, so I'm having terrible time for a few days and it still isn't working. I presume, that the mistake is in Maven configuration, but I don't know, what I'm supposed to rewrite / replace to repair it.
This is the exact error:
[INFO] Error building POM (may not be this project's POM).
Project ID: org.jboss.component.management:jboss-dependency-management-all
Reason: POM 'org.jboss.component.management:jboss-dependency-management-all' not found in repository: Unable to download the artifact from any repository
org.jboss.component.management:jboss-dependency-management-all:pom:6.0.1-redhat-1
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.jboss.component.management:jboss-dependency-management-all
I was trying to follow instructions given at http://www.jboss.org/quickstarts/eap/#build-and-deploy-th%20e-quickstarts , so my only configuration of Maven was, that I copied settings.xml from quickstart directory to .m2 directory.Finally I tried to build and deploy quickstart by command "mvn clean install jboss-as:deploy", but it caused the error :-(
How to repair this mistake?
P.s.: I use Ubuntu 14.04.
This is how the structure of my folder with JBoss looks like:
.
├── InstallationLog.txt
├── InstallSummary.html
├── jboss-eap-6.2
│ ├── appclient
│ ├── bin
│ ├── bundles
│ ├── docs
│ ├── domain
│ ├── icons
│ ├── JBossEULA.txt
│ ├── jboss-modules.jar
│ ├── LICENSE.txt
│ ├── modules
│ ├── standalone
│ ├── version.txt
│ └── welcome-content
├── jboss-eap-6.2.0.GA-quickstarts
│ ├── bean-validation
│ ├── bmt
│ ├── cdi-alternative
│ ├── cdi-decorator
│ ├── cdi-injection
│ ├── cdi-interceptors
│ ├── cdi-portable-extension
│ ├── cdi-stereotype
│ ├── cdi-veto
│ ├── cluster-ha-singleton
│ ├── cmt
│ ├── configure-postgresql.cli
│ ├── CONTRIBUTING.html
│ ├── CONTRIBUTING.md
│ ├── contributor-settings.xml
│ ├── dist
│ ├── ejb-asynchronous
│ ├── ejb-in-ear
│ ├── ejb-in-war
│ ├── ejb-multi-server
│ ├── ejb-remote
│ ├── ejb-security
│ ├── ejb-security-interceptors
│ ├── ejb-throws-exception
│ ├── ejb-timer
│ ├── forge-from-scratch
│ ├── greeter
│ ├── guide
│ ├── helloworld
│ ├── helloworld-jms
│ ├── helloworld-mbean
│ ├── helloworld-mdb
│ ├── helloworld-osgi
│ ├── helloworld-rs
│ ├── helloworld-singleton
│ ├── helloworld-ws
│ ├── hibernate3
│ ├── hibernate4
│ ├── hornetq-clustering
│ ├── h2-console
│ ├── inter-app
│ ├── jax-rs-client
│ ├── jta-crash-rec
│ ├── jts
│ ├── jts-distributed-crash-rec
│ ├── kitchensink
│ ├── kitchensink-ear
│ ├── kitchensink-jsp
│ ├── kitchensink-ml
│ ├── kitchensink-ml-ear
│ ├── LICENSE.txt
│ ├── logging
│ ├── logging-tools
│ ├── log4j
│ ├── mail
│ ├── numberguess
│ ├── payment-cdi-event
│ ├── picketlink-sts
│ ├── pom.xml
│ ├── README.html
│ ├── README.md
│ ├── RELEASE_PROCEDURE.html
│ ├── RELEASE_PROCEDURE.md
│ ├── remove-postgresql.cli
│ ├── servlet-async
│ ├── servlet-filterlistener
│ ├── servlet-security
│ ├── settings.xml
│ ├── shopping-cart
│ ├── tasks
│ ├── tasks-jsf
│ ├── tasks-rs
│ ├── temperature-converter
│ ├── template
│ ├── wicket-ear
│ ├── wicket-war
│ ├── wsat-simple
│ ├── wsba-coordinator-completion-simple
│ ├── wsba-participant-completion-simple
│ ├── xml-dom4j
│ └── xml-jaxp
└── Uninstaller
└── uninstaller.jar
settings.xml: http://hostcode.sourceforge.net/view/1926
pom.xml: http://hostcode.sourceforge.net/view/1927
Eventually I've solved this - thorough delete of all Maven files ( or files which held some deprecated info about Maven ) and installation of its newest version was the key :-)
This solution is written for Ubuntu 14.04 LTS (but it should work in other versions and even other Debian-based systems too).
STEP-BY-STEP SOLUTION:
1) Completely uninstall Maven
sudo apt-get purge maven
2) Uninstall libaether package
sudo apt-get purge libaether-java
3) Uninstall libplexus packages
sudo apt-get purge libplexus-*
4) Finally, install actual Maven version from the repository
sudo apt-get install maven

Where to find source code of Mozilla NoScript extension?

I read in wiki that NoScript is open source http://en.wikipedia.org/wiki/NoScript, but on official site http://noscript.net/, I can't find any sources. So my question is: where to find sources? Or, is there something I did not understand, and the source code is not available?
The Firefox XPI format does not prevent you from simply extracting the contents of the plugin to examine the source code.
While I cannot find a canonical public repository, it looks like someone has systematically downloaded and extracted all the available XPIs and created a GitHub repository out of them.
https://github.com/avian2/noscript
If you'd like to do it yourself, XPI files are just standard ZIP files, so if you want to extract one yourself you can simply point an extraction program at it.
Here's an example of doing that from the command line:
mkdir noscript_source
cd noscript_source
curl -LO https://addons.mozilla.org/firefox/downloads/file/219550/noscript_security_suite-2.6.6.8-fx+fn+sm.xpi
unzip noscript_security_suite-2.6.6.8-fx+fn+sm.xpi
That yields a directory structure that looks like this:
.
├── GPL.txt
├── META-INF
│ ├── manifest.mf
│ ├── zigbert.rsa
│ └── zigbert.sf
├── NoScript_License.txt
├── chrome
│ └── noscript.jar
├── chrome.manifest
├── components
│ └── noscriptService.js
├── defaults
│ └── preferences
│ └── noscript.js
├── install.rdf
├── mozilla.cfg
└── noscript_security_suite-2.6.6.8-fx+fn+sm.xpi
Then the main code is located inside chrome/noscript.jar. You can extract that to get at the JavaScript that makes up the bulk of the plugin:
cd chrome/
unzip noscript.jar
Which will yield the main source tree:
.
├── content
│ └── noscript
│ ├── ABE.g
│ ├── ABE.js
│ ├── ABELexer.js
│ ├── ABEParser.js
│ ├── ASPIdiocy.js
│ ├── ChannelReplacement.js
│ ├── ClearClickHandler.js
│ ├── ClearClickHandlerLegacy.js
│ ├── Cookie.js
│ ├── DNS.js
│ ├── DOM.js
│ ├── ExternalFilters.js
│ ├── FlashIdiocy.js
│ ├── HTTPS.js
│ ├── Lang.js
│ ├── NoScript_License.txt
│ ├── PlacesPrefs.js
│ ├── Plugins.js
│ ├── Policy.js
│ ├── Profiler.js
│ ├── Removal.js
│ ├── RequestWatchdog.js
│ ├── STS.js
│ ├── ScriptSurrogate.js
│ ├── Strings.js
│ ├── URIValidator.js
│ ├── about.xul
│ ├── antlr.js
│ ├── clearClick.js
│ ├── clearClick.xul
│ ├── frameOptErr.xhtml
│ ├── iaUI.js
│ ├── noscript.js
│ ├── noscript.xbl
│ ├── noscriptBM.js
│ ├── noscriptBMOverlay.xul
│ ├── noscriptOptions.js
│ ├── noscriptOptions.xul
│ ├── noscriptOverlay.js
│ ├── noscriptOverlay.xul
│ ├── options-mobile.xul
│ └── overlay-mobile.xul
├── locale
└── skin
The extension contains the source code - you just need to unzip it. See Giorgio's response here.
The whole source code is publicly available in every each XPI.
You've got it on your hard disk right now, if you're a NoScript user, otheriwise you can download it here.
You can examine and/or modify it by unzipping the XPI and the JAR inside, and "building" it back by rezipping both.
It's been like that for ever, since the very first version.

Resources