Search in sources :

Example 16 with WebServiceException

use of javax.xml.ws.WebServiceException in project teiid by teiid.

the class WSWSDLProcedureExecution method execute.

public void execute() throws TranslatorException {
    List<Argument> arguments = this.procedure.getArguments();
    XMLType docObject = (XMLType) arguments.get(0).getArgumentValue().getValue();
    StAXSource source = null;
    try {
        source = convertToSource(docObject);
        Dispatch<StAXSource> dispatch = conn.createDispatch(StAXSource.class, executionFactory.getDefaultServiceMode());
        String operation = this.procedure.getProcedureName();
        if (this.procedure.getMetadataObject() != null && this.procedure.getMetadataObject().getNameInSource() != null) {
            operation = this.procedure.getMetadataObject().getNameInSource();
        }
        QName opQName = new QName(conn.getServiceQName().getNamespaceURI(), operation);
        dispatch.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);
        if (source == null) {
            // JBoss Native DispatchImpl throws exception when the source is null
            // $NON-NLS-1$
            source = new StAXSource(XMLType.getXmlInputFactory().createXMLEventReader(new StringReader("<none/>")));
        }
        this.returnValue = dispatch.invoke(source);
    } catch (SQLException e) {
        throw new TranslatorException(e);
    } catch (WebServiceException e) {
        throw new TranslatorException(e);
    } catch (XMLStreamException e) {
        throw new TranslatorException(e);
    } catch (IOException e) {
        throw new TranslatorException(e);
    } finally {
        Util.closeSource(source);
    }
}
Also used : Argument(org.teiid.language.Argument) WebServiceException(javax.xml.ws.WebServiceException) SQLException(java.sql.SQLException) QName(javax.xml.namespace.QName) StAXSource(javax.xml.transform.stax.StAXSource) IOException(java.io.IOException) XMLType(org.teiid.core.types.XMLType) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) TranslatorException(org.teiid.translator.TranslatorException)

Example 17 with WebServiceException

use of javax.xml.ws.WebServiceException in project teiid by teiid.

the class WSConnectionImpl method createDispatch.

public <T> Dispatch<T> createDispatch(String binding, String endpoint, Class<T> type, Mode mode) {
    ArgCheck.isNotNull(binding);
    if (endpoint != null) {
        try {
            new URL(endpoint);
        // valid url, just use the endpoint
        } catch (MalformedURLException e) {
            // otherwise it should be a relative value
            // but we should still preserve the base path and query string
            String defaultEndpoint = this.mcf.getEndPoint();
            String defaultQueryString = null;
            String defaultFragment = null;
            if (defaultEndpoint == null) {
                // $NON-NLS-1$
                throw new WebServiceException(WSManagedConnectionFactory.UTIL.getString("null_default_endpoint"));
            }
            // $NON-NLS-1$
            String[] parts = defaultEndpoint.split("\\?", 2);
            defaultEndpoint = parts[0];
            if (parts.length > 1) {
                defaultQueryString = parts[1];
                // $NON-NLS-1$
                parts = defaultQueryString.split("#");
                defaultQueryString = parts[0];
                if (parts.length > 1) {
                    defaultFragment = parts[1];
                }
            }
            if (endpoint.startsWith("?") || endpoint.startsWith("/") || defaultEndpoint.endsWith("/")) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                endpoint = defaultEndpoint + endpoint;
            } else {
                // $NON-NLS-1$
                endpoint = defaultEndpoint + "/" + endpoint;
            }
            if ((defaultQueryString != null) && (defaultQueryString.trim().length() > 0)) {
                endpoint = WSConnection.Util.appendQueryString(endpoint, defaultQueryString);
            }
            if ((defaultFragment != null) && (endpoint.indexOf('#') < 0)) {
                endpoint = endpoint + '#' + defaultFragment;
            }
        }
    } else {
        endpoint = this.mcf.getEndPoint();
        if (endpoint == null) {
            // $NON-NLS-1$
            throw new WebServiceException(WSManagedConnectionFactory.UTIL.getString("null_endpoint"));
        }
    }
    Dispatch<T> dispatch = null;
    if (HTTPBinding.HTTP_BINDING.equals(binding) && (type == DataSource.class)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        BusFactory.setThreadDefaultBus(this.mcf.getBus());
        try {
            dispatch = (Dispatch<T>) new HttpDispatch(endpoint, this.mcf.getConfigFile(), this.mcf.getConfigName());
        } finally {
            BusFactory.setThreadDefaultBus(bus);
        }
    } else {
        // TODO: cache service/port/dispatch instances?
        Bus bus = BusFactory.getThreadDefaultBus();
        BusFactory.setThreadDefaultBus(this.mcf.getBus());
        Service svc;
        try {
            svc = Service.create(this.mcf.getServiceQName());
        } finally {
            BusFactory.setThreadDefaultBus(bus);
        }
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_WS, MessageLevel.DETAIL)) {
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_WS, "Creating a dispatch with endpoint", endpoint);
        }
        svc.addPort(this.mcf.getPortQName(), binding, endpoint);
        dispatch = svc.createDispatch(this.mcf.getPortQName(), type, mode);
        configureWSSecurity(dispatch);
    }
    setDispatchProperties(dispatch, binding);
    return dispatch;
}
Also used : Bus(org.apache.cxf.Bus) MalformedURLException(java.net.MalformedURLException) WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) URL(java.net.URL)

Example 18 with WebServiceException

use of javax.xml.ws.WebServiceException in project OpenOLAT by OpenOLAT.

the class ViteroManager method removeFromRoom.

public ViteroStatus removeFromRoom(ViteroBooking booking, int userId) throws VmsNotAvailableException {
    try {
        Groupiduserid groupuserId = new Groupiduserid();
        groupuserId.setGroupid(booking.getGroupId());
        groupuserId.setUserid(userId);
        getGroupWebService().removeUserFromGroup(groupuserId);
        return new ViteroStatus();
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case userDoesntExist:
                log.error("The user doesn ́t exist!", f);
                break;
            case groupDoesntExist:
                log.error("The group doesn ́t exist", f);
                break;
            case invalidAttribut:
                log.error("An id <= 0", f);
                break;
            default:
                logAxisError("Cannot remove an user from a group", f);
        }
        return new ViteroStatus(code);
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot remove an user from a group", e);
        return new ViteroStatus(ErrorCode.unkown);
    }
}
Also used : Groupiduserid(de.vitero.schema.group.Groupiduserid) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) ConnectException(java.net.ConnectException)

Example 19 with WebServiceException

use of javax.xml.ws.WebServiceException in project OpenOLAT by OpenOLAT.

the class ViteroManager method createBooking.

public ViteroStatus createBooking(BusinessGroup group, OLATResourceable ores, String subIdentifier, ViteroBooking vBooking) throws VmsNotAvailableException {
    Bookingtype booking = getVmsBookingById(vBooking.getBookingId());
    if (booking != null) {
        log.info("Booking already exists: " + vBooking.getBookingId());
        return new ViteroStatus();
    }
    try {
        // a group per meeting
        String groupName = vBooking.getGroupName();
        int groupId = createGroup(groupName);
        if (groupId < 0) {
            return new ViteroStatus(ErrorCode.unkown);
        }
        vBooking.setGroupId(groupId);
        // create the meeting with the new group
        Booking bookingWs = getBookingWebService();
        CreateBookingRequest createRequest = new CreateBookingRequest();
        Newbookingtype newBooking = new Newbookingtype();
        // mandatory
        newBooking.setStart(format(vBooking.getStart()));
        newBooking.setEnd(format(vBooking.getEnd()));
        newBooking.setStartbuffer(vBooking.getStartBuffer());
        newBooking.setEndbuffer(vBooking.getEndBuffer());
        newBooking.setGroupid(groupId);
        newBooking.setRoomsize(vBooking.getRoomSize());
        newBooking.setTimezone(viteroModule.getTimeZoneId());
        if (StringHelper.containsNonWhitespace(vBooking.getEventName())) {
            newBooking.setEventname(vBooking.getEventName());
        }
        createRequest.setBooking(newBooking);
        CreateBookingResponse response = bookingWs.createBooking(createRequest);
        Boolean bookingCollision = response.isBookingcollision();
        Boolean moduleCollision = response.isModulecollision();
        int bookingId = response.getBookingid();
        if (bookingCollision != null && bookingCollision.booleanValue()) {
            return new ViteroStatus(ErrorCode.bookingCollision);
        } else if (moduleCollision != null && moduleCollision.booleanValue()) {
            return new ViteroStatus(ErrorCode.moduleCollision);
        }
        vBooking.setBookingId(bookingId);
        getOrCreateProperty(group, ores, subIdentifier, vBooking);
        return new ViteroStatus();
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case invalidTimezone:
                log.error("Invalid time zone!", f);
                break;
            case bookingCollision:
                log.error("Booking collision!", f);
                break;
            case moduleCollision:
                log.error("Invalid module selection!", f);
                break;
            case bookingInPast:
                log.error("Booking in the past!", f);
                break;
            case licenseExpired:
                log.error("License/customer expired!", f);
                break;
            default:
                logAxisError("Cannot create a booking.", f);
        }
        return new ViteroStatus(code);
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot create a booking.", e);
        return new ViteroStatus(ErrorCode.remoteException);
    }
}
Also used : CreateBookingRequest(de.vitero.schema.booking.CreateBookingRequest) CreateBookingResponse(de.vitero.schema.booking.CreateBookingResponse) WebServiceException(javax.xml.ws.WebServiceException) Booking(de.vitero.schema.booking.Booking) ViteroBooking(org.olat.modules.vitero.model.ViteroBooking) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Bookingtype(de.vitero.schema.booking.Bookingtype) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroStatus(org.olat.modules.vitero.model.ViteroStatus) Newbookingtype(de.vitero.schema.booking.Newbookingtype) ConnectException(java.net.ConnectException)

Example 20 with WebServiceException

use of javax.xml.ws.WebServiceException in project OpenOLAT by OpenOLAT.

the class ViteroManager method getVmsUsersByGroup.

protected List<Usertype> getVmsUsersByGroup(int groupId) throws VmsNotAvailableException {
    try {
        GetUserListByGroupRequest listRequest = new GetUserListByGroupRequest();
        listRequest.setGroupid(groupId);
        Userlist userList = getUserWebService().getUserListByGroup(listRequest);
        List<Usertype> userTypes = userList.getUser();
        return userTypes;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            default:
                logAxisError("Cannot get the list of users in group: " + groupId, f);
        }
        return null;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.error("Cannot get the list of users in group: " + groupId, e);
        return null;
    }
}
Also used : Usertype(de.vitero.schema.user.Usertype) GetUserListByGroupRequest(de.vitero.schema.user.GetUserListByGroupRequest) WebServiceException(javax.xml.ws.WebServiceException) Userlist(de.vitero.schema.user.Userlist) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ConnectException(java.net.ConnectException)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)378 Test (org.junit.Test)115 SOAPException (javax.xml.soap.SOAPException)59 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)59 SOAPMessage (javax.xml.soap.SOAPMessage)57 ConnectException (java.net.ConnectException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 URL (java.net.URL)46 SOAPElement (javax.xml.soap.SOAPElement)46 IOException (java.io.IOException)43 SOAPBody (javax.xml.soap.SOAPBody)34 ArrayList (java.util.ArrayList)32 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)32 BindingProvider (javax.xml.ws.BindingProvider)31 Retry (io.github.resilience4j.retry.Retry)29 Service (javax.xml.ws.Service)29 QName (javax.xml.namespace.QName)27 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)21 DataHandler (javax.activation.DataHandler)17 RetryConfig (io.github.resilience4j.retry.RetryConfig)16