use of org.apache.chemistry.opencmis.client.SessionParameterMap in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method run.
@Override
public void run() throws Exception {
Session session;
SessionParameterMap parameters = new SessionParameterMap(getParameters());
if (!parameters.containsKey(SessionParameter.USER_AGENT)) {
parameters.setUserAgent(TCK_USER_AGENT);
}
String repId = parameters.get(SessionParameter.REPOSITORY_ID);
if (repId != null && repId.length() > 0) {
session = factory.createSession(parameters);
} else {
session = factory.getRepositories(parameters).get(0).createSession();
}
// switch off the cache
session.getDefaultContext().setCacheEnabled(false);
try {
run(session);
} catch (Exception e) {
if (!(e instanceof FatalTestException)) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Exception: " + e, e, true));
}
} catch (Error err) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Error: " + err, err, true));
} finally {
testFolder = null;
}
}
use of org.apache.chemistry.opencmis.client.SessionParameterMap in project iaf by ibissource.
the class CmisSessionBuilder method build.
/**
* @param userName to connect or empty when no username
* @param password
* @return a {@link Session} connected to the CMIS repository
* @throws CmisSessionException when the CmisSessionBuilder fails to connect to cmis repository
*/
public Session build(String userName, String password) throws CmisSessionException {
if (StringUtils.isEmpty(url) && overrideEntryPointWSDL == null) {
throw new CmisSessionException("no url configured");
}
if (StringUtils.isEmpty(repository)) {
throw new CmisSessionException("no repository configured");
}
if (getBindingType() == null) {
throw new CmisSessionException("no bindingType configured");
}
if (overrideEntryPointWSDL != null && getBindingType() != BindingTypes.WEBSERVICES) {
throw new CmisSessionException("illegal value for bindingtype [" + getBindingType() + "], overrideEntryPointWSDL only supports webservices");
}
log.debug("connecting to url [" + url + "] repository [" + repository + "]");
SessionParameterMap parameterMap = new SessionParameterMap();
if (StringUtils.isNotEmpty(userName))
parameterMap.setUserAndPassword(userName, password);
if (getBindingType() == BindingTypes.ATOMPUB) {
parameterMap.setAtomPubBindingUrl(url);
parameterMap.setUsernameTokenAuthentication(false);
} else if (getBindingType() == BindingTypes.BROWSER) {
parameterMap.setBrowserBindingUrl(url);
parameterMap.setBasicAuthentication();
// Add parameter dateTimeFormat to send dates in ISO format instead of milliseconds.
parameterMap.put(SessionParameter.BROWSER_DATETIME_FORMAT, DateTimeFormat.EXTENDED.value());
} else {
parameterMap.setUsernameTokenAuthentication(true);
// TODO: Does this work with any binding type?
if (overrideEntryPointWSDL != null) {
URL url = ClassUtils.getResourceURL(scopeProvider, overrideEntryPointWSDL);
if (url != null) {
try {
parameterMap.put(OVERRIDE_WSDL_KEY, Misc.streamToString(url.openStream()));
// We need to setup a fake URL in order to initialize the CMIS Session
parameterMap.setWebServicesBindingUrl(OVERRIDE_WSDL_URL);
} catch (IOException e) {
// eg. if the named charset is not supported
throw new CmisSessionException("error reading overrideEntryPointWSDL[" + overrideEntryPointWSDL + "]");
}
} else {
throw new CmisSessionException("cannot find overrideEntryPointWSDL[" + overrideEntryPointWSDL + "]");
}
} else {
parameterMap.setWebServicesBindingUrl(url);
parameterMap.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
parameterMap.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url + "/RepositoryService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url + "/NavigationService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url + "/ObjectService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url + "/VersioningService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url + "/DiscoveryService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url + "/RelationshipService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url + "/MultiFilingService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url + "/PolicyService.svc?wsdl");
parameterMap.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url + "/ACLService.svc?wsdl");
}
}
parameterMap.setRepositoryId(repository);
// SSL
if (keystore != null || truststore != null || allowSelfSignedCertificates) {
CredentialFactory keystoreCf = new CredentialFactory(keystoreAuthAlias, null, keystorePassword);
CredentialFactory keystoreAliasCf = StringUtils.isNotEmpty(keystoreAliasAuthAlias) || StringUtils.isNotEmpty(keystoreAliasPassword) ? new CredentialFactory(keystoreAliasAuthAlias, null, keystoreAliasPassword) : keystoreCf;
CredentialFactory truststoreCf = new CredentialFactory(truststoreAuthAlias, null, truststorePassword);
parameterMap.put("keystoreUrl", keystore);
parameterMap.put("keystorePassword", keystoreCf.getPassword());
parameterMap.put("keystoreType", keystoreType.name());
parameterMap.put("keystoreAlias", keystoreAlias);
parameterMap.put("keystoreAliasPassword", keystoreAliasCf.getPassword());
parameterMap.put("keyManagerAlgorithm", keyManagerAlgorithm);
parameterMap.put("truststoreUrl", truststore);
parameterMap.put("truststorePassword", truststoreCf.getPassword());
parameterMap.put("truststoreType", truststoreType.name());
parameterMap.put("trustManagerAlgorithm", trustManagerAlgorithm);
}
// SSL+
parameterMap.put("isAllowSelfSignedCertificates", "" + allowSelfSignedCertificates);
parameterMap.put("isVerifyHostname", "" + verifyHostname);
parameterMap.put("isIgnoreCertificateExpiredException", "" + ignoreCertificateExpiredException);
// PROXY
if (StringUtils.isNotEmpty(proxyHost)) {
CredentialFactory pcf = new CredentialFactory(proxyAuthAlias, proxyUserName, proxyPassword);
parameterMap.put("proxyHost", proxyHost);
parameterMap.put("proxyPort", "" + proxyPort);
parameterMap.put("proxyUsername", pcf.getUsername());
parameterMap.put("proxyPassword", pcf.getPassword());
}
if (maxConnections > 0)
parameterMap.put("maxConnections", maxConnections);
if (timeout > 0)
parameterMap.put(SessionParameter.CONNECT_TIMEOUT, timeout);
// Custom IBIS HttpSender to support ssl connections and proxies
parameterMap.setHttpInvoker(nl.nn.adapterframework.extensions.cmis.CmisHttpInvoker.class);
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Session session = sessionFactory.createSession(parameterMap);
log.debug("connected with repository [" + getRepositoryInfo(session) + "]");
return session;
}
Aggregations