Hi Asankha
Thankx for the Code.It was really helpful.
Hey our requirements have changed a bit now.I am implementing JMS Client
with synapse.So my Synapse.xml now have two proxies calling two web services
and in the fault sequence i want to call JMS Client.So how to do this??
And JMS Client I am creating seperately .The code for that is :
------------------------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.open3.soap;
/**
*
* @author agupta
*/
// import java.util.*;
import java.util.Properties;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import com.sun.jndi.fscontext.RefFSContextFactory;
import java.util.Hashtable;
public class Main implements MessageListener {
//contants for JMS
public final static String CTX_FACTORY =
"com.sun.jndi.fscontext.RefFSContextFactory";
public static final String QCF_NAME =
"javax.jms.QueueConnectionFactory";
public final static String TO_WS_DEST_NAME = "t...@open3soap";
public final static String FROM_WS_DEST_NAME = "fro...@open3soap";
protected String _configFile = "config/config.xml";
protected String _configName = "standard";
protected String _parser = "org.apache.crimson.parser.XMLReaderImpl";
protected boolean _verbose = false;
protected QueueConnectionFactory _qcf = null;
protected QueueConnection connection = null;
protected Queue _queueToWS = null;
protected Queue _queueFromWS = null;
protected QueueSession sessionReceiver = null;
protected QueueSession sessionSender = null;
protected QueueReceiver receiver = null;
protected QueueSender sender = null;
//constants for xml document
public static String XML_ORDER_OPEN_TAG = "<order>";
public static String XML_ORDER_CLOSE_TAG = "</order>";
public static String XML_WEIGHT_OPEN_TAG = "<shippingWeight>";
public static String XML_WEIGHT_CLOSE_TAG = "</shippingWeight>";
public static String XML_DISTANCE_OPEN_TAG = "<destinationDistance>";
public static String XML_DISTANCE_CLOSE_TAG = "</destinationDistance>";
public static String XML_COST_OPEN_TAG = "<shippingCost>";
public static String XML_COST_CLOSE_TAG = "</shippingCost>";
//Constructor
public void Main() {
}
public void init(String receiveFromQueue, String sendToQueue) {
try {
InitialContext initContext = null;
//InitialContext through JNDI
/* Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY);
props.put("org.open3.xstp.server.ConfigFile", _configFile);
props.put("org.open3.jms.ConfigName", _configName);
props.put("org.open3.xstp.server.SAXParser", _parser);*/
Hashtable env = new Hashtable();
// initContext = new InitialContext(props);
env.put(Context.INITIAL_CONTEXT_FACTORY, CTX_FACTORY);
env.put(Context.PROVIDER_URL,
"file:///c:/imq_admin_objects");
Context ctx = new InitialContext(env);
//get the Queue Connection factory
QueueConnectionFactory myQConnFactory = (QueueConnectionFactory)
ctx.lookup(QCF_NAME);
QueueConnection myQConn =
myQConnFactory.createQueueConnection();
// _qcf = (QueueConnectionFactory)
initContext.lookup(QCF_NAME);
//get the queue destinations
_queueToWS = (Queue) initContext.lookup(receiveFromQueue);
_queueFromWS = (Queue) initContext.lookup(sendToQueue);
connection = _qcf.createQueueConnection();
//create a receiver and sender session
sessionReceiver = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
sessionSender = connection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
//create the receiver and sender
receiver = sessionReceiver.createReceiver(_queueToWS);
sender = sessionSender.createSender(_queueFromWS);
//set to process onMessage events
receiver.setMessageListener(this);
//start delivery of incoming messages
connection.start();
} catch (Exception e) {
System.out.println("JMSClientSendReceive.init Error: " +
e.toString());
e.printStackTrace();
}
}
public void cleanUp() {
//free up system resources
try {
sender.close();
sessionReceiver.close();
sessionSender.close();
connection.close();
} catch (Exception e) {
System.out.println("JMSClientSendReceive.cleanUp Error: " +
e.toString());
}
}
public void onMessage(javax.jms.Message msg) {
}
public boolean sendJMSMessage(String msgContent) {
//sends a JMS TextMessage back to the JMS server
boolean sendOK = true;
System.out.println("ShippingClient: sending JMS message: " +
msgContent);
try {
Message msg = sessionSender.createTextMessage(msgContent);
sender.send(msg);
} catch (Exception e) {
System.out.println("ShippingClient.sendJMSMessage Error: " +
e.toString());
e.printStackTrace();
sendOK = false;
}
return sendOK;
}
}
------------------------------------------------------------------------------------------
I am creating two queues as i have two web services at both ends of it.
BUt in this particular line :
QueueConnectionFactory myQConnFactory = (QueueConnectionFactory)
ctx.lookup(QCF_NAME);
It throws an error javax.naming.namenotfoundexception.How to resolve it?
Asankha C. Perera wrote:
>
> Hi Abhishek
>
> Use the below SimplePOJO class, and drop it into the lib directory to
> make it available (either as a .class or JAR)
>
> Use a configuration as below:
>
> <definitions xmlns="http://ws.apache.org/ns/synapse">
> <proxy name="ServiceProxy">
> <target>
> <inSequence>
> <pojoCommand name="SimplePOJO">
> <property name="processString"
> expression="//processstring" action="ReadMessage"/>
> <property name="program" context-name="program-var"
> action="UpdateContext"/>
> </pojoCommand>
>
> <switch source="get-property('program-var')">
> <case regex="Law">
> <log level="custom">
> <property name="Program" value="Law **"/>
> </log>
> </case>
> <default>
> <log level="custom">
> <property name="Program"
> expression="get-property('program-var')"/>
> </log>
> </default>
> </switch>
> <!-- Fill as you want -->
> </inSequence>
> <outSequence>
> <send/>
> </outSequence>
> </target>
> </proxy>
> </definitions>
>
> Note, that when the POJO mediator is used a new instance is created to
> handle each message. You could use a custom mediator or a class mediator
> if you want to get around this
>
> cheers
> asankha
>
>> Hey my input request looks like this:
>>
>> <?xml version='1.0' encoding='utf-8'?><S:Envelope
>> xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:processProspectDetails
>> xmlns:ns2="http://BusinessSchoolService/"><processstring><?xml
>> version="1.0" encoding="UTF-8"?>
>> <prospect>
>> <Name> zxcz</Name>
>> <Age>2q</Age>
>> <Address>sada</Address>
>> <SSN>dasdadA</SSN>
>> <Program>Law</Program>
>> </prospect>
>> </processstring></ns2:processProspectDetails></S:Body></S:Envelope>
>>
>>
>> and if i am doing mc.geypayloadxml() in source element of switch case , i
>> am
>> getting the following error
>> error
>> org.jaxen.UnresolvableException: No Such Function mc.getPayloadXML
>>
>> Can i directly check for law somehow in the input request?
>>
> public class SimplePOJO {
>
> private String processString;
> private String program;
>
> public void setProcessString(String s) {
> this.processString = s;
> }
>
> public String getProcessString() {
> return processString;
> }
>
> public void setProgram(String s) {
> this.program = s;
> }
>
> public String getProgram() {
> return program;
> }
>
> public void execute() {
> int i = processString.indexOf("Program>");
> int j = processString.indexOf("</Program>");
> program = processString.substring(i+8, j);
> System.out.println("Executing :: program ==>" + program + "<==");
> }
>
> }
>
> --
> Asankha C. Perera
> http://adroitlogic.org
>
> http://esbmagic.blogspot.com
>
>
>
--
View this message in context:
http://www.nabble.com/Invoking-Synapse-from-Non-Axis-2-Client-tp21970007p22176286.html
Sent from the Synapse - User mailing list archive at Nabble.com.