Spring file upload goes to Access denied page

Spring file upload goes to Access denied page

When Spring security is enabled, when I upload a file using multipart, SpringSecurity redirects me to Access denied url.

Refer to https://stackoverflow.com/questions/28225359/file-upload-spring-security
I amend my Initializer as follows!


@EnableScheduling
@EnableAsync
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(servletContext, new MultipartFilter());
}
}

This error disappears. I landed in another problem. I’m resolving it now!!

Advertisements

Spring 5 migration: Unable to find setter method for attribute: [commandName]

Spring 5 Migration brings this pain. You will get this error during form submission.

Unable to find setter method for attribute: [commandName]

Command object does not work anymore.

Refer to https://stackoverflow.com/questions/46989072/org-apache-jasper-jasperexception-web-inf-views-home-jsp-line-25-column/48364974
and
https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x

commandName is dead in Spring 5. Replace it with modelAttribute


<form:form modelAttribute="customer" action="customerView" method="post">

It worked! I need to make this change in my workspace now!

Migrating to Hibernate 5: Table ‘crm.hibernate_sequence’ doesn’t exist

I’m doing upgrading Spring 4 to Spring 5 and Hibernate 4 to 5.
My existing functionality refused to work. It broke with the following exception.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘crm.hibernate_sequence’ doesn’t exist

I’m using MariaDB/MySQL. I don’t have to maintain any sequence tables as Oracle. In addition, it was working without any issues. All my primary keys are autogenerated with the following annotations.

@Id
@GeneratedValue
@Column(name=”ID”)
private Long id;

Thanks to https://stackoverflow.com/questions/32968527/hibernate-sequence-doesnt-exist

Adding hibernate.id.new_generator_mappings=false to Hibernate properties solved the problem.

Eclipse tomcat does not start – May be locked by another process.

Happy Western New Year 2019!

I had a single spring web project. It became too big over the day. I had to split it up into multiple reusable projects so that I can build APIs. After I split it, Tomcat refused to start with the following error.


Publishing failed with multiple errors
Could not delete D:/Pandian/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/crm-upload/WEB-INF/lib. May be locked by another process.
Could not delete D:/Pandian/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/crm-upload/WEB-INF. May be locked by another process.

I tried to clean work folder, It doesn’t work. I did the following sequence to resolve this.

  1. Remove the tomcat server from eclipse server tab
  2. Restart Eclipse
  3. Add a new tomcat server
  4. Start the project

 

Read properties values in Java Spring Controller

To configure the environmental parameters, we read the values from property files. I have a controller which upload the files. The uploaded files will be saved in a location, which is defined in a property file. In this example I shall show you how to read the location name from the property file.


@Controller
@PropertySource("classpath:app.properties")
public class FileUploadController {
  @Value("${upload.Folder}")
  String uploadFolder;
}

I have defined the property in app.properties file which is saved in src folder (or any other path defined in classpath.


upload.Folder=C:\\vss\\upload

Thats it! The variable uploadFolder will be assigned using the values given by app.properties.

Increase the partition size of a Unix VM in XenServer

Distribution: Ubuntu 18.04

This is how I increased the disk partition size of my Ubuntu virtual machine running in XenServer.

Using fdisk, view the partition information, delete the old partition, add a new partition with extended size, save the partition. This is the workflow followed below. Pls note that the partition will not be commited, until you confirm.


# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux

Command (m for help): ^C
# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 419430399 208665600 8e Linux LVM

Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-838860799, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-838860799, default 838860799):
Using default value 838860799
Partition 2 of type Linux and of size 399 GiB is set

Command (m for help): p

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 838860799 418380800 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
# fdisk -l

Disk /dev/xvda: 429.5 GB, 429496729600 bytes, 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b3935

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 2099199 1048576 83 Linux
/dev/xvda2 2099200 838860799 418380800 83 Linux

Disk /dev/mapper/cl_mgr-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl_mgr-swap: 3892 MB, 3892314112 bytes, 7602176 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/cl_mgr-home: 156.1 GB, 156086829056 bytes, 304857088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes