Search in sources :

Example 6 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project openolat by klemens.

the class ViteroManager method checkConnection.

public boolean checkConnection(final String url, final String login, final String password, final int customerId) throws VmsNotAvailableException {
    try {
        LicenceService ss = new LicenceService();
        ss.setHandlerResolver(new HandlerResolver() {

            @SuppressWarnings("rawtypes")
            @Override
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlerList = new ArrayList<Handler>();
                handlerList.add(new ViteroSecurityHandler(login, password));
                return handlerList;
            }
        });
        Licence port = ss.getLicenceSoap11();
        String endPoint = UriBuilder.fromUri(url).path("services").path("LicenseService").build().toString();
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
        GetModulesForCustomerRequest request = new GetModulesForCustomerRequest();
        request.setCustomerid(customerId);
        Modulestype modulesType = port.getModulesForCustomer(request);
        return modulesType != null;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case unsufficientRights:
                log.error("Unsufficient rights", f);
                break;
            default:
                logAxisError("Cannot check connection", f);
        }
        return false;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.warn("Error checking connection", e);
        return false;
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) DataHandler(javax.activation.DataHandler) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Modulestype(de.vitero.schema.licence.Modulestype) PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) GetModulesForCustomerRequest(de.vitero.schema.licence.GetModulesForCustomerRequest) Licence(de.vitero.schema.licence.Licence) ArrayList(java.util.ArrayList) List(java.util.List) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) LicenceService(de.vitero.schema.licence.LicenceService) ConnectException(java.net.ConnectException)

Example 7 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project OpenOLAT by OpenOLAT.

the class ViteroManager method checkConnection.

public boolean checkConnection(final String url, final String login, final String password, final int customerId) throws VmsNotAvailableException {
    try {
        LicenceService ss = new LicenceService();
        ss.setHandlerResolver(new HandlerResolver() {

            @SuppressWarnings("rawtypes")
            @Override
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlerList = new ArrayList<Handler>();
                handlerList.add(new ViteroSecurityHandler(login, password));
                return handlerList;
            }
        });
        Licence port = ss.getLicenceSoap11();
        String endPoint = UriBuilder.fromUri(url).path("services").path("LicenseService").build().toString();
        ((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
        GetModulesForCustomerRequest request = new GetModulesForCustomerRequest();
        request.setCustomerid(customerId);
        Modulestype modulesType = port.getModulesForCustomer(request);
        return modulesType != null;
    } catch (SOAPFaultException f) {
        ErrorCode code = handleAxisFault(f);
        switch(code) {
            case unsufficientRights:
                log.error("Unsufficient rights", f);
                break;
            default:
                logAxisError("Cannot check connection", f);
        }
        return false;
    } catch (WebServiceException e) {
        if (e.getCause() instanceof ConnectException) {
            throw new VmsNotAvailableException();
        }
        log.warn("Error checking connection", e);
        return false;
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) DataHandler(javax.activation.DataHandler) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Modulestype(de.vitero.schema.licence.Modulestype) PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) GetModulesForCustomerRequest(de.vitero.schema.licence.GetModulesForCustomerRequest) Licence(de.vitero.schema.licence.Licence) ArrayList(java.util.ArrayList) List(java.util.List) ErrorCode(org.olat.modules.vitero.model.ErrorCode) ViteroSecurityHandler(de.vitero.ViteroSecurityHandler) LicenceService(de.vitero.schema.licence.LicenceService) ConnectException(java.net.ConnectException)

Example 8 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project photon-model by vmware.

the class BasicConnection method _connect.

@SuppressWarnings("unchecked")
private void _connect() throws RuntimeFaultFaultMsg, InvalidLocaleFaultMsg, InvalidLoginFaultMsg, com.vmware.pbm.RuntimeFaultFaultMsg {
    if (this.token != null) {
        /* This lock exists because header handlers are set per VimService.
            LoginByToken and normal login with username and password are using different sets of
            header handlers. If the correct handlers are not set, the connection will fail */
        synchronized (BasicConnection.class) {
            HandlerResolver defaultResolver = getVimService().getHandlerResolver();
            HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
            handlerResolver.addHandler(new TimeStampHandler());
            handlerResolver.addHandler(new SamlTokenExtractionHandler());
            try {
                handlerResolver.addHandler(new SamlTokenHandler(SamlUtils.createSamlDocument(this.token).getDocumentElement()));
                getVimService().setHandlerResolver(handlerResolver);
            } catch (ParserConfigurationException | SAXException | IOException e) {
                throw new RuntimeFaultFaultMsg("Unable to authenticate", e);
            }
            this.vimPort = getVimService().getVimPort();
            updateBindingProvider(getBindingsProvider(), this.uri.toString());
            this.serviceContent = this.vimPort.retrieveServiceContent(this.getServiceInstanceReference());
            try {
                this.userSession = this.vimPort.loginByToken(this.serviceContent.getSessionManager(), null);
            } finally {
                getVimService().setHandlerResolver(defaultResolver);
            }
        }
    } else {
        this.vimPort = getVimService().getVimPort();
        updateBindingProvider(getBindingsProvider(), this.uri.toString());
        this.serviceContent = this.vimPort.retrieveServiceContent(this.getServiceInstanceReference());
        this.userSession = this.vimPort.login(this.serviceContent.getSessionManager(), this.username, this.password, null);
    }
    this.headers = (Map<String, List<String>>) getBindingsProvider().getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
    // Need to extract only the cookie value
    List<String> cookieHeaders = this.headers.getOrDefault(HttpHeaderNames.SET_COOKIE.toString(), Collections.EMPTY_LIST);
    if (cookieHeaders.isEmpty()) {
        throw new RuntimeFaultFaultMsg("Failure in connecting to server, no session cookie found");
    }
    String cookieVal = cookieHeaders.get(0);
    String[] tokens = cookieVal.split(";");
    tokens = tokens[0].split("=");
    String extractedCookie = tokens[1];
    // PbmPortType
    this.pbmService = new PbmService();
    // Setting the header resolver for adding the VC session cookie to the
    // requests for authentication
    HeaderHandlerResolver headerResolver = new HeaderHandlerResolver();
    headerResolver.addHandler(new VcSessionHandler(extractedCookie));
    this.pbmService.setHandlerResolver(headerResolver);
    this.pbmPort = this.pbmService.getPbmPort();
    updateBindingProvider((BindingProvider) this.pbmPort, this.getSpbmURL().toString());
    this.pbmServiceContent = this.pbmPort.pbmRetrieveServiceContent(this.getPbmServiceInstanceReference());
}
Also used : IOException(java.io.IOException) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) SAXException(org.xml.sax.SAXException) HandlerResolver(javax.xml.ws.handler.HandlerResolver) PbmService(com.vmware.pbm.PbmService) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 9 with HandlerResolver

