use of javax.xml.ws.ProtocolException in project narayana by jbosstm.
the class ActivationCoordinatorProcessorImpl method createCoordinationContext.
/**
* Create the coordination context.
* @param createCoordinationContext The create coordination context request.
* @param map The addressing context.
*/
public CreateCoordinationContextResponseType createCoordinationContext(final CreateCoordinationContextType createCoordinationContext, final MAP map, final boolean isSecure) {
final ContextFactoryMapper contextFactoryMapper = ContextFactoryMapper.getMapper();
try {
final String coordinationType = createCoordinationContext.getCoordinationType();
final ContextFactory contextFactory = contextFactoryMapper.getContextFactory(coordinationType);
if (contextFactory != null) {
final CoordinationContext coordinationContext;
try {
final Expires expiresElement = createCoordinationContext.getExpires();
final Long expires = (expiresElement == null ? null : new Long(expiresElement.getValue()));
coordinationContext = contextFactory.create(coordinationType, expires, createCoordinationContext.getCurrentContext(), isSecure);
final CreateCoordinationContextResponseType response = new CreateCoordinationContextResponseType();
response.setCoordinationContext(coordinationContext);
return response;
} catch (final InvalidCreateParametersException invalidCreateParametersException) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_ActivationCoordinatorProcessorImpl_1());
throw new SOAPFaultException(soapFault);
} catch (final Throwable th) {
if (WSCLogger.logger.isTraceEnabled()) {
WSCLogger.logger.tracev("Unexpected exception thrown from create:", th);
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_CREATE_CONTEXT_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_CREATE_CONTEXT_QNAME).addTextNode(th.getMessage());
throw new SOAPFaultException(soapFault);
}
} else {
if (WSCLogger.logger.isTraceEnabled()) {
WSCLogger.logger.tracev("CreateCoordinationContext called for unknown coordination type: {0}", new Object[] { coordinationType });
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_ActivationCoordinatorProcessorImpl_1());
throw new SOAPFaultException(soapFault);
}
} catch (SOAPException se) {
se.printStackTrace(System.err);
throw new ProtocolException(se);
}
}
use of javax.xml.ws.ProtocolException in project narayana by jbosstm.
the class RegistrationCoordinatorProcessorImpl method register.
/**
* Register the participant in the protocol.
* @param register The register request.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*/
public RegisterResponseType register(final RegisterType register, final MAP map, final ArjunaContext arjunaContext, final boolean isSecure) {
final com.arjuna.wsc11.RegistrarMapper registrarMapper = RegistrarMapper.getFactory();
try {
final String protocolIdentifier = register.getProtocolIdentifier();
final Registrar registrar = registrarMapper.getRegistrar(protocolIdentifier);
if (registrar != null) {
try {
final W3CEndpointReference participantProtocolService = register.getParticipantProtocolService();
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
final W3CEndpointReference coordinationProtocolService = registrar.register(participantProtocolService, protocolIdentifier, instanceIdentifier, isSecure);
final RegisterResponseType response = new RegisterResponseType();
response.setCoordinatorProtocolService(coordinationProtocolService);
return response;
} catch (final AlreadyRegisteredException alreadyRegisteredException) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_RegistrationCoordinatorProcessorImpl_1());
throw new SOAPFaultException(soapFault);
} catch (final InvalidProtocolException invalidProtocolException) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PROTOCOL_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_RegistrationCoordinatorProcessorImpl_2());
throw new SOAPFaultException(soapFault);
} catch (final InvalidStateException InvalidStateException) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_STATE_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_STATE_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_RegistrationCoordinatorProcessorImpl_3());
throw new SOAPFaultException(soapFault);
} catch (final NoActivityException noActivityException) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_RegistrationCoordinatorProcessorImpl_4());
throw new SOAPFaultException(soapFault);
} catch (final Throwable th) {
if (WSCLogger.logger.isTraceEnabled()) {
WSCLogger.logger.tracev("Unexpected exception thrown from create:", th);
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_CANNOT_REGISTER_QNAME).addTextNode(th.getMessage());
throw new SOAPFaultException(soapFault);
}
} else {
if (WSCLogger.logger.isTraceEnabled()) {
WSCLogger.logger.tracev("Register called for unknown protocol identifier: {0}", new Object[] { protocolIdentifier });
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PROTOCOL_QNAME);
soapFault.addDetail().addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME).addTextNode(WSCLogger.i18NLogger.get_wsc11_messaging_RegistrationCoordinatorProcessorImpl_2());
throw new SOAPFaultException(soapFault);
}
} catch (SOAPException se) {
se.printStackTrace(System.err);
throw new ProtocolException(se);
}
}
use of javax.xml.ws.ProtocolException in project narayana by jbosstm.
the class CoordinationContextHandler method handleMessageOutbound.
/**
* check for an arjuna context attached to the message context and, if found, install its identifier as the value
* of a soap message header element
* @param context
* @return
* @throws ProtocolException
*/
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
try {
CoordinationContextType coordinationContext = CoordinationContextManager.getThreadContext();
if (coordinationContext != null) {
final JAXBContext jaxbCtx = getJaxbContext();
// insert a header into the current message containing the coordination context
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.getHeader();
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}
/*
* this does not work but it is what we want!!
*
* The problem here is that the marshaller creates plain old elements and inserts them top
* down as it goes along. but the soap header add child method checks its argument and
* replaces plain elements with soap header elements before inserting them. it copies the
* inserted element substructure into the rpelacement but since it does not exist at
* copy time the chiuldren get lost
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.marshal(coordinationContext, soapHeader);
*/
/*
* ok, here's the workaround -- marshall the object as a child of a dummy header, detach it and
* then insert it as a header element.
*/
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(getDummyQName());
Marshaller marshaller = jaxbCtx.createMarshaller();
marshaller.marshal(coordinationContext, headerElement);
soapHeader.replaceChild(headerElement.getChildNodes().item(0), headerElement);
// ok, now we need to locate the inserted node and set the mustunderstand attribute
Iterator<SOAPHeaderElement> iterator = soapHeader.examineAllHeaderElements();
while (iterator.hasNext()) {
headerElement = iterator.next();
if (CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT_QNAME.equals(headerElement.getElementQName())) {
headerElement.setMustUnderstand(true);
break;
}
}
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.ws.ProtocolException in project narayana by jbosstm.
the class InstanceIdentifierHandler method handlemessageInbound.
/**
* check for an arjuna instance identifier element embedded in the soap message headesr and, if found, use it to
* label an arjuna context attached to the message context
* @param context
* @return
* @throws ProtocolException
*/
private boolean handlemessageInbound(SOAPMessageContext context) throws ProtocolException {
try {
final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
Iterator<SOAPHeaderElement> iterator = soapEnvelope.getHeader().examineAllHeaderElements();
while (iterator.hasNext()) {
final SOAPHeaderElement headerElement = iterator.next();
if (ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME.equals(headerElement.getElementQName())) {
// found it - clear the must understand flag, retrieve the value and store an arjuna
// context in the message context
headerElement.setMustUnderstand(false);
String identifierString = headerElement.getValue();
if (identifierString != null) {
ArjunaContext arjunaContext = ArjunaContext.getContext(context);
arjunaContext.setInstanceIdentifier(new InstanceIdentifier(identifierString));
break;
}
}
}
} catch (Exception se) {
throw new ProtocolException(se);
}
return true;
}
use of javax.xml.ws.ProtocolException in project narayana by jbosstm.
the class CompletionCoordinatorRPCProcessorImpl method commit.
/**
* Commit.
* @param commit The commit notification.
* @param map The addressing context.
* @param arjunaContext The arjuna context.
*/
public boolean commit(final Notification commit, final MAP map, final ArjunaContext arjunaContext) {
final InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
final CompletionCoordinatorParticipant participant = getParticipant(instanceIdentifier);
{
try {
if (participant != null) {
try {
participant.commit();
} catch (final TransactionRolledBackException trbe) {
return false;
} catch (final UnknownTransactionException ute) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME);
soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_1());
throw new SOAPFaultException(soapFault);
} catch (final SystemException se) {
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME);
soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2());
throw new SOAPFaultException(soapFault);
} catch (final Throwable th) {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("Unexpected exception thrown from commit:", th);
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME);
soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNERROR_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_2());
throw new SOAPFaultException(soapFault);
}
return true;
} else {
if (WSTLogger.logger.isTraceEnabled()) {
WSTLogger.logger.tracev("Commit called on unknown participant: {0}", new Object[] { instanceIdentifier });
}
SOAPFactory factory = SOAPFactory.newInstance();
SOAPFault soapFault = factory.createFault(SoapFaultType.FAULT_SENDER.getValue(), ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME);
soapFault.addDetail().addDetailEntry(ArjunaTXConstants.UNKNOWNTRANSACTION_ERROR_CODE_QNAME).addTextNode(WSTLogger.i18NLogger.get_wst11_messaging_CompletionCoordinatorProcessorImpl_5());
throw new SOAPFaultException(soapFault);
}
} catch (SOAPException se) {
se.printStackTrace(System.err);
throw new ProtocolException(se);
}
}
}
Aggregations