这是我的代码:
import org.javaswift.joss.client.factory.AccountConfig;
import org.javaswift.joss.client.factory.AccountFactory;
import org.javaswift.joss.client.factory.AuthenticationMethod;
import org.javaswift.joss.model.Account;
import org.javaswift.joss.model.Container;
public class Main3 {
private static String serverIP = "172.18.22.58";
private static String username = "admin";
private static String password = "123456";
//I get X-Auth-Token from this URL
private static String keystoneURL = "http://"+serverIP+":35357/v2.0/tokens";
private static String tenantName = "admin";
private static String swiftTenantID = "ccd51bbb829f4852a5c1bca6d4f2eb33";
//I communicate with this URL to work with SWIFT
private static String swiftPublicURL = "http://"+serverIP+":8080/v1/AUTH_"+swiftTenantID;
public static void main(String[] args) {
AccountConfig config = new AccountConfig();
config.setDisableSslValidation(true);
config.setUsername(username);
config.setPassword(password);
config.setAuthUrl(keystoneURL);
//config.setTenantId(tenantId);
config.setTenantName(tenantName);
config.setAuthenticationMethod(AuthenticationMethod.KEYSTONE);
Account account = new AccountFactory(config).createAccount();
}
}
然后我得到了这个结果:
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / Creating real account instance
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / * Allow caching: true
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / Attempting authentication with tenant name: admin, tenant ID: null, username: admin, Auth URL: http://172.18.22.58:35357/v2.0/tokens
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / Successfully authenticated
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / Applying preferred region: none
[main] INFO org.javaswift.joss.client.impl.ClientImpl - JOSS / Using TempURL hash prefix source: PUBLIC_URL_PATH
Exception in thread "main" org.javaswift.joss.exception.CommandException: Unable to execute the HTTP call or to convert the HTTP Response
at org.javaswift.joss.command.impl.core.AbstractCommand.call(AbstractCommand.java:58)
at org.javaswift.joss.command.impl.core.AbstractSecureCommand.call(AbstractSecureCommand.java:31)
at org.javaswift.joss.client.core.AbstractAccount.getInfo(AbstractAccount.java:190)
at org.javaswift.joss.client.core.AbstractObjectStoreEntity.checkForInfo(AbstractObjectStoreEntity.java:98)
at org.javaswift.joss.client.core.AbstractObjectStoreEntity.checkForInfo(AbstractObjectStoreEntity.java:89)
at org.javaswift.joss.client.core.AbstractAccount.getServerTime(AbstractAccount.java:136)
at org.javaswift.joss.client.core.AbstractAccount.synchronizeWithServerTime(AbstractAccount.java:147)
at org.javaswift.joss.client.core.AbstractClient.authenticate(AbstractClient.java:43)
at org.javaswift.joss.client.factory.AccountFactory.createAccount(AccountFactory.java:30)
at Main3.main(Main3.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.net.UnknownHostException: controller
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
at java.net.InetAddress.getAllByName0(InetAddress.java:1255)
at java.net.InetAddress.getAllByName(InetAddress.java:1171)
at java.net.InetAddress.getAllByName(InetAddress.java:1105)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:278)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:162)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at org.javaswift.joss.command.impl.core.AbstractCommand.call(AbstractCommand.java:49)
... 14 more
Process finished with exit code 1
这是我在pom.xml中的依赖项:
groupId:org.javaswift
artifactId:joss
版本:0.9.8
的groupId:org.slf4j
的artifactId:SLF4J-简单
版本:1.7.12
我用rest客户端(firefox插件)测试我安装的swift,一切都很好。你在日志中看到我成功通过身份验证。但我不知道出了什么问题。
提前致谢
答案 0 :(得分:0)
我在Windows 7中遇到了同样的错误。
我编辑了C:\Windows\System32\drivers\etc\hosts
文件
添加第172.18.22.58 hostname
行。
然后一切都很好。