How to convert a ArrayList into 2D array jn Java 7

I am trying to convert a Integer list in a 2D array in java 7. I first converted a String list to Integer and then Integer list to 2D array. Then I will do more operations as required.
What I tired is

List<String> list = Arrays.asList("1", "2", "3", "4");
    List<Integer> intList = new ArrayList<>();
    for (String s : list) {
        intList.add(Integer.valueOf(s));
    }
    //the problem is from here
    int[][] array = new int[intList.size()][];
    for (int i = 0; i < list.size(); i++) {
        for (int j = 0; j < list.size(); j++) {
            array[i][j] = intList.get(j + (list.size() * i));
        }
    }

I tried solving my issue looking at this Converting an ArrayList into a 2D Array and this Convert ArrayList into 2D array containing varying lengths of arrays but majority of the answers are given in java 8 which I don’t want! i know its a basic problem but i am stuck! Can someone help me to fix this? Thanks in advance!

Go to Source
Author: Code Dexter

How to apply MVC pattern in JavaFX with nested classes

I am trying to create a Calendar application in JavaFX using MVC. What I have in mind is something as what is shown in the image below:

Calendar draft

Basically:

  • I have a CalendarView (red background) showing the title of the calendar (“Calendar for today”) and the labels of the hours of the day. This CalendarView includes a container (blue background), that works as a holder for the individual appointments.
  • I have an AppointmentView (green background) which is generated for each and every appointment in the calendar.

Based on this scenario, my idea would be doing something as follows:

  1. Create an AppointmentModel class as model for the appointment
  2. Create a CalendarModel class as model for the calendar. This class includes a list of AppointmentModel
  3. Create a controller for the appointment, called AppointmentController. This controller will include an instance of an AppointmentModel class and an AppointmentView class
  4. Create a controller for the calendar, called CallendarController. This controller will include an instance of a CalendarModel class and CalendarView class

I have written the following pseuocode to describe this scenario:

public class AppointmentModel {
    ...
}

public class CalendarModel {
    List<AppointmentModel> appointments;
    
    ...
}

public class AppointmentController {
    AppointmentModel model;
    AppointmentView view;

    ...
}
public class CalendarController {
    CalendarModel model;
    CalendarView view;

    ...
}

The problem I find now is how to link the calendar and the appointments. In the code above I have included List<AppointmentModel> appointments; inside CalendarModel, but by doing this, I do not know what to do with AppointmentController. Only thing I could think of is including a List<ApointmentControllers> ... in CalendarController and removing the List<AppointmentModel> ... from CalendarModel, but this does not make sense for me, as the CalendarModel, by definition, implies a list of appointments.

What am I missing in my reasoning?

Go to Source
Author: Fernando Cereijo

Spring-webflow SnapshotCreationException Error after login

I am working with a java project with spring-webflow and fimefaces 3.3.
The version of primefaces cannot be increased due to menu developments and other components that generate an error when trying to upload the version. The problem is not this.

The problem comes from setting the max-execution-snapshots property. If I put a value other than 0, it generates the exception indicated by the statement.

I thought that it could be the objects that some were not serialized, but I have implemented serialization and it continues with the same result.
Before refactoring the project, passing it from ant build to Maven, it was not necessary to indicate in the flow-executor the flow-execution-repository. The most curious thing is that they are the same libraries that are used:
spring-faces-2.4.1.RELEASE, spring-webflow-2.4.1.RELEASE and the rest of spring are 4.3.16.RELEASE.

When the application loads, it makes a call to return a list, but this is not the fault. I guess the problem must be in the call to the WebService because the error it throws in the rootcase is: java.io.NotSerializableException: org.apache.cxf.jaxws.JaxWsClientProxy

I don’t know if it’s also a problem with the filters, I don’t know exactly. I have been looking for a solution for several days, but it has not been possible.

I put here the stacktrace and the spring-webflow configuration
Thanks in advance!

