Sunday, February 08, 2015

How to extract audio from youtube and burn it CD format

Step 1) Use torch browser to download youtube. It will extract it to both mp4 (video) and acc (audio) Step 2) Use foobar2000 + Audio CD Writer component of foobar (installed separately) to convert acc to wav. Step 3) Use CdBurnerXP to burn wav into audio cd format.

Wednesday, July 22, 2009

Invoking an external web service using WID from behind the firewall


So, you imported a WSDL (from an external provider) onto your SCA module in WID, you tried invoking it, but you keep getting

javax.xml.ws.WebServiceException: java.net.ConnectException: Connection timed out: no further information
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:180)
...


That's because the machine where the WSDL is being invoked from is behind the firewall.

So, to invoke an external web service from behind a firewall, you need to set your jvm system properties :
1) Open the administrative console. Click Servers ==> Application Servers ==> server ==> Java and Process Management ==> Process Definition ==> Java Virtual Machine ==> Custom Properties

2) Add these into the Generic JVM Arguments


name=http.proxySet value=true
name=http.proxyHost value=proxy.mycompany.com
name=http.proxyPort value=8080
name=http.proxyUser value=your_proxy_username_if_required
name=http.proxyPassword value=your_proxy_password_if_required
name=http.nonProxyHosts value=localhost|*.hosts.to.be.excluded.from.going.thru.proxy



Alternatively, you could add this to the generic JVM arguments of your JVM


-Dhttp.proxySet=true -Dhttp.proxyHost=proxy.mycompany.com -Dhttp.proxyPort=8080 -Dhttp.proxyUser=yourproxyusername -Dhttp.proxyPassword=yourproxypassword -Dhttp.nonProxyHosts=hostNamesOfMachinesToWhichRequestsWillNotBeSentThroughTheProxyServer



See Configuring additional HTTP transport properties using the JVM custom property panel in the administrative console



Don't forget to set your http.nonProxyHosts. If it is not set, all your http connections will go thru the proxy server, which you don't want to do. You only want your external web service requests to go thru the proxy server, but you want your internal web service requests to not go thru the proxy server.


See

http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html

Wednesday, March 19, 2008

java: An algorithm for converting an array to comma delimited/separated string/value (e.g. csv)

StringBuilder sb = new StringBuilder();

Long[] array = {new Long("1"), new Long("2"), new Long("3")};

for (int i = 0; i < array.length(); i++)
{
   if (i > 0) 
   {
       sb.append(", ");
   }

   sb.append(array[i]);
}

System.out.println(sb.toString());

//output: 1, 2, 3

Tuesday, March 18, 2008

java: How to convert String array to Long array

String[] numbersString = {"1", "2", "3"};

List list = new ArrayList();

