Search in sources :

Example 1 with BindingProvider

use of javax.xml.ws.BindingProvider in project midpoint by Evolveum.

the class Action method createModelPort.

protected ModelPortType createModelPort() {
    ModelService modelService = new ModelService();
    ModelPortType port = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) port;
    Client client = ClientProxy.getClient(port);
    Endpoint endpoint = client.getEndpoint();
    HTTPConduit http = (HTTPConduit) client.getConduit();
    HTTPClientPolicy httpClientPolicy = http.getClient();
    if (httpClientPolicy == null) {
        httpClientPolicy = new HTTPClientPolicy();
        http.setClient(httpClientPolicy);
    }
    httpClientPolicy.setConnectionTimeout(10000);
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, params.getUrl().toString());
    requestContext.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    requestContext.put(WSHandlerConstants.USER, params.getUsername());
    requestContext.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    ClientPasswordHandler handler = new ClientPasswordHandler();
    handler.setPassword(params.getInsertedPassword());
    requestContext.put(WSHandlerConstants.PW_CALLBACK_REF, handler);
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(requestContext);
    endpoint.getOutInterceptors().add(wssOut);
    if (params.isVerbose()) {
        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
        endpoint.getInInterceptors().add(new LoggingInInterceptor());
    }
    return port;
}
Also used : ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) BindingProvider(javax.xml.ws.BindingProvider) ModelService(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) Endpoint(org.apache.cxf.endpoint.Endpoint) ClientPasswordHandler(com.evolveum.midpoint.cli.ninja.util.ClientPasswordHandler) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor) Client(org.apache.cxf.endpoint.Client)

Example 2 with BindingProvider

use of javax.xml.ws.BindingProvider in project nhin-d by DirectProject.

the class DocumentRepositoryProxy method initProxy.

private void initProxy() {
    try {
        URL url = DocumentRepositoryProxy.class.getClassLoader().getResource("XDS.b_DocumentRepositoryWSDLSynchMTOM.wsdl");
        QName qname = new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_Service");
        DocumentRepositoryService service = new DocumentRepositoryService(url, qname);
        if (handlerResolver != null)
            service.setHandlerResolver(handlerResolver);
        proxy = service.getDocumentRepositoryPortSoap12(new MTOMFeature(true, 1));
        BindingProvider bp = (BindingProvider) proxy;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();
        binding.setMTOMEnabled(true);
        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    } catch (Exception e) {
        LOGGER.error("Error initializing proxy.", e);
    }
}
Also used : QName(javax.xml.namespace.QName) MTOMFeature(javax.xml.ws.soap.MTOMFeature) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DocumentRepositoryService(ihe.iti.xds_b._2007.DocumentRepositoryService) URL(java.net.URL) OperationNotSupportedException(javax.naming.OperationNotSupportedException)

Example 3 with BindingProvider

use of javax.xml.ws.BindingProvider in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method initializeStub.

