Tuesday, March 10, 2009

JMS, quick example

before you run it, create a Queue ""scavazza_SAFImportedDestinationsscavazza_localSAFQueue_0"
(in my case, it was a SAF destination)

package com.pierre.jms;

import java.util.Date;

import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;


/**
 * Add these jars:
 * javax.jms_1.1.jar
 * wls-api.jar
 * 
 * @author vernetto
 *
 */
public class JMSSender {
public static void main(String[] args) throws NamingException, JMSException {
send();
}

private static void send() throws NamingException, JMSException {
String url = "t3://localhost:7001";
InitialContext ctx = JNDIHelper.getInitialContext(url);

QueueConnectionFactory qConFactory = (QueueConnectionFactory)ctx.lookup("javax/jms/QueueConnectionFactory");
QueueConnection qConnection = qConFactory.createQueueConnection();
QueueSession qSession    = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)ctx.lookup("scavazza_SAFImportedDestinationsscavazza_localSAFQueue_0");
QueueSender qSender  = qSession.createSender(queue);
TextMessage msg = qSession.createTextMessage();
msg.setJMSCorrelationID("iamanidagains");
msg.setIntProperty("sonoscemo", 27);
msg.setJMSPriority(7);
qConnection.start();
msg.setText("Hello this is Pierre " + new Date());
qSender.send(msg);
qSender.setDeliveryMode(DeliveryMode.PERSISTENT);
qSender.close();
qSession.close();
qConnection.close();
System.out.println("done");
}
}



Sunday, March 8, 2009

Weblogic and SOASuite Certification Exams

sample questions:

http://www.scribd.com/doc/12580321/1z0108-Oracle-WebLogic-Server-10g-System-Administration-Certification

the Mock Exams company: http://www.certinside.com/

Certification Guide:

http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=41&p_org_id=1080544〈=US&p_exam_id=1Z0_108

topics of training:

http://www.webagesolutions.com/training/weblogic/wa1409/outline.html


1Z0-599 Oracle WebLogic Server 12c Certified Implementation Specialist

https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=654&get_params=p_id:136

GLP https://competencycenter.oracle.com/opncc/full_glp.cc?group_id=22243

https://www.pass-guaranteed.com/1Z0-599.htm

http://1z0-599-practice-exam-questions.blogspot.it/

http://www.oracle.com/partners/en/knowledge-zone/middleware/wls12cexampage-1595582.html



1Z0-478 Oracle SOA Suite 11g Certified Implementation Specialist

http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-478

http://www.oracle.com/partners/en/knowledge-zone/applications/soasuite11g-1877659.pdf priceless guide to all the topics in the exam, with links to study material

http://certifyguide.com/exam/1z0-478/ good question list with explanations, reasonably priced

http://www.test4actual.com/1z0-478.html same as above, a bit more costly

http://www.aiotestking.com/oracle/category/exam-1z0-478-oracle-soa-suite-11g-certified-implementation-specialist/ same as above, but FREE of charge!

http://www.free-online-exams.com/pages/exams/DumpsQA.aspx?d=1&c=1z0-478&q=1



Friday, March 6, 2009

Accessing resources in a WAR file

you can easily read the content of a directory in Java, even if this directory is in the classpath:

Here is a useful method to load only the resources:

public static List getDirContent(String dir, boolean throwExceptionIfNotFound) throws IOException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
URL configDir = contextClassLoader.getResource(dir);
if (configDir == null && throwExceptionIfNotFound) throw new IllegalArgumentException("Unable to locate directory " + dir);
List result = new ArrayList();
if (configDir != null) {
URLConnection openConnection = configDir.openConnection();
openConnection.connect();
InputStream is = openConnection.getInputStream();
String content = NuonFileUtils.convertStreamToString(is);
String[] resources = content.split("\n");
for (String resource : resources) {
URL resurl = Thread.currentThread().getContextClassLoader().getResource(resource);
result.add(resurl);
}
}
return result;
}


the content of the resource can be read with a URL using its InputStream.
This method doesn't work in a WAR file, since the classloader's resource locator can't introspect the WAR file. The solution is to use the ServletContext and ServletConfig pattern:

in a JSP, you can do:

String path = ""/WEB-INF/config";
java.net.URL url = config.getServletContext().getResource(path);

and it works beautyfully!

The more elegant way is to have a ServletContextListener intercepting your servlet's initialization, and loading the resources:

public void contextInitialized(ServletContextEvent sce) {
String path = "/WEB-INF/classes";
try {
sce.getServletContext().getResource(path);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}