use of javax.xml.ws.handler.HandlerResolver in project cloudstack by apache.

the class VmwareClient method pbmConnect.

private void pbmConnect(String url, String cookieValue) throws Exception {
    URI uri = new URI(url);
    String pbmurl = "https://" + uri.getHost() + "/pbm";
    String[] tokens = cookieValue.split("=");
    String extractedCookie = tokens[1];
    HandlerResolver soapHandlerResolver = new HandlerResolver() {

        @Override
        public List<Handler> getHandlerChain(PortInfo portInfo) {
            VcenterSessionHandler VcSessionHandler = new VcenterSessionHandler(extractedCookie);
            List<Handler> handlerChain = new ArrayList<Handler>();
            handlerChain.add((Handler) VcSessionHandler);
            return handlerChain;
        }
    };
    pbmService.setHandlerResolver(soapHandlerResolver);
    pbmSvcInstRef.setType(PBM_SERVICE_INSTANCE_TYPE);
    pbmSvcInstRef.setValue(PBM_SERVICE_INSTANCE_VALUE);
    pbmPort = pbmService.getPbmPort();
    Map<String, Object> pbmCtxt = ((BindingProvider) pbmPort).getRequestContext();
    pbmCtxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    pbmCtxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, pbmurl);
}
Also used : PortInfo(javax.xml.ws.handler.PortInfo) HandlerResolver(javax.xml.ws.handler.HandlerResolver) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) BindingProvider(javax.xml.ws.BindingProvider) URI(java.net.URI)

Aggregations

HandlerResolver (javax.xml.ws.handler.HandlerResolver)9 ArrayList (java.util.ArrayList)6 PortInfo (javax.xml.ws.handler.PortInfo)6 List (java.util.List)5 QName (javax.xml.namespace.QName)4 WebServiceException (javax.xml.ws.WebServiceException)4 Handler (javax.xml.ws.handler.Handler)4 ViteroSecurityHandler (de.vitero.ViteroSecurityHandler)2 GetModulesForCustomerRequest (de.vitero.schema.licence.GetModulesForCustomerRequest)2 Licence (de.vitero.schema.licence.Licence)2 LicenceService (de.vitero.schema.licence.LicenceService)2 Modulestype (de.vitero.schema.licence.Modulestype)2 ConnectException (java.net.ConnectException)2 URL (java.net.URL)2 DataHandler (javax.activation.DataHandler)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 Service (javax.xml.ws.Service)2 WebServiceFeature (javax.xml.ws.WebServiceFeature)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2