public void initializeStub() throws Exception {
    URL wsdl_locationUrl = this.getClass().getResource("/wsdl/netsuite.wsdl");
    QName serviceQname = new QName("urn:platform_2014_2.webservices.netsuite.com", "NetSuiteService");
    NetSuiteService service = new NetSuiteService(wsdl_locationUrl, serviceQname);
    NetSuitePortType port = service.getNetSuitePort();
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, _url);
    Preferences preferences = new Preferences();
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.FALSE);
    preferences.setWarningAsError(Boolean.FALSE);
    preferences.setIgnoreReadOnlyFields(Boolean.TRUE);
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.TRUE);
    SearchPreferences searchPreferences = new SearchPreferences();
    searchPreferences.setPageSize(this._pageSize);
    searchPreferences.setBodyFieldsOnly(Boolean.valueOf(false));
    RecordRef role = new RecordRef();
    role.setInternalId(this._role);
    Passport passport = new Passport();
    passport.setEmail(this._email);
    passport.setPassword(this._pwd);
    passport.setRole(role);
    passport.setAccount(this._account);
    // Get the webservices domain for your account
    GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
    dataCenterRequest.setAccount(this._account);
    DataCenterUrls urls = null;
    GetDataCenterUrlsResponse reponse = port.getDataCenterUrls(dataCenterRequest);
    if (reponse != null && reponse.getGetDataCenterUrlsResult() != null) {
        urls = reponse.getGetDataCenterUrlsResult().getDataCenterUrls();
    }
    if (urls == null) {
        throw new Exception("Can't get a correct webservice domain! Please check your configuration or try to run again.");
    }
    String wsDomain = urls.getWebservicesDomain();
    String endpoint = wsDomain.concat(new URL(this._url).getPath());
    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    if (list == null) {
        list = new ArrayList<Header>();
        requestContext.put(Header.HEADER_LIST, list);
    }
    Header searchPreferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
    Header preferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
    list.add(searchPreferences_header);
    list.add(preferences_header);
    LoginRequest request = new LoginRequest();
    request.setPassport(passport);
    port.login(request);
    this._port = port;
    Arrays.asList(new String[] { "", "", "" });
}
Also used : GetDataCenterUrlsResponse(com.netsuite.webservices.platform.messages.GetDataCenterUrlsResponse) QName(javax.xml.namespace.QName) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) DataCenterUrls(com.netsuite.webservices.platform.core.DataCenterUrls) BindingProvider(javax.xml.ws.BindingProvider) LoginRequest(com.netsuite.webservices.platform.messages.LoginRequest) URL(java.net.URL) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SOAPException(javax.xml.soap.SOAPException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.platform.NetSuitePortType) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Passport(com.netsuite.webservices.platform.core.Passport) Header(org.apache.cxf.headers.Header) NetSuiteService(com.netsuite.webservices.platform.NetSuiteService) GetDataCenterUrlsRequest(com.netsuite.webservices.platform.messages.GetDataCenterUrlsRequest) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Preferences(com.netsuite.webservices.platform.messages.Preferences)

Example 4 with BindingProvider

use of javax.xml.ws.BindingProvider in project ats-framework by Axway.

the class AgentServicePool method createServicePort.

private AgentService createServicePort(String host) throws AgentException {
    try {
        String protocol = AgentConfigurator.getConnectionProtocol(host);
        if (protocol == null) {
            protocol = "http";
        } else {
            SslUtils.trustAllHttpsCertificates();
            SslUtils.trustAllHostnames();
        }
        URL url = this.getClass().getResource("/META-INF/wsdl/" + AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME + ".wsdl");
        Service agentService = Service.create(url, new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME));
        AgentService agentServicePort = agentService.getPort(new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_PORT_NAME), AgentService.class);
        Map<String, Object> ctxt = ((BindingProvider) agentServicePort).getRequestContext();
        // setting ENDPOINT ADDRESS, which defines the web service URL for SOAP communication
        // NOTE: if we specify WSDL URL (...<endpoint_address>?wsdl), the JBoss server returns the WSDL on a SOAP call,
        // but we are expecting a SOAP message response and an exception is thrown.
        // The Jetty server (in ATS agents) is working in both cases.
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, protocol + "://" + host + AgentWsDefinitions.AGENT_SERVICE_ENDPOINT_ADDRESS);
        // setting timeouts
        // timeout in milliseconds
        ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, 10000);
        // check if new unique id must be generated each time
        if (!useNewUuId) {
            // create temp file containing caller working directory and the unique id
            String userWorkingDirectory = AtsSystemProperties.SYSTEM_USER_HOME_DIR;
            String uuiFileLocation = AtsSystemProperties.SYSTEM_USER_TEMP_DIR + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "\\ats_uid.txt";
            File uuiFile = new File(uuiFileLocation);
            // otherwise add it to the file 
            if (uuiFile.exists()) {
                String uuiFileContent = IoUtils.streamToString(IoUtils.readFile(uuiFileLocation));
                if (uuiFileContent.contains(userWorkingDirectory)) {
                    for (String line : uuiFileContent.split("\n")) {
                        if (line.contains(userWorkingDirectory)) {
                            uniqueId = line.substring(userWorkingDirectory.length()).trim();
                        }
                    }
                } else {
                    generateNewUUID();
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            } else {
                generateNewUUID();
                try {
                    uuiFile.createNewFile();
                } catch (IOException e) {
                    log.warn("Unable to create file '" + uuiFile.getAbsolutePath() + "'");
                }
                if (uuiFile.exists()) {
                    new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
                }
            }
        } else {
            generateNewUUID();
        }
        // add header with unique session ID
        Map<String, List<String>> requestHeaders = new HashMap<>();
        requestHeaders.put(ApplicationContext.ATS_UID_SESSION_TOKEN, Arrays.asList(uniqueId));
        ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
        return agentServicePort;
    } catch (Exception e) {
        throw new AgentException("Cannot connect to Agent application on host '" + host + "' check your configuration", e);
    }
}
Also used : LocalFileSystemOperations(com.axway.ats.core.filesystem.LocalFileSystemOperations) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AgentException(com.axway.ats.agent.core.exceptions.AgentException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) IOException(java.io.IOException) URL(java.net.URL) AgentException(com.axway.ats.agent.core.exceptions.AgentException) IOException(java.io.IOException) List(java.util.List) File(java.io.File)

