tag:blogger.com,1999:blog-79358384333717957972024-02-18T19:50:06.705-08:00michargmicharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.comBlogger353125tag:blogger.com,1999:blog-7935838433371795797.post-34466665669647302392019-05-11T13:40:00.002-07:002019-05-11T13:40:59.166-07:00Patched Nagios scripts to monitor top 5 processes using CPU / memory<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Overview</h2>
Unfortunately the Nagios scripts (plugins) provided in <a href="https://exchange.nagios.org/directory/Plugins/System-Metrics/CPU-Usage-and-Load/CPU-Stats-2FMemory-Used-Plugin--2D-Top-5-CPU-2FMemory-Consuming-Processes-for-Unix-Servers/details">https://exchange.nagios.org/directory/Plugins/System-Metrics/CPU-Usage-and-Load/CPU-Stats-2FMemory-Used-Plugin--2D-Top-5-CPU-2FMemory-Consuming-Processes-for-Unix-Servers/details</a> are not maintained since 2012 and do not work in Linux (tried with CentOS 7.x). I provide later on this page their patched versions for Linux (tried with CentOS 7.x but it should be OK for any Linux version - please confirm / or not).<br />
<br />
<h2 style="text-align: left;">
Prerequisites</h2>
Install the following:<br />
# yum install bc ksh sysstat<br />
<br />
<br />
<h2 style="text-align: left;">
Patched Nagios scripts</h2>
Patched files working on CentOS 7.x:<br />
<br />
<ul style="text-align: left;">
<li><a href="https://drive.google.com/open?id=1jqlOBOJALGujUWsZ1j_UhbQWY9iXfYm5">check_cpu_stats.sh</a></li>
<li><a href="https://drive.google.com/open?id=1xpfFUcBZw3XG-39XwRTJjJAQhtzQ0W4K">check_mem_hpux_custom</a></li>
</ul>
</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-42267508075184574112015-11-26T01:56:00.003-08:002015-11-26T02:25:12.334-08:00JTable: overriding default behaviours<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
</div>
<h3 style="text-align: left;">
JTable and Tab/Shift-Tab</h3>
<div style="text-align: left;">
By default when the focus in in a JTable then Tab changes focus to the next cell. If the cell is the last one then the 1st cell is focused. Shift-Tab does the opposite.</div>
<h4 style="text-align: left;">
disable Tab/Shift-Tab</h4>
<div style="text-align: left;">
myJTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(<br />
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "none");<br />
myJTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(<br />
KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), "none");<br />
<br />
</div>
<h4 style="text-align: left;">
moving to next component</h4>
<div style="text-align: left;">
Assuming we want to move out of the JTable to the next/prev UI component (instead of the next/prev cell) we can do the following to modify the default behaviour:<br />
<br />
Set<AWTKeyStroke> forward = new HashSet<AWTKeyStroke>(<br />
myJTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));<br />
forward.add(KeyStroke.getKeyStroke("TAB"));<br />
myJTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forward);<br />
Set<AWTKeyStroke> backward = new HashSet<AWTKeyStroke>(<br />
myJTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));<br />
backward.add(KeyStroke.getKeyStroke("shift TAB"));<br />
myJTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backward);<br />
<br />
// create the policy which determines what will be the next/prev UI component on Tab/Shift-Tab <br />
class TabFocusTraversalPolicy extends DefaultFocusTraversalPolicy {<br /><br /> private static final long serialVersionUID = 1L;<br /> <br /> @Override<br /> public Component getComponentAfter(Container container, Component component) {<br /> Component nextComponent = null;<br /> <br /> if(...) {<br /> nextComponent = ...;<br /> } else if(component == ...) {<br /> nextComponent = ...;<br /> } else {<br /> nextComponent = super.getComponentAfter(container, component);<br /> }<br /> <br /> return nextComponent;<br /> }<br /><br /> @Override<br /> public Component getComponentBefore(Container container, Component component) {<br /> Component nextComponent = null;<br /> <br /> if(...) {<br /> nextComponent = ...;<br /> } else if(...) {<br /> nextComponent = ...;<br /> } else {<br /> nextComponent = super.getComponentBefore(container, component);<br /> }<br /> <br /> return nextComponent;<br /> }<br /><br /> @Override<br /> public Component getDefaultComponent(Container container) {<br /> return super.getDefaultComponent(container);<br /> }<br /><br /> @Override<br /> public Component getFirstComponent(Container container) {<br /> return super.getFirstComponent(container);<br /> }<br /><br /> @Override<br /> public Component getLastComponent(Container container) {<br /> return super.getLastComponent(container);<br /> }<br /> <br /> }<br /> <br />
// install the policy to the JTable <br />
myTable.setFocusCycleRoot(true); // if not true then the policy is not triggered<br />
myTable..setFocusTraversalPolicy(newPolicy);<br />
<br />
<br />
references:<br />
<ul style="text-align: left;">
<li><a href="http://stackoverflow.com/questions/12154734/change-focus-to-next-component-in-jtable-using-tab/12157344#12157344">StackOverflow</a></li>
</ul>
<br /></div>
<h3 style="text-align: left;">
JTable and Enter</h3>
<div style="text-align: left;">
</div>
<h4 style="text-align: left;">
Enter: selects next row</h4>
<div style="text-align: left;">
By default when we click Enter in a JTable where a row is selected then the next row gets the focus.<br />
<br />
In order to disable this do the following:<br />
myJTable.getActionMap().put("Enter", new AbstractAction() {<br />
private static final long serialVersionUID = 1L;<br />
<br />
@Override<br />
public void actionPerformed(ActionEvent ae) {<br />
// override default behaviour which selects the next row<br />
}<br />
});<br />
<br />
<br /></div>
</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-23168505472701372892015-09-12T10:48:00.001-07:002015-09-12T10:48:29.438-07:00How to sort an Array of Strings<div dir="ltr" style="text-align: left;" trbidi="on">
This is a silly mistake I did..<br />
<br />
Don't use<br />
<i>Arrays.sort(strs.toArray(new String[0]));</i><br /><br />
<br />
Instead use the following:<br />
<i>Collections.sort(strs);</i><br />
<br />
<br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-14910371024943310422015-09-09T00:20:00.003-07:002015-09-09T05:53:14.196-07:00MongoDB: The ugly things<div dir="ltr" style="text-align: left;" trbidi="on">
Here is a list of all the ugly things that I have found so far regarding MongoDB:<br />
<br />
<br />
<h3 style="text-align: left;">
Writes that return errors to the client due to <i>wtimeout </i>may in fact succeed (<a href="http://docs.mongodb.org/manual/reference/write-concern/#wc-wtimeout">link</a>)</h3>
<div>
Regarding the option <i>wtimeout</i>:</div>
<blockquote class="tr_bq">
This option specifies a time limit, in milliseconds, for the write
concern. <tt class="docutils literal">wtimeout</tt> is only applicable for <tt class="docutils literal">w</tt> values greater than
<tt class="docutils literal">1</tt>.<br />
<b><tt class="docutils literal">wtimeout</tt> causes write operations to return with an error
after the specified limit, even if the required write concern will
eventually succeed. When these write operations return,
<u>MongoDB does not undo successful data modifications</u> performed
before the write concern exceeded the <tt class="docutils literal">wtimeout</tt> time limit.</b><br />
If you do not specify the <tt class="docutils literal"><span class="pre">wtimeout</span></tt> option and the level of write
concern is unachievable, the write operation will block indefinitely.
Specifying a <tt class="docutils literal"><span class="pre">wtimeout</span></tt> value of <tt class="docutils literal"><span class="pre">0</span></tt> is equivalent to a write
concern without the <tt class="docutils literal"><span class="pre">wtimeout</span></tt> option.</blockquote>
<br />
WTF?<br />
<br />
<h3 style="text-align: left;">
Maximum document size is 16MB (<a href="http://docs.mongodb.org/master/reference/limits/">link</a>)</h3>
<div>
<blockquote class="tr_bq">
The maximum BSON document size is 16 megabytes.</blockquote>
<br />
<h3 style="text-align: left;">
A client may think that a write was successful but it wasn't!</h3>
<div style="text-align: left;">
Even with (w=1 or w='majority') and (j=1), it is possible to wind up rolling back a committed write to the primary on failover (link) and the client may think that the write was successful but it wasn't!<br />
<br />
<u>Examples</u><br />
<ul style="text-align: left;">
<li>The
network TCP connection between the application and the server was reset
after the server received a write but before a response could be sent.</li>
<li>The MongoDB server terminates between receiving the write and responding to it.</li>
<li>The network fails between the time of the write and the time the client receives a response to the write. </li>
</ul>
</div>
<br />
w='majority' doesn't resolve the problem because the parameter j doesn't affect the replicas (<a href="http://docs.mongodb.org/manual/reference/write-concern/">link</a>):<br />
<blockquote class="tr_bq">
Requiring journaled write concern in a replica set only requires a journal commit of the write operation to the primary of the set regardless of the level of replica acknowledged write concern.</blockquote>
You can find more information on the <a href="http://docs.mongodb.org/master/core/replica-set-rollbacks/">official MongoDB docs</a> and a relative <a href="http://stackoverflow.com/questions/22410831/can-rollback-still-occur-on-a-mongodb-replica-set-with-j-1-and-w-majority">StackOverflow post</a>.<br />
<br />
<h3 style="text-align: left;">
A client doesn't get a response after a write and thinks that the write didn't happen but happened!</h3>
<div>
Usually the MongoDB client (e.g. Java driver) tackles the following problems transparently to the developer:</div>
<ul style="text-align: left;">
<li><b>insert</b> isn't acknowledged --> re-execute it (provided the _id was set by the client and is the same on both executions)</li>
<li><b>update</b> isn't acknowledged --> treat it as deletion and insertion </li>
<li><b>deletion </b>isn't acknowledged --> idempotent; re-execute it</li>
<li><b>find </b>isn't acknowledged --> idempotent; re-execute it</li>
</ul>
<div>
<br /></div>
<h3 style="text-align: left;">
During failover writes cannot occur (i.e. they fail)</h3>
<div style="text-align: left;">
When the primary node fails, another is elected from its replica set. During the election the client cannot write. This is because in MongoDB only the primary node can accept writes.</div>
<br />
Therefore you may have to guard your code and try to re-execute the failed write.<br />
By the way can the MongoDB driver do anything about it?<br />
<br /></div>
</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-30300046295886509152014-12-20T06:55:00.003-08:002014-12-20T06:55:29.620-08:00How to hibernate Gnome Shell<div dir="ltr" style="text-align: left;" trbidi="on">
Install the relative plugin found on https://extensions.gnome.org/extension/755/hibernate-status-button/</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-69581010359333997962014-11-07T00:18:00.001-08:002014-11-07T00:18:06.367-08:00Oracle Database error: ORA-01109: database not open<div dir="ltr" style="text-align: left;" trbidi="on">
Oracle db installed on VM / my host computer powered off => VM halted<br />When trying to run a SQL script I got "ORA-01109: database not open"<br /><br />More info.. starting SQLPLUS:<br />SQL> shutdown normal;<br />ORA-01109: database not open<br /><br />SQL> startup;<br />ORACLE instance started.<br />Database mounted.<br />ORA-00600: internal error code, arguments: [kcratr_scan_lastbwr], [], [], [],<br />[], [], [], [], [], [], [], []<br /><br /><br />SQL> recover database;<br />Media recovery complete.<br /><br />SQL> shutdown normal;<br />ORA-01109: database not open<br />Database dismounted.<br />ORACLE instance shut down.<br /><br />SQL> startup;<br />Database opened.<br /><br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-54643323308494790042014-11-06T04:44:00.000-08:002014-11-06T04:44:11.578-08:00Virtualbox: How to mount shared folder<div dir="ltr" style="text-align: left;" trbidi="on">
create shared folder on host:<br />Settings / Shared Folders / Adds a new shared folder definition. / <br /> Folder Path: C:/shared<br /> Folder Name: shared<br /> mark: "Auto-mount" and "Make Permanent"<br /><u> </u><br />
<br />
<u>Manually mount shared folder:</u><br />mount shared folder on guest os (linux):<br /><br /># mkir /mnt/shared<br /># usermod -G vboxsf -a oracle<br /># mount.vboxsf shared /mnt/shared<br /><br /><br /><u>Auto-mount shared folder on start-up:</u><br /># mkir /mnt/shared<br />/etc/fstab:<br />shared /mnt/shared vboxsf defaults 0 0</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-54134159974426430452014-11-06T03:38:00.002-08:002014-11-06T03:38:07.801-08:00add user xxx to sudo<div dir="ltr" style="text-align: left;" trbidi="on">
Add user micharg to sudo:<br />$ sudo -i<br /># visudo<br /> micharg ALL=(ALL) ALL</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-72949703423217004742014-11-06T03:36:00.002-08:002014-11-06T03:36:32.636-08:00Virtualbox: copy/paste between host-guest doesn't work (solved)<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="https://forums.virtualbox.org/viewtopic.php?f=6&t=50330">Solution (doesn't work)</a><u>:</u><br /><br />Virtualbox copy/paste between host-guest doesn't work:<br />Settings-->Storage-->SATA Controller and 2. 'Solid-state drive' is checked <br /><br />DIDN'T WORK<br /><br /><br /><u>Solution #2:</u><br /><br />Settings / General / Advanced:<br /> Shared Clipboard: Bidirectional<br /> Drag'n'Drop: Bidirectional</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-1568518484525408592014-11-05T07:07:00.000-08:002014-11-05T07:07:45.080-08:00Java 64bit not supported by LibreOffice nor OpenOffice<div dir="ltr" style="text-align: left;" trbidi="on">
Install Java 32bit<br />
<br />
<br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-65008508939932526142014-10-11T07:28:00.002-07:002014-10-11T07:29:39.305-07:00Spring Data: How to call a stored procedure<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<a href="http://docs.spring.io/spring-data/jpa/docs/1.6.4.RELEASE/reference/html/jpa.repositories.html">Spring data reference</a> supports calling stored procedure (from JPA 2.1) but didn't work for me. Therefore I called the stored procedure with a native query:<br />
<br />
<i>@Repository<br />public interface MyEntityRepository extends PagingAndSortingRepository<MyEntity, Long> {<br /> <br /> @Query(nativeQuery=true, value="{call GetFoo()}")<br /> Object[] callMyStoredProcedure();<br />}</i><br />
<br />
Details:<br />
<br />
1) We are obliged to write the call in an entity repository. Therefore choose an entity in random (e.g. I used MyEntity) and place there your stored procedure call.<br />
<br />
2) The stored procedure with name GetFoo() joins some tables, etc, and returns a row. Its columns are stored in the returned Object[].<br />
<br />
PS: For Spring Data and Stored Procedures check the following sites:<br />
- http://blogs.isostech.com/database/jpa-spring-data-awesomeness/<br />
</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-90289038642374702052014-10-05T23:56:00.000-07:002014-10-06T00:00:24.593-07:00Review of book "Apache Camel Developer's Cookbook"<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
Spoiler: I have been assigned <span style="mso-spacerun: yes;"> </span>to review this "Apache Camel Developer's Cookbook" since I won a free copy in a contest on LinkedIn.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This book should be read by developers already familiar with Camel existence (e.g. read first "Camel in Action" - you will learn how Camel works). It references the most Valuable EIPs with a good discussion and examples (and code maven managed!) about each one. It presents EIPs like Content Based Router, Filter, Wire Tap, Multicast, Content Enricher, Recipient List, Throttler, Load Balancer, Routing Slip, Enricher, Splitter, etc. Its follows the common PACKT's presentation format "Getting ready" / "How to do it..." / "How it works..." / "There's more..." / "See also". It felt like reading Camel's official Documentation but from a user guide's approach and not a detailed reference approach.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
What I liked most was a whole a chapter on testing. Integration with Spring (a common usage scenario) is also presented throughout the book. I really liked "Chapter 8: Transactions and Idempotency" where more advanced issues are presented about transactions on a single-resource and on how to implement distributed transactions without XA (hint: using Idempotent EIP).<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
To sum up:<o:p></o:p></div>
<div class="MsoNormal">
- Don't read it if this is your first contact with Camel.<o:p></o:p></div>
<div class="MsoNormal">
- Read it if you want good examples on how to use Camel's patterns and official documentation is not enough for you. Source code provides hands-on experience on all the EIPs presented on the book.<o:p></o:p></div>
<div class="MsoNormal">
<span style="mso-spacerun: yes;"> </span></div>
<link href="file:///C:%5CUsers%5CArgyriou%5CAppData%5CLocal%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List"></link> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--> </div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-42810450144685240532014-09-23T07:19:00.000-07:002014-09-23T07:28:12.877-07:00SVN: delete all .svn (recursively)<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://stackoverflow.com/questions/4889619/command-to-recursively-remove-all-svn-directories-on-windows">Windows</a>:<br />
FOR /F "tokens=*" %G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%G"<br />
<br />
<a href="https://www.blogger.com/blogger.g?blogID=7935838433371795797#editor/target=post;postID=4281045014468524053">Linux</a>:<br />
find . -type d -name '.svn' -print -exec rm -rf {} \;</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-88921367821835696502014-09-18T05:23:00.000-07:002014-09-18T05:28:12.141-07:00Spring Security + @Async problem: (SecurityContextHolder is empty)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b>Problem: </b>I annotated a method with <i>@Async</i> and <i>@PreAuthorize</i> so that is executed asynchronously and be secured.<br />
But it seems the security context (<i>SecurityContextHolder</i>) is not populated (althouth user has authenticated).<br />
This happens only if the method is annotated with <i>@Async</i>.<br />
<br />
<b>Solution:</b> From <i>SecurityContextHolder </i>we can get e.g. the logged in username (e.g. check <a href="http://www.mkyong.com/spring-security/get-current-logged-in-username-in-spring-security/">this</a>). <i>SecurityContextHolder </i>is saved in <br />
current thread [1]. When we spawn a new thread the current thread's <i><i>SecurityContextHolder </i></i> (which is a<i><i> </i>ThreadLocal</i>s) <br />
is not copied/inherited. <br />
<br />
In order to inherit it do the following:<br />
<br />
<i><bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"></i><br />
<i> <property name="targetClass" value="org.springframework.security.core.context.SecurityContextHolder" /></i><br />
<i> <property name="targetMethod" value="setStrategyName" /></i><br />
<i> <property name="arguments"></i><br />
<i> <list></i><br />
<i> <value><b>MODE_INHERITABLETHREADLOCAL</b></value></i><br />
<i> </list></i><br />
<i> </property></i><br />
<i> </bean></i><br />
<br />
<br />
All possible modes:<br />
<ul>
<li>MODE_THREADLOCAL (default strategy)</li>
<li><a href="http://docs.spring.io/autorepo/docs/spring-security/3.1.7.RELEASE/apidocs/org/springframework/security/core/context/SecurityContextHolder.html#MODE_INHERITABLETHREADLOCAL">MODE_INHERITABLETHREADLOCAL</a>: spawned threads inherit SecurityContext of the parent thread</li>
<li>MODE_THREADLOCAL </li>
<li>SYSTEM_PROPERTY </li>
</ul>
<br />
[1] From the Spring <a href="http://docs.spring.io/spring-security/site/docs/3.0.x/reference/technical-overview.html">Reference</a>: "By default the SecurityContextHolder uses a ThreadLocal to store these details, which means that the security context is always available to methods in the same thread of execution ..."<br />
<br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-87430341020127924782014-09-18T04:58:00.000-07:002014-09-18T05:10:52.361-07:00Apache CXF+Spring: How to add authentication (dynamic credentials: from db, AD, etc)<div dir="ltr" style="text-align: left;" trbidi="on">
<i> </i><b>Server exposing Web Service</b><i><br /></i><br />
<br />
<i>@WebService<br />public interface MyWebService {</i><br />
<i>... </i><br />
<i></i><br />
<i>}</i><br />
<br />
<i>@WebService(endpointInterface = "com.micharg.MyWebService")<br />public class MyWebServiceImpl implements MyWebService {</i><br />
<i>...</i><br />
<i>} </i><br />
<i></i><br />
<i><br /> </i><i>public interface WebServiceAuthenticationService {</i><i><br /> </i><i><br /> </i><i>}</i><i><br /> </i><i></i><i><br /> </i><i><br /> </i><i><br /> </i><i>@Service("webServiceAuthenticationService")</i><i><br /> </i><i>public class WebServiceAuthenticationServiceImpl implements Validator, WebServiceAuthenticationService {</i><i><br /> </i><i><br /> </i><i> @Autowired</i><i><br /> </i><i> private AuthenticationService authenticationService;</i><i><br /> </i><i> </i><i><br /> </i><i> </i><i><br /> </i><i> @Override</i><i><br /> </i><i> public Credential validate(Credential credential, RequestData data) throws WSSecurityException {</i><i><br /> </i><i><br /> </i><i> String candidateUsername = credential.getUsernametoken().getName();</i><i><br /> </i><i> String candidatePassword = credential.getUsernametoken().getPassword();</i><i><br /> </i><i> </i><i><br /> </i><i> boolean isUserAuthenticated = authenticationService.authenticate(candidateUsername, candidatePassword)</i><i>;</i><i><br /> </i><i> </i><i><br /> </i><i> if(!isUserAuthenticated ) {</i><i><br /> </i><i> throw new WSSecurityException("Wrong credentials (" + candidateUsername + ", " + candidatePassword + "); can not execute web service");</i><i><br /> </i><i> }</i><i><br /> </i><i> </i><i><br /> </i><i> return credential;</i><i><br /> </i><i> }</i><i><br /> </i><i><br /> </i><i>}</i><i><br /> </i><i><br /> </i><i><bean id="inbound-security" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"></i><i><br /> </i><i> <constructor-arg></i><i><br /> </i><i> <map></i><i><br /> </i><i> <entry key="action" value="UsernameToken" /></i><i><br /> </i><i> <entry key="passwordType" value="PasswordText" /></i><i><br /> </i><i> </map></i><i><br /> </i><i> </constructor-arg></i><i><br /> </i><i> </bean></i><i><br /> </i><i> <br /> <!-- Add authentication to the web service that listens to endpoint <a class="moz-txt-link-freetext" href="http://mydomain/myendpoint">http://mydomain/myendpoint;</a> --><br /> </i><i><jaxws:endpoint id="myWebService" implementor="#myWebServiceImpl" address="/myendpoint"></i><i><br /> </i><i> </i><i><br /> </i><i> <jaxws:properties></i><i><br /> </i><i> <entry key="ws-security.ut.validator" value-ref="webServiceAuthenticationService" /></i><i><br /> </i><i> </jaxws:properties></i><i><br /> </i><i> </i><i><br /> </i><i> <jaxws:inInterceptors></i><i><br /> </i><i> <ref bean="inbound-security" /></i><i><br /> </i><i> </jaxws:inInterceptors></i><i><br /> </i><i></jaxws:endpoint></i><i></i><br />
<i><br /> </i> <br />
<i><br /> </i> <br />
<b>Client consuming Web Service</b><i></i><br />
<i><br /> </i> <br />
<i><!-- consume web service located on http://foo.com/myendpoint<br /> </i> <br />
<i><jaxws:client id="myWebServicesClient"<br /> serviceClass="com.micharg.MyWebService"<br /> address="http://foo.com/myendpoint"><br /> <br /> <jaxws:outInterceptors><br /> <ref bean="outbound-security" /><br /> </jaxws:outInterceptors><br /> </jaxws:client></i><br />
<i><br /> </i> <br />
<i><br /> </i> <br />
<i><bean class="eu.europa.europarl.apapeople.people.web.ws.WebServicesCallbackHandler" id="webServicesCallbackHandler" /></i><br />
<i><br /> </i> <br />
<i><bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor" id="outbound-security"><br /> <constructor-arg><br /> <map><br /> <entry key="action" value="UsernameToken"/> <br /> <entry key="user" value="dummy password - passwordCallbackClass overrides it"/> <br /> <entry key="passwordType" value="PasswordText"/><br /> <entry key="passwordCallbackRef" value-ref="webServicesCallbackHandler"/> <br /> </map><br /> </constructor-arg><br /> </bean> </i><br />
<br />
<br />
<i></i><br />
<i>public class WebServicesCallbackHandler implements CallbackHandler {<br /><br /> private String username = "...";<br /> private String password = "...";<br /> <br /> @Override<br /> public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {<br /> WSPasswordCallback c = (WSPasswordCallback) callbacks[0];<br /> c.setIdentifier(username);<br /> c.setPassword(password);<br /> }<br /><br />}<br /> <br /> </i> </div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-10631049550145083632014-09-18T04:48:00.000-07:002014-09-18T05:04:50.126-07:00Spring+Apache CXF: How to disable XML payload limits<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Error:</b> "org.apache.cxf.staxutils.DepthExceededStaxException: reach the innerElementCountThreshold:50000"<br />
<b>Solution</b>: Disable XML payload limits<br />
<br />
<i><</i><i>!-- disable XML payload limits</i><i> --></i><i><br /> </i><i> <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"></i><i><br /> </i><i> <property name="targetClass" value="java.lang.System" /></i><i><br /> </i><i> <property name="targetMethod" value="setProperty" /></i><i><br /> </i><i> <property name="arguments"></i><i><br /> </i><i> <list></i><i><br /> </i><i> <value>org.apache.cxf.stax.maxChildElements</value></i><i><br /> </i><i> <value>1000000</value></i><i><br /> </i><i> </list></i><i><br /> </i><i> </property></i><i><br /> </i><i> </bean></i><br />
<br />
PS: org.apache.cxf.interceptor.security.DepthRestrictingStreamInterceptor seem not to work</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com1tag:blogger.com,1999:blog-7935838433371795797.post-23886012674015573302014-09-12T10:00:00.002-07:002014-09-12T10:00:42.073-07:00Maven: How to execute main-class<div dir="ltr" style="text-align: left;" trbidi="on">
mvn compile exec:java -Dexec.mainClass=micharg.Main</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-84745431992608921772014-08-25T02:34:00.000-07:002014-08-25T03:13:31.466-07:00Excel doesn't render correctly UTF-8 characters when it opens CSVs<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b>Scenario #1</b>: I create a CSV in UTF-8 encoding with Java, save the character 'è' <br />
but Excel doesn't render it well.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQDkKmNXB21WAKCJxgkl6ncK3dxruK7F-nheoLFZK2wi9B7Une2EBVFNUmPj-sCMRuPeFWZFRQun-uQFrKTDZk7ui0qs9hcdrnMDAb7z7s1L25Xa3HdI32j_ucqxgQZTBU30V8F8tVu2FU/s1600/csv+open+with+xls+-+problem.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQDkKmNXB21WAKCJxgkl6ncK3dxruK7F-nheoLFZK2wi9B7Une2EBVFNUmPj-sCMRuPeFWZFRQun-uQFrKTDZk7ui0qs9hcdrnMDAb7z7s1L25Xa3HdI32j_ucqxgQZTBU30V8F8tVu2FU/s1600/csv+open+with+xls+-+problem.PNG" height="172" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<b> </b><br />
<b>Scenario #2</b>: I create a CSV in UTF-8 encoding with Notepad, save the character 'è' <br />
and Excel renders it well.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNtcaR40XOYTXPaJpQRdFX5vYtLmSucvPhT43UN7hrSiPMR2je5Q4clcAzaFucjP_C6F6cARvv2IlF3tt40O8HE4aftEknP_g97UWGd2iyR6Os5vfLqd18_KyaGRu_Fhn9w_9_rLThQIec/s1600/notepad+save+-+open+with+excel+-+correct.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNtcaR40XOYTXPaJpQRdFX5vYtLmSucvPhT43UN7hrSiPMR2je5Q4clcAzaFucjP_C6F6cARvv2IlF3tt40O8HE4aftEknP_g97UWGd2iyR6Os5vfLqd18_KyaGRu_Fhn9w_9_rLThQIec/s1600/notepad+save+-+open+with+excel+-+correct.PNG" height="416" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<br />
<u>Explanation (from <a href="http://en.wikipedia.org/wiki/FEFF">Wikipedia</a>)</u><br />
<blockquote>
"BOM use is optional, and, if used, should appear at the start of the text stream. <br />
... the BOM character may also indicate which of the several Unicode representations <br />
the text is encoded in."</blockquote>
<blockquote class="tr_bq">
"In UTF-16, a BOM (<b>U+FEFF</b>) may be placed as the first character of a file ... " (Java is UTF-16) </blockquote>
<blockquote class="tr_bq">
"The UTF-8 representation of the BOM is the byte sequence <b>0xEF,0xBB,0xBF</b>." (Windows is UTF-8)</blockquote>
<blockquote class="tr_bq">
"many pieces of software on Microsoft Windows such as Notepad will not correctly <br />
read UTF-8 text unless it has only ASCII characters or it starts with the BOM, <br />
and will add a BOM to the start when saving text as UTF-8"</blockquote>
<br />
<br />
<u> Therefore: </u><br />
=> Scenario #1: notepad saves a CSV UTF-8 with the BOM U+EFBBBF therefore Excel opens it correctly<br />
=> Scenario #2: but when the CSV UTF-8 is created with Java the Excel doesn't open it correctly <br />
<br />
<u>Demo on how to solve the problem on Scenario #1:</u><br />
Adding the prefix BOM U+EFBBBF on the CSV created programmatically<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHYaal09w0ppYkSpm81ObdG5urHPRGT-blCyZlM-y_BTVF30_dVsBP91xgKO2L7dXDwMffbamqDwF1_FZsQCx1AlHTK8z5iSLUb5A-CY-4RUprGMeLMZV_2r8H-aQw0KXmDoTRTSIjobS1/s1600/hex+editor+-+BOM+EFBBBF.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHYaal09w0ppYkSpm81ObdG5urHPRGT-blCyZlM-y_BTVF30_dVsBP91xgKO2L7dXDwMffbamqDwF1_FZsQCx1AlHTK8z5iSLUb5A-CY-4RUprGMeLMZV_2r8H-aQw0KXmDoTRTSIjobS1/s1600/hex+editor+-+BOM+EFBBBF.PNG" height="364" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
and now opening the CSV with excel and it is correct!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw9HcuVoK4oR2dpU-bi_ZRgBbfw3w4StpfFGuu2es8KXkSkWAxrw9VPitF_OI4zWuLT4V0qAnbY7ZUs9ppeBmcPbWIvSRlQ3uFtGhV_v0-GJYSc0pW9MW4sPZ1u-zrOMHOd1rFosRAf7CI/s1600/csv+open+with+xls+-+correct.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw9HcuVoK4oR2dpU-bi_ZRgBbfw3w4StpfFGuu2es8KXkSkWAxrw9VPitF_OI4zWuLT4V0qAnbY7ZUs9ppeBmcPbWIvSRlQ3uFtGhV_v0-GJYSc0pW9MW4sPZ1u-zrOMHOd1rFosRAf7CI/s1600/csv+open+with+xls+-+correct.PNG" height="190" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<u>Code solution for scenario #1 (creating CSV programmatically)</u>: add to generated CSV the <br />
BOM suffix U+EFBBBF (for UTF-8 Operating Systems like Windows)<br />
<br />
<u>How to do it in Java</u><br />
Java is UTF-16; therefore you have to write the UTF-16 BOM <b>U+FEFF</b><i>:</i><br />
<br />
<i>// BOM prefix U+FEFF for exported CSVs so that if the csv is openned with<br />// excel in UTF-8 OS (e.g. Windows) encoding is ok (e.g. char è)<br />char CSV_BOM = '\uFEFF';</i><br />
<i>writer.write(CSV_BOM); // writer is e.g. a BufferedWriter</i><br />
<br />
<br />
Note: if you open the exported file with a hex editor like I did on the last image you will see the BOM <b>U+EFBBBF</b>.<br />
<br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-54581568786205874402014-08-01T02:32:00.003-07:002014-08-01T02:32:59.712-07:00Android: How to fake GPS<div dir="ltr" style="text-align: left;" trbidi="on">
<b>How to fake GPS on Android; e.g. when you use the emulator</b><br />
<br />
<br />
String mockLocationProvider = LocationManager.GPS_PROVIDER;<br />
Location mockLocation = new Location(mocLocationProvider);<br />
mockLocation.setLatitude(1d);<br />
mockLocation.setLongitude(1d);<br />
<br />
<br /></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-85769276823595819212014-07-30T13:32:00.002-07:002014-07-31T02:34:54.528-07:00MySQL: How to insert blob in table<div dir="ltr" style="text-align: left;" trbidi="on">
In order to insert a blob (image, txt, etc) in table FOO in MySQL you should execute the LOAD_FILE [1] statement:<br />
<br />
<span style="color: red;"><i>mysql> insert into FOO(data) values(LOAD_FILE('/path/to/file.txt'));</i></span><br />
<br />
But in my case NULLs were inserted in column data. <br />
<br />
<br />
<b>Troubleshooting </b>[2]:<br />
<i>mysql> select load_file('/path/to/file.txt'); -- returns NULL</i><br />
<br />
Solution: file.txt should be owned by mysql user/group (although its permissions are -rw-rw-r--; i.e. granted read access to others)<br />
<br />
<span style="color: red;"><i>$ sudo chown mysql:mysql </i><i>/path/to/file.txt</i></span><br />
<br />
<br />
<br />
<b>References</b><i> </i><br />
<br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_load-file">[1] From the manual</a>:<br />
<br />
LOAD_FILE(file_name)<br />
<br />
Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.<br />
<br />
If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns NULL.<br />
<br />
As of MySQL 5.0.19, the character_set_filesystem system variable controls interpretation of file names that are given as literal strings.<br />
<br />
[2] Thanks <a href="http://stackoverflow.com/questions/8229951/load-file-doesnt-work">StackOverflow</a><br />
</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-16054330854198895032014-07-29T13:34:00.000-07:002014-07-29T13:34:12.952-07:00MySQL error: Cannot delete or update a parent row: a foreign key constraint fails"<div dir="ltr" style="text-align: left;" trbidi="on">
When trying to delete table foo(<i>DROP TABLE <b>foo1</b>;</i>) I got the following error:<br /><br />Cannot delete or update a parent row: a foreign key constraint fails<br />
<br />
<br />As root execute the following to see what in what state is the db:<br />
<br /><i>SHOW ENGINE INNODB STATUS;</i><br />------------------------<br />LATEST FOREIGN KEY ERROR<br />------------------------<br />140729 23:16:08 Cannot drop table `mydb`.`<b>foo1</b>`<br />because it is referenced by `mydb`.`<b>foo2</b>`<br />
<br />
<br />
This tells us that table foo2 has fk to foo1. So remove the fk in foo2 (set it to null) or drop foo2 (this was the case for me since foo2 was empty -- db was in an inconsistent state).</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-2654420143733289862014-07-29T12:50:00.001-07:002014-07-29T12:50:52.227-07:00Squirrel: doesn't support DELIMITER<div dir="ltr" style="text-align: left;" trbidi="on">
Note to myself: don't use DELIMITER in Squirrel; just remove it</div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-84044088507319103902014-07-29T11:42:00.005-07:002014-07-29T11:42:52.886-07:00Install jar with maven in local repository<div dir="ltr" style="text-align: left;" trbidi="on">
$ ls<br />
foo.jar <br />
$ mvn install:install-file -Dfile=foo.jar -DgroupId=foo-group -DartifactId=foo-artifact -Dversion=1 -Dpackaging=jar <br />
<br />
pom.xml:<br />
<dependency><br /> <groupId>foo-group</groupId><br /> <artifactId>foo-artifact</artifactId><br /> <version>1</version><br />
</dependency></div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-66469717980206503642014-07-29T01:26:00.001-07:002014-07-29T01:40:53.466-07:00Aspose.Words problem with fonts (encoding)<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Summary</b> <br />
When using Aspose.Words in order to produce a pdf I had problem with some characters not renderer properly (e.g. <b>ȗ</b>) -- see the attached image where the created PDF does not render properly the character <b>ȗ </b>and it<b> </b>has embedded the Gentium fonts. The problem was that fonts were missing from my Operating System and the default fronts that Aspose.Words uses in this case don't support all the characters.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMq3bwvKOaXZJZNIv2-lU1IkGtFjqNJXcW3Cs5tAgOE1Wxl3Av_PAFyHpLEW7B3mQ7-SHkp2G3pYpcWwKHXJeeq01l1a07t4C_IfBjHMcWgdafhQrpLAx5Wzq-U4aU7u2IPSCl2sU4KzT/s1600/pdf_fonts.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMq3bwvKOaXZJZNIv2-lU1IkGtFjqNJXcW3Cs5tAgOE1Wxl3Av_PAFyHpLEW7B3mQ7-SHkp2G3pYpcWwKHXJeeq01l1a07t4C_IfBjHMcWgdafhQrpLAx5Wzq-U4aU7u2IPSCl2sU4KzT/s1600/pdf_fonts.png" height="175" width="320" /></a></div>
<br />
<br />
<b>More Info</b><br />
Aspose.Words when creates PDF uses <a href="http://www.aspose.com/docs/display/wordsnet/How+Aspose.Words+Uses+True+Type+Fonts">True Type fonts</a>. If it doesn't find True Type fonts it uses <a href="http://www.aspose.com/docs/display/wordsnet/How+to++Specify+True+Type+Fonts+Location">Gentium font</a>; actually it embeds the fonts in the PDF (see the attached image). Gentium font <a href="http://www.google.com/fonts/specimen/Gentium+Basic">doesn't support ȗ</a>.<br />
<br />
Therefore make sure that you have intalled on your Operating system True Type fonts. The algorithm that Aspose looks for fonts is the following (from <a href="http://www.aspose.com/docs/display/wordsnet/How+Aspose.Words+Uses+True+Type+Fonts">here</a>):<br />
<ol>
<li><i>Aspose.Words tries to find a font on the file system with an exact font name match.</i></li>
<li><i>Next, Aspose.Words tries to find the required font among the fonts
embedded in the original document. Some document formats such as DOCX
can contain embedded fonts</i></li>
<li><i>If Aspose.Words cannot find a font with the exact name match, it will attempt to to use the default font specified under <a href="http://www.aspose.com/docs/display/wordsnet/DefaultFontName+Property" title="DefaultFontName Property">FontSettings.DefaultFontName</a>. If the user has not chosen their own default font then "Times New Roman" is the selected default font that is used. See the <a href="http://www.aspose.com/docs/display/wordsnet/How+to+Specify+the+Default+Font+to+use+when+Rendering" title="How to Specify the Default Font to use when Rendering">How to Set the Default Font used when Rendering</a> topic for further information on setting default font.</i></li>
<li><i>If Aspose.Words is unable to locate the font defined under <a href="http://www.aspose.com/docs/display/wordsnet/DefaultFontName+Property" title="DefaultFontName Property">FontSettings.DefaultFontName</a>, it attempts to select the most suitable font from all of the available fonts.</i></li>
<li><i>Finally, if Aspose.Words cannot find any fonts on the file system,
it renders the document using the free Gentium font that is embedded
into the Aspose.Words assembly.</i></li>
</ol>
<br />
<br />
Programmatically setting the fonts path has worked for me:<br />
<br />
<span style="font-size: x-small;"><br />import com.aspose.words.FolderFontSource; </span><br />
<br />
<span style="font-size: x-small;">final String pathToFonts = "PATH TO TRUE TYPE FONTS";</span> <br />
<br />
<span style="font-size: x-small;">FolderFontSource folderFontSource = new FolderFontSource(pathToFonts, true);<br />fontSources.add(folderFontSource);<br />FontSourceBase[] f</span><span style="font-size: x-small;"><span style="font-size: x-small;">ontSourceBase </span>= (FontSourceBase[])fontSources.toArray(new FontSourceBase[fontSources.size()]);<br />FontSettings.setFontsSources(</span><span style="font-size: x-small;"><span style="font-size: x-small;">f</span><span style="font-size: x-small;"><span style="font-size: x-small;">ontSourceBase</span></span>);</span><br />
<br />
<br />
<div style="text-align: left;">
<b><span style="font-size: small;">Default font locations for various Operating Systems</span></b></div>
<br />
<span style="font-size: x-small;"><span style="font-size: small;"><u>Unix (Linux, Solaris)</u></span></span><br />
<span style="font-size: small;">/usr/share/fonts</span><br />
<span style="font-size: small;">/usr/local/share/fonts</span><br />
<span style="font-size: small;">/usr/X11R6/lib/X11/fonts </span><br />
<br />
<u>Windows</u><br />
Start | Run --> Fonts </div>
micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0tag:blogger.com,1999:blog-7935838433371795797.post-35530041092463401532014-07-10T07:45:00.000-07:002014-07-10T07:47:46.993-07:00Java: How to remove accents<u>How to remove accents</u><u> in strings</u> [1]<br> <br> attempt 1 (remove accents) -- with problems:<br> Normalizer.normalize(str, Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "")<br> ç gives c<br> ' gives '<br> ê gives e<br> Ö gives O<br> ü gives u.<br> <b> ´ gives ´</b><br> <b>but Ø gives Ø</b><b> <br> <br> </b>Accents are removed! But letters (non-ascii) are not removed. <br> <b><br> </b>attempt 2 (Remove non-ascii chars) -- successfully!<br> Normalizer.normalize(str, Form.NFD).replaceAll("[^\\p{ASCII}]", "")<br> ç gives c<br> ' gives '<br> ê gives e<br> Ö gives O<br> ü gives u.<br> <b> ´ gives nothing</b><br> <b>Ø gives nothing</b><b><br> <br> </b>[1] This may be useful e.g. if you want to give filenames in non-unicode filesystem.<b><br> </b> micharghttp://www.blogger.com/profile/12733531629600432067noreply@blogger.com0