[英]cannot connect to the server stub using java client
I recently joined a project.I am a beginner. 我最近加入了一个项目。我是新手。 My responsibility is to create server stub, create SDK and create a java client using SDk and communicate with server stub.
我的责任是使用SDk创建服务器存根,创建SDK和创建Java客户端,并与服务器存根进行通信。
I created server stub using, 我使用创建了服务器存根
java -jar /data/Swagger/swagger-codegen-cli.jar generate \
-i /data/AM/ame/ameee.json \
-l spring --library spring-mvc\
-o /data/stub/spring_mvc
Run it using, 使用运行它,
mvn clean package jetty:run
url is, 网址是
http://localhost:8002/api/swagger-ui.html
generated SDK using, 生成的SDK使用,
java -jar /data/Swagger/swagger-codegen-cli.jar generate \
-i /data/AM/ame/ameee.json \
-l java\
-o /data/stub/SDK
Then i compiled the SDk and imported the .jar file to my client project, this is the code, 然后我编译了SDk并将.jar文件导入到我的客户端项目中,这是代码,
import io.swagger.client.*;
import io.swagger.client.auth.*;
import io.swagger.client.model.*;
import io.swagger.client.api.MonatizationAPIApi;
import java.io.File;
import java.util.*;
public class MonatizationAPIApiExample {
public static void main(String[] args) {
MonatizationAPIApi apiInstance = new MonatizationAPIApi();
try {
List<ParticipantType> result = apiInstance.getAllParticipantTypesUsingGET();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MonatizationAPIApi#getAllParticipantTypesUsingGET");
e.printStackTrace();
}
}
}
I'm still trying to get a connection to the server stub, 我仍在尝试与服务器存根建立连接,
this is the error, 这是错误,
Exception when calling MonatizationAPIApi#getAllParticipantTypesUsingGET
io.swagger.client.ApiException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:8080
at io.swagger.client.ApiClient.execute(ApiClient.java:984)
at io.swagger.client.api.MonatizationAPIApi.getAllParticipantTypesUsingGETWithHttpInfo(MonatizationAPIApi.java:878)
at io.swagger.client.api.MonatizationAPIApi.getAllParticipantTypesUsingGET(MonatizationAPIApi.java:865)
at MonatizationAPIApiExample.main(MonatizationAPIApiExample.java:19)
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:120)
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:8080
at com.squareup.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143)
at com.squareup.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
at com.squareup.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.squareup.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.squareup.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.squareup.okhttp.Call.getResponse(Call.java:286)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:243)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:205)
at com.squareup.okhttp.Call.execute(Call.java:80)
at io.swagger.client.ApiClient.execute(ApiClient.java:980)
... 8 more
Process finished with exit code 0
Here the calling address differ from my server stub address. 这里的呼叫地址不同于我的服务器存根地址。 How can i change it?
我该如何更改? (I searched everywhere, i can't find an address like this
localhost/0:0:0:0:0:0:0:1:8080
in the code. (我到处搜索,我在代码中找不到像
localhost/0:0:0:0:0:0:0:1:8080
的地址。
PLzz help me. 请帮我。 Thank you
谢谢
My guess is that your OpenAPI/Swagger spec does not have a proper host
defined: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L12 and therefore Swagger Codegen defaults it to localhost. 我的猜测是您的OpenAPI / Swagger规范没有定义正确的
host
: https : //github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0 /petstore.yaml#L12 ,因此Swagger Codegen将其默认为localhost。
You can also change the host
during runtime in the Configuration
object (Java API client) 您还可以在运行时在
Configuration
对象(Java API客户端)中更改host
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.