summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java30
-rw-r--r--java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java13
-rw-r--r--java/common/src/main/java/org/apache/qpidity/ErrorCode.java25
3 files changed, 53 insertions, 15 deletions
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
index 9cbd40f9ea..1e1390941f 100644
--- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
+++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
@@ -25,6 +25,8 @@ import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
@@ -32,6 +34,12 @@ import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession_0_10;
+import org.apache.qpidity.nclient.Client;
+import org.apache.qpidity.transport.Option;
+
/**
* Message producer example, sends message to a queue.
*/
@@ -73,13 +81,22 @@ public class Producer
Context ctx = new InitialContext(properties);
// look up destination
- Destination destination = (Destination)ctx.lookup("directQueue");
+ //Destination destination = (Destination)ctx.lookup("directQueue");
+ Destination destination = new AMQQueue("amq.fancy","myQeueu");
// Lookup the connection factory
ConnectionFactory conFac = (ConnectionFactory)ctx.lookup("qpidConnectionfactory");
// create the connection
Connection connection = conFac.createConnection();
+ connection.setExceptionListener(new ExceptionListener()
+ {
+ public void onException(JMSException e)
+ {
+ e.printStackTrace();
+ }
+ });
+
// Create a session on the connection
// This session is a default choice of non-transacted and uses the auto acknowledge feature of a session.
System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session");
@@ -92,6 +109,17 @@ public class Producer
System.out.println(CLASS + ": Creating a Message Producer");
MessageProducer messageProducer = session.createProducer(destination);
+ try{
+ org.apache.qpidity.nclient.Connection con = Client.createConnection();
+ con.connect("qpid:password=pass;username=name@tcp:localhost:5672");
+ org.apache.qpidity.nclient.Session ses = con.createSession(1000000);
+ ses.exchangeDelete("amq.direct", Option.NO_OPTION);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+
// Create a Message
TextMessage message;
System.out.println(CLASS + ": Creating a TestMessage to send to the destination");
diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
index 78090b45ad..1bf1c5bc7f 100644
--- a/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
+++ b/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java
@@ -11,11 +11,13 @@ import org.apache.qpid.client.failover.FailoverException;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.jms.Session;
import org.apache.qpidity.nclient.Client;
+import org.apache.qpidity.nclient.ClosedListener;
+import org.apache.qpidity.ErrorCode;
import org.apache.qpidity.QpidException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate
+public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, ClosedListener
{
/**
* This class logger.
@@ -138,4 +140,13 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate
}
}
+
+ public void onClosed(ErrorCode errorCode, String reason)
+ {
+ if (_logger.isDebugEnabled())
+ {
+ _logger.debug("Received a connection close from the broker: Error code : " + errorCode.getCode());
+ }
+ _conn._exceptionListener.onException(new JMSException(reason,String.valueOf(errorCode.getCode())));
+ }
}
diff --git a/java/common/src/main/java/org/apache/qpidity/ErrorCode.java b/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
index 75f9f00622..3f6308622a 100644
--- a/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
+++ b/java/common/src/main/java/org/apache/qpidity/ErrorCode.java
@@ -5,10 +5,10 @@ public enum ErrorCode
//Qpid specific - for the time being
UNDEFINED(1,"undefined",true),
MESSAGE_REJECTED(1,"message_rejected",true),
-
+
//This might change in the spec, the error class is not applicable
NO_ERROR(200,"reply-success",true),
-
+
//From the spec
CONTENT_TOO_LARGE(311,"content-too-large",false),
NO_ROUTE(312,"no-route",false),
@@ -16,10 +16,10 @@ public enum ErrorCode
CONNECTION_FORCED(320,"connection-forced",true),
INVALID_PATH(402,"invalid-path",true),
ACCESS_REFUSED(403,"access-refused",false),
- NOT_FOUND(404,"not-found",false),
- RESOURCE_LOCKED(405,"resource-locked",false),
+ NOT_FOUND(404,"not-found",false),
+ RESOURCE_LOCKED(405,"resource-locked",false),
PRE_CONDITION_FAILED(406,"precondition-failed",false),
-
+
FRAME_ERROR(501,"frame_error",true),
SYNTAX_ERROR(502,"syntax_error",true),
COMMAND_INVALID(503,"command_invalid",true),
@@ -28,11 +28,11 @@ public enum ErrorCode
NOT_IMPLEMENTED(540,"not_implemented",true),
INTERNAL_ERROR(541,"internal_error",true),
INVALID_ARGUMENT(542,"invalid_argument",true);
-
+
private int _code;
private String _desc;
private boolean _hardError;
-
+
private ErrorCode(int code,String desc,boolean hardError)
{
_code = code;
@@ -49,12 +49,12 @@ public enum ErrorCode
{
return _desc;
}
-
+
private boolean isHardError()
{
return _hardError;
}
-
+
public static ErrorCode get(int code)
{
switch(code)
@@ -72,17 +72,16 @@ public enum ErrorCode
case 501 : return FRAME_ERROR;
case 502 : return SYNTAX_ERROR;
case 503 : return COMMAND_INVALID;
- case 504 : return SESSION_ERROR;
+ case 504 : return SESSION_ERROR;
case 530 : return NOT_ALLOWED;
case 540 : return NOT_IMPLEMENTED;
case 541 : return INTERNAL_ERROR;
case 542 : return INVALID_ARGUMENT;
-
+
default : return UNDEFINED;
}
}
-
-}
+ }
/*