Example 5 with BindingProvider

use of javax.xml.ws.BindingProvider in project cloudstack by apache.

the class VmwareClient method connect.

/**
     * Establishes session with the virtual center server.
     *
     * @throws Exception
     *             the exception
     */
public void connect(String url, String userName, String password) throws Exception {
    svcInstRef.setType(SVC_INST_NAME);
    svcInstRef.setValue(SVC_INST_NAME);
    vimPort = vimService.getVimPort();
    Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
    ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    ctxt.put("com.sun.xml.internal.ws.request.timeout", vCenterSessionTimeout);
    ctxt.put("com.sun.xml.internal.ws.connect.timeout", vCenterSessionTimeout);
    ServiceContent serviceContent = vimPort.retrieveServiceContent(svcInstRef);
    // Extract a cookie. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
    @SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) ((BindingProvider) vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
    List<String> cookies = headers.get("Set-cookie");
    vimPort.login(serviceContent.getSessionManager(), userName, password, null);
    if (cookies == null) {
        // Get the cookie from the response header. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
        @SuppressWarnings("unchecked") Map<String, List<String>> responseHeaders = (Map<String, List<String>>) ((BindingProvider) vimPort).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
        cookies = responseHeaders.get("Set-cookie");
        if (cookies == null) {
            String msg = "Login successful, but failed to get server cookies from url :[" + url + "]";
            s_logger.error(msg);
            throw new Exception(msg);
        }
    }
    String cookieValue = cookies.get(0);
    StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");
    cookieValue = tokenizer.nextToken();
    String pathData = "$" + tokenizer.nextToken();
    serviceCookie = "$Version=\"1\"; " + cookieValue + "; " + pathData;
    isConnected = true;
}
Also used : StringTokenizer(java.util.StringTokenizer) ServiceContent(com.vmware.vim25.ServiceContent) ArrayList(java.util.ArrayList) List(java.util.List) BindingProvider(javax.xml.ws.BindingProvider) Map(java.util.Map) WebServiceException(javax.xml.ws.WebServiceException)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)58 URL (java.net.URL)40 Service (javax.xml.ws.Service)39 Test (org.junit.Test)31 WebServiceException (javax.xml.ws.WebServiceException)17 QName (javax.xml.namespace.QName)12 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)7 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)6 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)6 HashMap (java.util.HashMap)6 File (java.io.File)4 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)4 InvocationHandler (java.lang.reflect.InvocationHandler)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 DocumentRepositoryService (ihe.iti.xds_b._2007.DocumentRepositoryService)2 ArrayList (java.util.ArrayList)2 SOAPBinding (javax.xml.ws.soap.SOAPBinding)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2