Export SVN Entries to CSV
Today i faced the problem, that we wanted to create a CSV list out of our SVN Repository … That is not so simple as we thought, so here a quick Solution (with hardcoded Path .. change them )
|
1 |
svn info -R --xml svn://yourPathToSvn > d:\output.xml |
this creates a XML File with all subfolders of “yourPathToSvn” Now you can just copy [...]
How to get the current Server path
If you ever needed to create a link inside you managedBean, you might want to know how the server url is.
|
1 2 |
String contextName = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath(); return contextName + "/faces/index.xhtml"; |
How To Add Cookies In JSF Context
If you want to read a Cookie to your JSF Bean, you can simply do it like that:
|
1 2 |
Map<String, Object> cookies = FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap(); Cookie cookie = (Cookie) cookies.get("yourCookieName"); |
To change or add the Cookie, you could try this method
|
1 2 3 4 5 6 7 8 9 |
private void setCookie(String cookieName, String cookieValue) { Map<String, Object> cookieProps = new HashMap<String, Object>(); // properties are not really needed, but quite useful cookieProps.put("maxAge", new Integer(365 * 24 * 60 * 60)); // 1 year as default cookieProps.put("path", FacesContext.getCurrentInstance() .getExternalContext().getRequestServerName()); FacesContext.getCurrentInstance().getExternalContext() .addResponseCookie(cookieName, cookieValue, cookieProps); } |
Have Fun!
How to mock FacesContext with PowerMock and Mockito
I am always facing the problem, to fail testing FacesContext in some classes. If you know how you can do that, it is quite simple. In this case i need to mock away FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); So here is an example.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// important to get this stuff running @RunWith(PowerMockRunner.class) @PrepareForTest(FacesContext.class) public class MyBeanTest { @Before public void setUp() { PowerMockito.mockStatic(FacesContext.class); // simply mock away all stuff you need FacesContext context = mock(FacesContext.class); ExternalContext externalContext = mock(ExternalContext.class); // create a new map with you params Map<String, String> requestParameter = new HashMap<String, String>(); requestParameter.put("YourParameter", "YourValue"); // tell mockito what to do when(FacesContext.getCurrentInstance()).thenReturn(context); when(context.getExternalContext()).thenReturn(externalContext); when(externalContext.getRequestParameterMap()).thenReturn(requestParameter); } |
Thats it! Here my Maven Dependencys
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<powermock-version>1.4.12</powermock-version> <!-- snipp --> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.9.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>${powermock-version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>${powermock-version}</version> <scope>test</scope> </dependency> |
constructor Service in class javax.xml.ws.Service cannot be applied to given types
If you are trying to create a Webservice with Netbeans, you might get an error like constructor Service in class javax.xml.ws.Service cannot be applied to given types There is a bugreport here: http://netbeans.org/bugzilla/show_bug.cgi?id=195792 which means that this is not a bug, yes .. they are right.., but anyway, if you want to make you code [...]
Composite Component in JSF
If you ever wanted to have your own special tag in your JSF Page, you can create a composite component.. Of course, it also helps to avoid written some code twice or even more often. The main problem using “normal” JSF like:
|
1 |
<ui:include src=""/> |
you cannot pass a bean as parameter to a normal JSF page [...]
MultipleBagFetchException
Error: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags A Solution can look like that: Add @IndexColumn(name=”Your Unique ColumnName”) to your @OneToMany relationship Or you change all your @OneToMany(fetch=FetchType.EAGER) to @OneToMany(fetch=FetchType.LAZY), but keep in mind that you cannot access theses collections anymore Or you change all of your LAZY Collections to a java.util.Set, but keep in mind, [...]
Run Glassfish without beeing root on Port 80
Hi, if you try to run Glassfish on Port 80 without beeing root, that will fail. It fails because of security reason. Non-root user cannot access ports under 1024. First and often found way is to change you Iptables, which you can do like that.
|
1 2 3 |
sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8181 sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080 sudo iptables-save |
But that did not really work for me. I [...]