spring-webflow.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:webflow="http://www.springframework.org/schema/webflow-config"
   xmlns:faces="http://www.springframework.org/schema/faces"
   xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/webflow-config
        http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd
        http://www.springframework.org/schema/faces 
        http://www.springframework.org/schema/faces/spring-faces.xsd">

    <faces:resources/>

    <!-- Spring Webflow central configuration component -->
    <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
        <webflow:flow-execution-repository max-executions="10" max-execution-snapshots="-1"/>
        <webflow:flow-execution-listeners>          
            <webflow:listener ref="facesContextListener"/>          
            <webflow:listener ref="securityListener"/>
        </webflow:flow-execution-listeners>
    </webflow:flow-executor>
    
    <!-- Installs a listener that creates and releases the FacesContext for each request. -->   
    <bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>   
    
    <webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" 
        base-path="/WEB-INF/flows/" >
        <webflow:flow-location-pattern value="/**.xml" />
        <webflow:flow-location id="parent-flow" path="parent-flow.xml" />
    </webflow:flow-registry>
    
    <!-- Configures the Spring Web Flow JSF integration --> 
    <faces:flow-builder-services id="facesFlowBuilderServices" development="true" />
    
    <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
        <property name="viewResolvers">
            <list>
                <ref bean="viewResolver"/>
            </list>
        </property>     
    </bean>
    
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/WEB-INF/views/"/>
          <property name="suffix" value=".xhtml" />
    </bean>
          
    <!-- Dispatches requests mapped to flows to FlowHandler implementations --> 
    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">      
        <property name="flowExecutor" ref="flowExecutor" /> 
    </bean>
    
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="flowRegistry"/>
        <property name="order" value="1"/>
    </bean>
    
</beans>

The filters shown in the stacktrace are from third parties, we don’t have the code

StackTrace

JBWEB000065: HTTP Status 500 - Request processing failed; nested exception is org.springframework.webflow.execution.repository.snapshot.SnapshotCreationException: Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable


JBWEB000309: type JBWEB000066: Exception report

JBWEB000068: message Request processing failed; nested exception is org.springframework.webflow.execution.repository.snapshot.SnapshotCreationException: Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable

JBWEB000069: description JBWEB000145: The server encountered an internal error that prevented it from fulfilling this request.

JBWEB000070: exception 
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.webflow.execution.repository.snapshot.SnapshotCreationException: Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    com.jeveris.web.core.filter.log.PerformanceLogFilter.doFilter(PerformanceLogFilter.java:55)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    com.axa.ca.caem.credentials.IamAuthenticationFilter.doFilter(IamAuthenticationFilter.java:116)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)



JBWEB000071: root cause 
org.springframework.webflow.execution.repository.snapshot.SnapshotCreationException: Could not serialize flow execution; make sure all objects stored in flow or flash scope are serializable
    org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.<init>(SerializedFlowExecutionSnapshot.java:75)
    org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.createSnapshot(SerializedFlowExecutionSnapshotFactory.java:70)
    org.springframework.webflow.execution.repository.snapshot.AbstractSnapshottingFlowExecutionRepository.snapshot(AbstractSnapshottingFlowExecutionRepository.java:75)
    org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.putFlowExecution(DefaultFlowExecutionRepository.java:126)
    org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:145)
    org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:238)
    org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:57)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    com.jeveris.web.core.filter.log.PerformanceLogFilter.doFilter(PerformanceLogFilter.java:55)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    com.axa.ca.caem.credentials.IamAuthenticationFilter.doFilter(IamAuthenticationFilter.java:116)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)



JBWEB000071: root cause 
java.io.NotSerializableException: org.apache.cxf.jaxws.JaxWsClientProxy
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
    java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    java.util.HashMap.internalWriteEntries(HashMap.java:1793)
    java.util.HashMap.writeObject(HashMap.java:1363)
    sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1140)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
    java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
    org.springframework.webflow.core.collection.LocalAttributeMap.writeObject(LocalAttributeMap.java:333)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1140)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    org.springframework.webflow.engine.impl.FlowSessionImpl.writeExternal(FlowSessionImpl.java:162)
    java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    java.util.LinkedList.writeObject(LinkedList.java:1131)
    sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1140)
    java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    org.springframework.webflow.engine.impl.FlowExecutionImpl.writeExternal(FlowExecutionImpl.java:311)
    java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
    java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
    java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
    java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
    org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.serialize(SerializedFlowExecutionSnapshot.java:173)
    org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshot.<init>(SerializedFlowExecutionSnapshot.java:70)
    org.springframework.webflow.execution.repository.snapshot.SerializedFlowExecutionSnapshotFactory.createSnapshot(SerializedFlowExecutionSnapshotFactory.java:70)
    org.springframework.webflow.execution.repository.snapshot.AbstractSnapshottingFlowExecutionRepository.snapshot(AbstractSnapshottingFlowExecutionRepository.java:75)
    org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.putFlowExecution(DefaultFlowExecutionRepository.java:126)
    org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:145)
    org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:238)
    org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:57)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    com.jeveris.web.core.filter.log.PerformanceLogFilter.doFilter(PerformanceLogFilter.java:55)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    com.axa.ca.caem.credentials.IamAuthenticationFilter.doFilter(IamAuthenticationFilter.java:116)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)

