use of org.jboss.ejb.client.RequestSendFailedException in project jboss-ejb-client by wildfly.
the class EJBClientChannel method processInvocation.
public void processInvocation(final EJBReceiverInvocationContext receiverContext, final ConnectionPeerIdentity peerIdentity) {
MethodInvocation invocation = invocationTracker.addInvocation(id -> new MethodInvocation(id, receiverContext));
final EJBClientInvocationContext invocationContext = receiverContext.getClientInvocationContext();
invocationContext.putAttachment(INV_KEY, invocation);
final EJBLocator<?> locator = invocationContext.getLocator();
final int peerIdentityId;
if (version >= 3) {
peerIdentityId = peerIdentity.getId();
} else {
// unused
peerIdentityId = 0;
}
try (MessageOutputStream underlying = invocationTracker.allocateMessage()) {
MessageOutputStream out = handleCompression(invocationContext, underlying);
try {
out.write(Protocol.INVOCATION_REQUEST);
out.writeShort(invocation.getIndex());
Marshaller marshaller = getMarshaller();
marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out)));
final Method invokedMethod = invocationContext.getInvokedMethod();
final Object[] parameters = invocationContext.getParameters();
if (version < 3) {
// method name as UTF string
out.writeUTF(invokedMethod.getName());
// write the method signature as UTF string
out.writeUTF(invocationContext.getMethodSignatureString());
// protocol 1 & 2 redundant locator objects
marshaller.writeObject(locator.getAppName());
marshaller.writeObject(locator.getModuleName());
marshaller.writeObject(locator.getDistinctName());
marshaller.writeObject(locator.getBeanName());
} else {
// write identifier to allow the peer to find the class loader
marshaller.writeObject(locator.getIdentifier());
// write method locator
marshaller.writeObject(invocationContext.getMethodLocator());
// write sec context
marshaller.writeInt(peerIdentityId);
// write weak affinity
marshaller.writeObject(invocationContext.getWeakAffinity());
// write response compression info
if (invocationContext.isCompressResponse()) {
int compressionLevel = invocationContext.getCompressionLevel() > 0 ? invocationContext.getCompressionLevel() : 9;
marshaller.writeByte(compressionLevel);
} else {
marshaller.writeByte(0);
}
// write txn context
invocation.setOutflowHandle(writeTransaction(invocationContext.getTransaction(), marshaller, invocationContext.getAuthenticationContext()));
}
// write the invocation locator itself
marshaller.writeObject(locator);
// and the parameters
if (parameters != null && parameters.length > 0) {
for (final Object methodParam : parameters) {
marshaller.writeObject(methodParam);
}
}
// now, attachments
// we write out the private (a.k.a JBoss specific) attachments as well as public invocation context data
// (a.k.a user application specific data)
final Map<AttachmentKey<?>, ?> privateAttachments = invocationContext.getAttachments();
final Map<String, Object> contextData = invocationContext.getContextData();
// write the attachment count which is the sum of invocation context data + 1 (since we write
// out the private attachments under a single key with the value being the entire attachment map)
int totalContextData = contextData.size();
if (version >= 3) {
// Just write the attachments.
PackedInteger.writePackedInteger(marshaller, totalContextData);
for (Map.Entry<String, Object> invocationContextData : contextData.entrySet()) {
marshaller.writeObject(invocationContextData.getKey());
marshaller.writeObject(invocationContextData.getValue());
}
} else {
final Transaction transaction = invocationContext.getTransaction();
// We are only marshalling those attachments whose keys are present in the object table
final Map<AttachmentKey<?>, Object> marshalledPrivateAttachments = new HashMap<>();
for (final Map.Entry<AttachmentKey<?>, ?> entry : privateAttachments.entrySet()) {
final AttachmentKey<?> key = entry.getKey();
if (key == AttachmentKeys.TRANSACTION_ID_KEY) {
// skip!
} else if (ProtocolV1ObjectTable.INSTANCE.getObjectWriter(key) != null) {
marshalledPrivateAttachments.put(key, entry.getValue());
}
}
if (transaction != null) {
marshalledPrivateAttachments.put(AttachmentKeys.TRANSACTION_ID_KEY, calculateTransactionId(transaction));
}
final boolean hasPrivateAttachments = !marshalledPrivateAttachments.isEmpty();
if (hasPrivateAttachments) {
totalContextData++;
}
if (transaction != null) {
// we additionally add/duplicate the transaction id under a different attachment key
// to preserve backward compatibility. This is here just for 1.0.x backward compatibility
totalContextData++;
}
// backward compatibility code block for transaction id ends here.
PackedInteger.writePackedInteger(marshaller, totalContextData);
// write out public (application specific) context data
ProtocolObjectResolver.enableNonSerReplacement();
try {
for (Map.Entry<String, Object> invocationContextData : contextData.entrySet()) {
marshaller.writeObject(invocationContextData.getKey());
marshaller.writeObject(invocationContextData.getValue());
}
} finally {
ProtocolObjectResolver.disableNonSerReplacement();
}
if (hasPrivateAttachments) {
// now write out the JBoss specific attachments under a single key and the value will be the
// entire map of JBoss specific attachments
marshaller.writeObject(EJBClientInvocationContext.PRIVATE_ATTACHMENTS_KEY);
marshaller.writeObject(marshalledPrivateAttachments);
}
// against AS7 7.1.x releases. Discussion here https://github.com/wildfly/jboss-ejb-client/pull/11#issuecomment-6573863
if (transaction != null) {
// we additionally add/duplicate the transaction id under a different attachment key
// to preserve backward compatibility. This is here just for 1.0.x backward compatibility
marshaller.writeObject(TransactionID.PRIVATE_DATA_KEY);
// This transaction id attachment duplication *won't* cause increase in EJB protocol message payload
// since we rely on JBoss Marshalling to use back references for the same transaction id object being
// written out
marshaller.writeObject(marshalledPrivateAttachments.get(AttachmentKeys.TRANSACTION_ID_KEY));
}
// backward compatibility code block for transaction id ends here.
}
// finished
marshaller.finish();
} catch (IOException e) {
underlying.cancel();
throw e;
} finally {
out.close();
}
} catch (IOException e) {
receiverContext.requestFailed(new RequestSendFailedException(e.getMessage() + " @ " + peerIdentity.getConnection().getPeerURI(), e, true), getRetryExecutor(receiverContext));
} catch (RollbackException | SystemException | RuntimeException e) {
receiverContext.requestFailed(new EJBException(e.getMessage(), e), getRetryExecutor(receiverContext));
return;
}
}
use of org.jboss.ejb.client.RequestSendFailedException in project jboss-ejb-client by wildfly.
the class EJBServerChannel method writeFailedResponse.
private void writeFailedResponse(final int invId, final Throwable e) {
try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) {
os.writeByte(Protocol.APPLICATION_EXCEPTION);
os.writeShort(invId);
final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os)));
marshaller.writeObject(new RequestSendFailedException(e.getMessage() + "@" + channel.getConnection().getPeerURI(), e));
marshaller.writeByte(0);
marshaller.finish();
} catch (IOException e2) {
// nothing to do at this point; the client doesn't want the response
Logs.REMOTING.trace("EJB response write failed", e2);
}
}
use of org.jboss.ejb.client.RequestSendFailedException in project wildfly by wildfly.
the class ExceptionEjbClientTestCase method testConnectException.
/**
* Test exception contains destination when there is no server running (wrong server)
*/
@Test
public void testConnectException() throws Exception {
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
// Wrong server so an exception will be thrown
props.put(Context.PROVIDER_URL, "remote+http://localhost:1000");
Context ctx = new InitialContext(props);
DestroyMarkerBeanInterface destroyM = (DestroyMarkerBeanInterface) ctx.lookup(String.format("ejb:/%s/%s!%s", ARCHIVE_NAME, DestroyMarkerBean.class.getSimpleName(), DestroyMarkerBeanInterface.class.getName()));
destroyM.is();
Assert.fail("It was expected a RequestSendFailedException being thrown");
} catch (RequestSendFailedException e) {
assertTrue("Destination should be displayed", ExceptionUtils.getFullStackTrace(e).contains("remote+http://localhost:1000"));
}
}
use of org.jboss.ejb.client.RequestSendFailedException in project wildfly by wildfly.
the class AuthenticationWithSourceAddressRoleDecoderMatchTestCase method testAuthenticationIPAddressMatchAndPermissionMapperMismatch.
@Test
public void testAuthenticationIPAddressMatchAndPermissionMapperMismatch() throws Exception {
final Properties ejbClientConfiguration = createEjbClientConfiguration(Utils.getHost(mgmtClient), "user2", "password2");
final SecurityInformation targetBean = lookupEJB(SecuredBean.class, SecurityInformation.class, ejbClientConfiguration);
try {
targetBean.getPrincipalName();
Assert.fail("Expected RequestSendFailedException not thrown");
} catch (RequestSendFailedException expected) {
}
}
use of org.jboss.ejb.client.RequestSendFailedException in project wildfly by wildfly.
the class AuthenticationWithSourceAddressRoleDecoderMismatchTestCase method testAuthenticationInvalidCredentials.
@Test
public void testAuthenticationInvalidCredentials() throws Exception {
Properties ejbClientConfiguration = createEjbClientConfiguration(Utils.getHost(mgmtClient), "user1", "badpassword");
SecurityInformation targetBean = lookupEJB(SecuredBean.class, SecurityInformation.class, ejbClientConfiguration);
try {
targetBean.getPrincipalName();
Assert.fail("Expected RequestSendFailedException not thrown");
} catch (RequestSendFailedException expected) {
}
ejbClientConfiguration = createEjbClientConfiguration(Utils.getHost(mgmtClient), "user2", "badpassword");
targetBean = lookupEJB(SecuredBean.class, SecurityInformation.class, ejbClientConfiguration);
try {
targetBean.getPrincipalName();
Assert.fail("Expected RequestSendFailedException not thrown");
} catch (RequestSendFailedException expected) {
}
}
Aggregations