|
From: Patrick Y. <kc...@ce...> - 2003-06-26 09:39:16
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body>
Michal,<br>
If you want to use onMessage(), return null in getClientUrl() is the
right way. I'm not sure what you mean by returned all messages as
undelivered. I inspected your code, normally you send message using
sendMessage(), and the message will come in from onMessage().<br>
<br>
Regards, -Patrick<br>
<br>
<br>
Michal Sankot wrote:<br>
<blockquote type="cite"
cite="mid001401c339a9$1363a6e0$5dc8c8c8@Michalsankot">
<pre wrap="">Hi Patrick,
I tried to change code so that there is only one program running but it
still didn't help.
HempClient now implements MessageListener and creates request with itself as
a listener. But it still throws RequestException when I try to create that
request.
Problem arises when I change getClientUrl() from returning null to returning
a path to a local folder.
I tried running it with getClientUrl() returning null sending messages to
itself and it returned all messages as undelivered. I'd guess it was caused
by getClientUrl() returning null. Source files of both Client and
MessageListener are attached.
Michal
----- Original Message -----
</pre>
<blockquote type="cite">
<pre wrap="">Hi Michal,
Is you HempClientMessageListener implementing MessageListener interface?
Or it extends from MessageListenerImpl? If possible, please attach the
source code to us so that we can have a better understanding on your
situation. Thanks.
Regards, -Patrick
P.S. I am forwarding this to the mailing list dedicated to Hermes
discussions. You may want to subscribe to it at
<a class="moz-txt-link-freetext" href="http://sourceforge.net/projects/ebxmlms">http://sourceforge.net/projects/ebxmlms</a>.
Michal Sankot wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
I dowloaded Hermes installation from freebXML.org and tried to develop
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->some
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">simple client using ebMS.
I get en error message though when I try to run it. As your email address
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->is
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">the only one I found related to Hermes, I address my enquiry to you.
My program consist of 2 files so far - HempClient and
HempClientMessageListener.
Problem arises when HempClient passes HempClientMessageListener to
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->Request
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">constructor. I get an error message:
</pre>
</blockquote>
<pre wrap="">--------------------------------------------------------------------------
</pre>
<blockquote type="cite">
<pre wrap="">Cannot create request object. RequestException.
hk.hku.cecid.phoenix.message.handler.RequestException:
Failed to send query to MSH.
HTTP response code = 409
HTTP response message = HTTP POST submitted to MessageServiceHandler
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->failed: java.lang.ClassNotFoundException: hemp.HempClient
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">at
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->hk.hku.cecid.phoenix.message.handler.Request.expectMapResponse(Request.java:
1777)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">at
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->hk.hku.cecid.phoenix.message.handler.Request.sendMessageServiceHandlerConfig
(<a class="moz-txt-link-freetext" href="Request.java:1270">Request.java:1270</a>)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">at
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->hk.hku.cecid.phoenix.message.handler.Request.register(<a class="moz-txt-link-freetext" href="Request.java:1179">Request.java:1179</a>)
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">at hk.hku.cecid.phoenix.message.handler.Request.<init>(<a class="moz-txt-link-freetext" href="Request.java:839">Request.java:839</a>)
at hemp.HempClient.initializeClient(<a class="moz-txt-link-freetext" href="HempClient.java:116">HempClient.java:116</a>)
at hemp.HempClient.run(<a class="moz-txt-link-freetext" href="HempClient.java:73">HempClient.java:73</a>)
at hemp.HempClient.main(<a class="moz-txt-link-freetext" href="HempClient.java:63">HempClient.java:63</a>)
Process terminated with exit code 0
</pre>
</blockquote>
<pre wrap="">--------------------------------------------------------------------------
</pre>
<blockquote type="cite">
<pre wrap="">Why is it so ? I thought that I register MessageListener to react on
messages on CLIENT side, not server side, so there shouldn't be any
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->problem
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">with classpath.
Please tell me where the problem is, or forward my enquery to a person
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->who
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">would be able to solve it.
Thank you
Michal Sankot
Ireland
</pre>
<pre wrap="">
<hr width="90%" size="4">
package hemp;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.BufferedInputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.Iterator;
import hk.hku.cecid.phoenix.message.handler.*;
import hk.hku.cecid.phoenix.message.packaging.*;
import javax.xml.soap.SOAPException;
import javax.activation.DataHandler;
/**
* Created by IntelliJ IDEA.
* User: michal
* Date: 19-Jun-2003
* Time: 10:52:31
* To change this template use Options | File Templates.
*/
public class HempClient implements MessageListener{
static String tomcat = "9999"; // Tomcat
static String jboss = "8080"; // JBoss
private static String toMshUrl = <a class="moz-txt-link-rfc2396E" href="http://localhost:">"http://localhost:"</a>+jboss+"/msh/"; // local MSH
// private static String fromPartyId = <a class="moz-txt-link-rfc2396E" href="http://localhost:">"http://localhost:"</a>+tomcat+"/msh/"; // local MSH
// private static String toPartyId = <a class="moz-txt-link-rfc2396E" href="http://localhost:">"http://localhost:"</a>+jboss+"/msh/"; // remote MSH
private static String fromPartyId = <a class="moz-txt-link-rfc2396E" href="http://localhost:">"http://localhost:"</a>+jboss+"/msh/"; // local MSH
private static String toPartyId = <a class="moz-txt-link-rfc2396E" href="http://localhost:">"http://localhost:"</a>+jboss+"/msh/"; // remote MSH
/** MSH stub object */
protected static Request request = null;
//*************************** MSH settings
private static String cpaID = "Some_CPA_ID";
private static String conversationID = "Conversation_"+(new Date().getTime());
private static String service = <a class="moz-txt-link-rfc2396E" href="http://propylon/hemp">"http://propylon/hemp"</a>;
private static String action = "Order";
private static int numRetry = 2;
private static String retryInterval = "30000";
private static String transportType = "http"; // "https", "mail"
private static int syncReply = Request.SYNC_REPLY_MODE_SIGNALS_AND_RESPONSE;// what's the difference ?
private static boolean messageOrder = true;
private static String persistDuration = "-1"; // how long to persist messages. "-1" = persist forever
//****************************************
//************************* Messages settings
private static String timeToLive = null; //"10000";
//*******************************************
public static void main(String[] args){
HempClient hempClient = new HempClient();
hempClient.run(args);
}
private void run(String[] args) {
if (args.length!=1){
System.out.println("Usage: HempClient msg_file\n");
System.out.println("msg_file is sent to hard-coded MSH (Hermes) at 127.0.0.1\n");
}
else {
initializeClient();
try {
File msgFile = new File(args[0]);
sendMessage(msgFile);
System.out.println("Message "+args[0]+" sent.");
} catch (Exception e) {
System.err.println("Exception occued during loading file "+args[0]+". "+e);
//e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
// wait for message to come now.
while(true){
try {
Thread.sleep(1000); //s interval
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
}
}
private void initializeClient() {
//HempClientMessageListener messageListener = new HempClientMessageListener();
// MessageListener messageListener =null;
// try {
// messageListener = new ClientMessageListenerImpl(new File("").toURL());
// } catch (MalformedURLException e) {
// e.printStackTrace(); //To change body of catch statement use Options | File Templates.
// }
ApplicationContext ac = new ApplicationContext(cpaID,
conversationID, service, action);
try {
URL toMshURL = new URL(toMshUrl);
// request = new Request(ac, toMshURL, messageListener, transportType,
// numRetry, retryInterval,syncReply, messageOrder,persistDuration);
request = new Request(ac, toMshURL, this, transportType,
numRetry, retryInterval,syncReply, messageOrder,persistDuration);
request.setSendAcknowledgment(true);
request.setReceiveAcknowledgment(true);
} catch (RequestException e) {
System.out.println("Cannot create request object. RequestException.");
e.printStackTrace();
System.exit(0);
}
catch (MalformedURLException e) {
System.out.println("Cannot create request object. MalformedURLException.");
e.printStackTrace();
System.exit(0);
}
}
/** Sends message to hard-coded msh.
* */
public static void sendMessage(File messageFile) throws SOAPException {
// 2) Construnct ebXML Message
// 2.a) construct Header
// 2.b) construct Attachement
// 2.c) bind Header + Attachement to new ebXMl message
Date currentDate = new Date();
String messageId = "msg_"+currentDate.getTime()+"@"+fromPartyId+"_to_"+toPartyId;
String timestamp = Utility.toUTCString(currentDate);
EbxmlMessage ebxmlMessage = new EbxmlMessage();
MessageHeader msgHeader = ebxmlMessage.addMessageHeader();
msgHeader.addFromPartyId(fromPartyId);
msgHeader.addToPartyId(toPartyId);
msgHeader.setCpaId(cpaID);
msgHeader.setConversationId(conversationID);
msgHeader.setService(service);
msgHeader.setAction(action);
msgHeader.setMessageId(messageId);
msgHeader.setTimestamp(timestamp);
if (timeToLive!=null) msgHeader.setTimeToLive(timeToLive);
msgHeader.setDuplicateElimination();
// todo add attachements
String fileName = messageFile.getAbsolutePath();
String type = "text/xml";
if (!fileName.toUpperCase().endsWith("XML")) {
type = "application/octet";
}
AttachmentDataSource ads = null;
try {
ads = new AttachmentDataSource(messageFile, type);
} catch (IOException e) {
System.err.println("Loading of file "+fileName+" failed.");
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
DataHandler dataHandler = new DataHandler(ads);
ebxmlMessage.addPayloadContainer(dataHandler, "Payload-"+1, "Description of Payload-"+1+".");
int status = MessageOrder.STATUS_CONTINUE; // MessageOrder.STATUS_RESET
int seqNo = -1;
try {
seqNo = request.getSequenceNumber(conversationID, MessageOrder.STATUS_CONTINUE);
} catch (RequestException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
ebxmlMessage.addMessageOrder(status, seqNo);
ebxmlMessage.saveChanges();
//ommit signature
boolean isSigned = false;
// 3) Send it :-) sendReliably();
try {
System.out.println("Sending message "+ebxmlMessage.getMessageId()+" ...");
request.sendReliably(ebxmlMessage, isSigned);
System.out.println("Sent OK.");
} catch (RequestException e) {
System.err.println("Send didn't succed.");
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
/**
* Get the URL used to communicate with the client application when
* message arrives.
*
* @return URL of the client application
*/
public URL getClientUrl() {
URL saveURL = null;
try {
saveURL = new File(<a class="moz-txt-link-rfc2396E" href="e:\\hermes\\hemp_temp">"e:\\hermes\\hemp_temp"</a>).toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
System.out.println("save URL returned: "+saveURL);
return saveURL;
}
/**
* Event handler to be invoked when message arrives.
*
* @param ebxmlMessage An {@link EbxmlMessage} received by the message
* handler.
*/
public void onMessage(EbxmlMessage ebxmlMessage) {
System.out.println("Message CAME : "+ebxmlMessage.getMessageId());
Iterator containerIter = ebxmlMessage.getPayloadContainers();
while(containerIter.hasNext()){
PayloadContainer payload = (PayloadContainer) containerIter.next();
try {
Object content = payload.getDataHandler().getContent();
if (content instanceof InputStream){
InputStream is = (InputStream) content;
BufferedInputStream bs = new BufferedInputStream(is);
int ch = bs.read();
String s = "";
while (ch != -1){
s+=(char)ch;
ch=bs.read();
}
System.out.println("> "+s);
}
else {
System.out.println("> "+content);
}
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
} catch (SOAPException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
}
}
</pre>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>
|