Go to Source
Author: Marco Osorio

How to visualise Inheritance and Polymorphism?

I want to make diagrams that explain how Inheritance and Polymorphism work conceptually.

Assume that we have a Cat class that inherits from the Animal class. The way that I can think of a Cat object is that it is an object that contains a copy of the members of the Cat class and also it have an Animal object inside of it.

Note: technically, I think that all Cat objects share the same copy of the methods of the Cat class, however, it is clearer to conceptually think of every Cat object as if it contains its own copy of the methods of the Cat class.

Now when we do:

Cat cat1 = new Cat();

Then cat1 will point to the Cat object, this is how the diagram would look like:

enter image description here

The operations that are allowed on the cat1 variable are the following:

  • cat1.x (will access the x variable inside the Cat object).

  • cat1.move() (will call the move() method inside the Cat object).

  • cat1.jump() (will call the jump() method inside the Animal object).

And when we do:

Animal animal1 = cat1;

Then animal1 will point to the Animal object that is inside the Cat object, this is how the diagram would look like:

enter image description here

Note: the arrow pointing at the Animal object doesn’t mean that animal1 actually point to a different location in memory than cat1, the truth is that animal1 and cat1 point to the same location in memory, the arrow pointing at the Animal object is just to indicate that animal1 can only access the members inside the Animal object (unless we have an overridden method).

The operations that are allowed on the animal1 variable are the following:

  • animal1.x (will access the x variable inside the Animal object).

  • animal1.move() (now if the move() method is not overridden in the Cat class, then animal1.move() should call the move() method inside the Animal object, however, since the move() method is overridden in the Cat class, then animal1.move() would call the move() method inside the Cat object).

  • animal1.jump() (will call the jump() method inside the Animal object).

Is my understanding correct?

Go to Source
Author: Tom

What’s in THIS environment?

We work on multiple java web projects going on at the same time and those are all being tested on several different QA environments. Id like to show on our support portal what projects are in what environments without having to manually updated it all the time. I was thinking of some what to tag the build so I could just query tomcat or those linux servers themselves and show the results. The tags would be something like “August Release”, “Project 1”, “Project 2”, etc.. Has anyone done something similar? I’m looking for different options.

Go to Source
Author: DaveTX

Using a domain model to persist metrics

I am currently developing a spring boot web application in which no entity is persistent, and hence will not be saved on a database.

Although, I need to be able to query some business metrics from it. Suppose the following scenario:

  1. EntityA belongs to a third party API.
  2. An user on my web app requests to see some details of EntityA.
  3. My app then requests EntityA from the third party API, does some processing (could be combining that data with some other available on the web), and returns the desired info to the requesting user.

I am not required to persist EntityA because it is already being persisted inside the third party API. All the processing done is transient. But, I want to be able to check how many times EntityA was requested by an user on my web application, and what data it contained on each request. This metric is useful for audit purposes, for example, since the third party accepts input and output of data. I want to be able to check who input a certain piece of data, and how many times it was done.

If I were to persist EntityA, I would not need all fields that the domain model contain. Also, I would have to add some metadata fields to it (date of request, requesting user, etc.).

What is the correct approach to it?

  1. Persist the domain model of EntityA in my web app, adding the metadata fields on, for example, a superclass?
  2. Create a new entity that express the desired metric, for example RequestedEntity, and map the desired fields of EntityA to RequestedEntity before persisting?

