Search in sources :

Example 1 with ProtocolException

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);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) ContextFactoryMapper(com.arjuna.wsc11.ContextFactoryMapper) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) InvalidCreateParametersException(com.arjuna.wsc.InvalidCreateParametersException) SOAPFactory(javax.xml.soap.SOAPFactory) ContextFactory(com.arjuna.wsc11.ContextFactory) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault)

Example 2 with ProtocolException

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);
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFactory(javax.xml.soap.SOAPFactory) RegisterResponseType(org.oasis_open.docs.ws_tx.wscoor._2006._06.RegisterResponseType) Registrar(com.arjuna.wsc11.Registrar) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) SOAPException(javax.xml.soap.SOAPException) RegistrarMapper(com.arjuna.wsc11.RegistrarMapper) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPFault(javax.xml.soap.SOAPFault)

Example 3 with ProtocolException

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;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) ProtocolException(javax.xml.ws.ProtocolException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with ProtocolException

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;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) ArjunaContext(com.arjuna.webservices11.wsarj.ArjunaContext) SOAPMessage(javax.xml.soap.SOAPMessage) ProtocolException(javax.xml.ws.ProtocolException)

Example 5 with ProtocolException

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);
        }
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) SOAPException(javax.xml.soap.SOAPException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) CompletionCoordinatorParticipant(com.arjuna.wst11.CompletionCoordinatorParticipant) SOAPFactory(javax.xml.soap.SOAPFactory)

Aggregations

ProtocolException (javax.xml.ws.ProtocolException)32 Test (org.junit.Test)10 InstanceIdentifier (com.arjuna.webservices11.wsarj.InstanceIdentifier)9 SOAPException (javax.xml.soap.SOAPException)9 SOAPFactory (javax.xml.soap.SOAPFactory)9 SOAPFault (javax.xml.soap.SOAPFault)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 SOAPMessage (javax.xml.soap.SOAPMessage)8 JAXBContext (javax.xml.bind.JAXBContext)7 JAXBException (javax.xml.bind.JAXBException)7 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)6 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)6 CoordinationContextType (org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType)5 LogicalMessage (javax.xml.ws.LogicalMessage)4 SystemException (com.arjuna.wst.SystemException)3 UnknownTransactionException (com.arjuna.wst.UnknownTransactionException)3 BusinessActivityTerminator (com.arjuna.wst11.BusinessActivityTerminator)3 JAXBElement (javax.xml.bind.JAXBElement)3 SOAPHeader (javax.xml.soap.SOAPHeader)3 Source (javax.xml.transform.Source)3