for (int i = 0; i <>
{
    Long tmp = Long.valueOf(s[i]);
    list.add(tmp); 
}    
//convert Long ArrayList to Long[] array 
Long[] numbersLong = (Long[])list.toArray(new Long[0]);

Saturday, March 15, 2008

java: How to put checkboxes in DisplayTag using Struts multibox


<display:table name="sessionScope.myFormBean.mySearchResultArrayList" id="myRecord">
<display:column title="Select">
<html:multibox property="selectedItems"
value='<%= (String)((com.abc.def.MyClass)myRecord).getAbc().toString() %>' />
</display:column>
</display:table>


Note:

myFormBean is the name of your Form Bean (i.e. MyFormBean.java)

mySearchResultArrayList is a collection getter in your MyFormBeanName.java. It will hold a collection of your MyClass.java

MyClass will represent each row in your DisplayTag (i.e. MyClass.java). Your mySearchResultArrayList will contain many MyClass.java

myRecord represents the reference to the MyClass object.

selectedItems is a String array property in your MyFormBeanName.java with a getter/setter. It will hold the values of the selected checkboxes. It will also be the name of the checkbox group in html.


MyClass.java


public class MyClass
{
private String abc;

public void setAbc(String abc)
{
this.abc = abc;
}

private String getAbc( )
{
return abc;
}
}



MyFormBean.java

public class MyFormBean
{
private String[ ] selectedItems;
private List mySearchResultArrayList;

public void setMySearchResultArrayList(List list)
{
mySearchResultArrayList = list;
String[] selectedItems = (String[]) mySearchResultArrayList.toArray(new String[0]);
}

public List get
MySearchResultArrayList( )
{
return
mySearchResultArrayList;
}

public String[ } getSelectedItems( )
{
return
selectedItems;
}

public void setSelectedItems(String[ ] selectedItems)
{
this.selectedItems = selectedItems;
}
}

javascript: How to select/deselect checkboxes

This function will select/deselect, tick/untick, check/uncheck all checkboxes belonging to a group. It can be used by a button to toggle a checkbox collection (e.g. Struts multibox in DisplayTag).


function toggle (checkboxes, isSelectAll)
{
if (checkboxes != null)
{
for (i = 0; i < checkboxes.length; i++)
{
checkboxes[i].checked = isSelectAll;
}
}
}


Usage: You can call this function on two buttons:
- select button: onclick="CheckboxUtil.toggle(document.formName.checkboxName, true)"
- deselect button: onclick="CheckboxUtil.toggle(document.formName.checkboxName, false)"


where:
- formName = name of the form.
- checkboxName = name of the checkbox group

Make sure all your checkboxes have the same checkboxName.

java: How to get DisplayTag sorting URL to work in Struts Tiles

Simply put requestURI with blank value onto the DisplayTag attribute.


<display:table name="sessionScope.myForm.searchResult"
id="record"
requestURI="">

</display:table>

java: How to convert a String ArrayList into String array

String[] stringArray = (String[]) stringArrayList.toArray(new String[0]);

java: The difference between the HTML comment <!-- --> and the JSP comment <%-- --%>

The HTML comment will show up in browser view source.

The JSP comment <%-- --%> will not show up in browser view source.

Monday, March 10, 2008

java: Why Log4J's Logger should be declared static final

Declaring Logger to be static final is recommended, particularly for long lived objects such as the Struts Action class
http://www.owasp.org/index.php/Poor_Logging_Practice:_Logger_Not_Declared_Static_Final

e.g.
private static final Logger LOGGER = Logger.getLogger(Donkey.class)

The Struts framework creates only one instance of an Action class for all client requests. e.g. FooAction and BarAction will only be created once.
Static means the Logger is not specific to a particular client request, but is shared by all requests.
Final means the Logger will only be instantiated once.

Logger is tread safe because it doesn't hold a state.

Sunday, February 24, 2008

Java: Eclipe's notion of classpath 101

In Eclipse, if you don't specify the build path, your classes by default will be placed in the base classpath of your project module. E.g.
C:\workspaces\myproject\myModuleEJB\classes\xxx

Therefore, your base classpath is C:\workspaces\myproject\myModuleEJB\classes\xxx

Consider two spring config source folders :
C:\workspaces\myproject\myModuleEJB\testsrc\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\configsrc\spring\businessRules.xml

testApplicationContext.xml is referring to businessRules.xml e.g.

testApplicationContext.xml
===================

<bean id="businessRules" init="false" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list><value>spring/businessRules.xml</value></list>
</constructor-arg>
</bean>


both testApplicationContext.xml and businessRules.xml are compiled by Eclipse into
C:\workspaces\myproject\myModuleEJB\classes\spring\testApplicationContext.xml
C:\workspaces\myproject\myModuleEJB\classes\spring\businessRules.xml

therefore, if testApplicationContext.xml wants to refer to businessRules.xml, the testApplicationContext.xml has to refer to the base classpath location of businessRules.xml
ie. /spring/businessRules.xml

java: Spring's Hibernate Template now obsolete as of Hibernate 3.0.1

See
http://blog.springsource.com/main/2007/06/26/so-should-you-still-use-springs-hibernatetemplate-andor-jpatemplate/

Also, see
- Spring in Action (2nd ed) page 193

- Beginning Spring 2 page 70