Go to Source
Author: Gabriel Robaina

Link in Java returns HTTP instead of HTTPS

Many times your application can be running behind a reverse proxy or a load balancer, and often in between the protocol is just plain old HTTP. This is a very common setup and one that has been around for several years.

When this happens, when generating URLs through the Java Link class on Spring boot, you might get the wrong scheme or protocol. What should have been HTTPS becomes HTTP. When you’re building APIs that follows HATEOAS/HAL, this becomes an issue. With just a single letter ‘S’ your URLs become invalid.

First off, this should be already handled properly by the underlying framework but if the proxy in front of your app was misconfigured this leads to the problem happening and it is then difficult, maybe impossible, to tell whether the client connecting to the app used HTTP or HTTPS.

Luckily, you can force it somehow to use the proper protocol. This is a solution nonetheless, which works, but I would say having the reverse proxy or load balancer configured correctly is the proper way to do it.

ANSWER

The band-aid solution is to manipulate your Spring Boot app depending on the environment.

For example, if I’m just developing/using it locally HTTP is fine. With profiles setup as it ought to be – dev, test, prod – you can get the correct environment and have your URL use HTTP or HTTPS depending on it. When you deploy it to your server, you know you want it to be using secure HTTP so now you can override the Link to use the right scheme in this case.

Here is a one way on how to do manipulate the protocol or scheme of a Link.

Oh, and getting the profile can be done in 2 ways that I know of in Spring Boot.

First is injecting it via annotation.

@Value("${spring.profiles.active}")
private String activeProfile;

and/or autowiring Environment

@Autowired
private Environment environment;
 
public void getActiveProfiles() {
   for (String profileName : environment.getActiveProfiles()) {
      System.out.println("Active profile: " + profileName);
   }  
}

How to prevent from DNS spoofing in Java code which obtains a name of localhost

FORTIFY static scan has detected that this piece of our java code is vulnerable to DNS spoofing attack:

public String getLocalhostName(){
    try {
        return Inet4Address.getLocalHost().getHostName();
    } catch (UnknownHostException e) {
        return null;
    }
}

FORTIFY also gives these recommendations:

Recommendations:

You can increase confidence in a domain name lookup if you check to
make sure that the host’s forward and backward DNS entries match.
Attackers will not be able to spoof both the forward and the reverse
DNS entries without controlling the nameservers for the target domain.
This is not a foolproof approach however: attackers may be able to
convince the domain registrar to turn over the domain to a malicious
nameserver. Basing authentication on DNS entries is simply a risky
proposition.

My questions are:

  1. Is getting the local host name really vulnerable to such an attack ? I can’t imagine such a scenario.
  2. How to implement this check in practice (in this code snippet)?

Tkank you.

Go to Source
Author: krokodilko

How to manage user java deployments in a small team, across different java applications (which require different java versions)?

I provide a java application (desktop client) which requires jdk11 (it really does).
We installed that SDK on all users and were happy for a while.

Then, someone shared with us his java application (also a desktop client, but unrelated to mine), which only works with jre8 (he is not willing to recompile to 11 and his status in the company is such that we must conform to him at all costs)…

I’ve instructed the team members to change their JAVA_HOME between an installed jre8 and jdk11, as they need, but this doesn’t seem like more than an annoying manual stop gap.

I am wondering what is a good, modern approach to allow, for example: a system-wide jre8 for the applications I don’t control but also code a little something into my project that can switch to jdk11 for the duration of their use of my application?

Since I am delivering a project with source code (which compiles every time they run, because they sometimes need to modify some of the java code), I am thinking along the lines of including a portable jdk11 and have the project refer to that as the SDK, relatively (so that they don’t have to install anything to get my application going).

I actually tried this a little bit but couldn’t get it done and I am wondering if it’s a good approach that is worth fixing or there is a better idea?

Can you share your experience about this relatively common problem?

Edit: + I am not sure a containerized solution is viable. It sounds like I’ll have to help them set up their system to support that and then wrap my project in a container – which sounds like a can of worms for someone with my skills (middleweight java dev, at best)

Go to Source
Author: DraxDomax