Java Code Examples for org.apache.qpid.proton.amqp.Symbol#getSymbol()
The following examples show how to use
org.apache.qpid.proton.amqp.Symbol#getSymbol() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SymbolType.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Symbol decode(DecoderImpl decoder, ReadableBuffer buffer) { Symbol symbol = _symbolCache.get(buffer); if (symbol == null) { byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); String str = new String(bytes, ASCII_CHARSET); symbol = Symbol.getSymbol(str); _symbolCache.put(ReadableBuffer.ByteBufferReader.wrap(bytes), symbol); } return symbol; }
Example 2
Source File: JmsBasedRequestResponseClient.java From hono with Eclipse Public License 2.0 | 5 votes |
/** * Converts an exception to a Hono specific {@code ServiceInvocationException}. * * @param cause The exception to convert. * @return The Hono specific exception. */ public static ServiceInvocationException getServiceInvocationException(final Exception cause) { if (cause instanceof JMSException) { final Matcher matcher = PATTERN_ERROR_CONDITION.matcher(cause.getMessage()); if (matcher.matches()) { final Symbol condition = Symbol.getSymbol(matcher.group(2)); final String description = matcher.group(1); return StatusCodeMapper.from(condition, description); } } return new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, cause); }
Example 3
Source File: AmqpSinkBridgeEndpoint.java From strimzi-kafka-bridge with Apache License 2.0 | 5 votes |
private void commitHandler(AsyncResult<Void> seekResult) { if (seekResult.failed()) { ErrorCondition condition = new ErrorCondition(Symbol.getSymbol(AmqpBridge.AMQP_ERROR_KAFKA_COMMIT), "Error in commit"); sendAmqpError(condition); } }
Example 4
Source File: ConnectionTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
/** * "each peer MUST write a close frame with a code indicating the reason for closing" * Also see 2.8.16 Connection Error */ @Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testCloseConnectionWithErrorCode_causesCloseFrameContainingErrorCodeToBeSent() { bindAndOpenConnections(); /* * TODO javadoc for {@link Connection#getCondition()} states null is returned if there is no condition, * this differs from the implementation of both Proton-c and Proton-j. */ assertNull(_clientConnection.getCondition().getCondition()); assertNull(_serverConnection.getCondition().getCondition()); assertNull(_clientConnection.getRemoteCondition().getCondition()); assertNull(_serverConnection.getRemoteCondition().getCondition()); ErrorCondition clientErrorCondition = new ErrorCondition(Symbol.getSymbol("myerror"), "mydescription"); Map info = new HashMap(); info.put(Symbol.getSymbol("simplevalue"), "value"); info.put(Symbol.getSymbol("list"), Arrays.asList("e1", "e2", "e3")); clientErrorCondition.setInfo(info); _clientConnection.setCondition(clientErrorCondition); _clientConnection.close(); _pumper.pumpAll(); assertEquals(clientErrorCondition, _serverConnection.getRemoteCondition()); assertNull(_serverConnection.getCondition().getCondition()); }
Example 5
Source File: AmqpErrorConditionException.java From strimzi-kafka-bridge with Apache License 2.0 | 4 votes |
/** * Convert this exception into an {@code ErrorCondition}. */ public ErrorCondition toCondition() { return new ErrorCondition(Symbol.getSymbol(this.error), getMessage()); }
Example 6
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Override public long tick(long now) { long deadline = 0; if (_localIdleTimeout > 0) { if (_localIdleDeadline == 0 || _lastBytesInput != _bytesInput) { _localIdleDeadline = computeDeadline(now, _localIdleTimeout); _lastBytesInput = _bytesInput; } else if (_localIdleDeadline - now <= 0) { _localIdleDeadline = computeDeadline(now, _localIdleTimeout); if (_connectionEndpoint != null && _connectionEndpoint.getLocalState() != EndpointState.CLOSED) { ErrorCondition condition = new ErrorCondition(Symbol.getSymbol("amqp:resource-limit-exceeded"), "local-idle-timeout expired"); _connectionEndpoint.setCondition(condition); _connectionEndpoint.setLocalState(EndpointState.CLOSED); if (!_isOpenSent) { if ((_sasl != null) && (!_sasl.isDone())) { _sasl.fail(); } Open open = new Open(); _isOpenSent = true; writeFrame(0, open, null, null); } if (!_isCloseSent) { Close close = new Close(); close.setError(condition); _isCloseSent = true; writeFrame(0, close, null, null); } close_tail(); } } deadline = _localIdleDeadline; } if (_remoteIdleTimeout != 0 && !_isCloseSent) { if (_remoteIdleDeadline == 0 || _lastBytesOutput != _bytesOutput) { _remoteIdleDeadline = computeDeadline(now, _remoteIdleTimeout / 2); _lastBytesOutput = _bytesOutput; } else if (_remoteIdleDeadline - now <= 0) { _remoteIdleDeadline = computeDeadline(now, _remoteIdleTimeout / 2); if (pending() == 0) { writeFrame(0, null, null, null); _lastBytesOutput += pending(); } } if(deadline == 0) { deadline = _remoteIdleDeadline; } else { if(_remoteIdleDeadline - _localIdleDeadline <= 0) { deadline = _remoteIdleDeadline; } else { deadline = _localIdleDeadline; } } } return deadline; }
Example 7
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Test public void testErrorConditionSetGet() { // Try setting with an empty condition object, expect to get a null back per historic behaviour. TransportImpl transport = new TransportImpl(); ErrorCondition emptyErrorCondition = new ErrorCondition(); assertNull("Expected empty Condition given historic behaviour", emptyErrorCondition.getCondition()); transport.setCondition(emptyErrorCondition); assertNull("Expected null ErrorCondition given historic behaviour", transport.getCondition()); // Try setting with a populated condition object. transport = new TransportImpl(); Symbol condition = Symbol.getSymbol("some-error"); String description = "some-error-description"; ErrorCondition populatedErrorCondition = new ErrorCondition(); populatedErrorCondition.setCondition(condition); populatedErrorCondition.setDescription(description); assertNotNull("Expected a Condition", populatedErrorCondition.getCondition()); transport.setCondition(populatedErrorCondition); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected ErrorCondition returned", populatedErrorCondition, transport.getCondition()); // Try setting again with another populated condition object. Symbol otherCondition = Symbol.getSymbol("some-other-error"); String otherDescription = "some-other-error-description"; ErrorCondition otherErrorCondition = new ErrorCondition(); otherErrorCondition.setCondition(otherCondition); otherErrorCondition.setDescription(otherDescription); assertNotNull("Expected a Condition", otherErrorCondition.getCondition()); assertNotEquals(condition, otherCondition); assertNotEquals(populatedErrorCondition.getCondition(), otherErrorCondition.getCondition()); assertNotEquals(description, otherDescription); assertNotEquals(populatedErrorCondition.getDescription(), otherErrorCondition.getDescription()); assertNotEquals(populatedErrorCondition, otherErrorCondition); transport.setCondition(otherErrorCondition); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected ErrorCondition returned", otherErrorCondition, transport.getCondition()); // Try setting again with an empty condition object, expect to get a null back per historic behaviour. transport.setCondition(emptyErrorCondition); assertNull("Expected null ErrorCondition given historic behaviour", transport.getCondition()); }
Example 8
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 4 votes |
@Test public void testErrorConditionAfterTransportClosed() { Symbol condition = Symbol.getSymbol("some-error"); String description = "some-error-description"; ErrorCondition origErrorCondition = new ErrorCondition(); origErrorCondition.setCondition(condition); origErrorCondition.setDescription(description); assertNotNull("Expected a Condition", origErrorCondition.getCondition()); // Set an error condition, then call 'closed' specifying an error. // Expect the original condition which was set to remain. TransportImpl transport = new TransportImpl(); transport.setCondition(origErrorCondition); transport.closed(new TransportException("my-ignored-exception")); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition()); // ---------------------------------------------------------------- // // Set an error condition, then call 'closed' without an error. // Expect the original condition which was set to remain. transport = new TransportImpl(); transport.setCondition(origErrorCondition); transport.closed(null); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition()); // ---------------------------------------------------------------- // // Without having set an error condition, call 'closed' specifying an error. // Expect a condition to be set. transport = new TransportImpl(); transport.closed(new TransportException(description)); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected condition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition()); assertEquals("Unexpected description returned", "org.apache.qpid.proton.engine.TransportException: " + description, transport.getCondition().getDescription()); // ---------------------------------------------------------------- // // Without having set an error condition, call 'closed' without an error. // Expect a condition to be set. transport = new TransportImpl(); transport.closed(null); assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition()); assertEquals("Unexpected ErrorCondition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition()); assertEquals("Unexpected description returned", "connection aborted", transport.getCondition().getDescription()); }
Example 9
Source File: AmqpErrorException.java From hono with Eclipse Public License 2.0 | 2 votes |
/** * Creates a new exception for an error and description. * * @param error The AMQP error to convey in this exception. * @param description A textual description of the context the error occurred in. */ public AmqpErrorException(final String error, final String description) { super(Objects.requireNonNull(description)); this.error = Symbol.getSymbol(Objects.requireNonNull(error)); }
Example 10
Source File: AmqpBridge.java From strimzi-kafka-bridge with Apache License 2.0 | 2 votes |
/** * Create a new AMQP error condition * * @param error AMQP error * @param description description for the AMQP error condition * @return AMQP error condition */ static ErrorCondition newError(String error, String description) { return new ErrorCondition(Symbol.getSymbol(error), description); }