本文整理汇总了Java中retrofit2.converter.simplexml.SimpleXmlConverterFactory类的典型用法代码示例。如果您正苦于以下问题:Java SimpleXmlConverterFactory类的具体用法?Java SimpleXmlConverterFactory怎么用?Java SimpleXmlConverterFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleXmlConverterFactory类属于retrofit2.converter.simplexml包,在下文中一共展示了SimpleXmlConverterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public static void main(String... args) throws IOException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody("{\"name\": \"Jason\"}"));
server.enqueue(new MockResponse().setBody("<user name=\"Eximel\"/>"));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new QualifiedTypeConverterFactory(
GsonConverterFactory.create(),
SimpleXmlConverterFactory.create()))
.build();
Service service = retrofit.create(Service.class);
User user1 = service.exampleJson().execute().body();
System.out.println("User 1: " + user1.name);
User user2 = service.exampleXml().execute().body();
System.out.println("User 2: " + user2.name);
server.shutdown();
}
示例2: initService
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
private void initService(){
// Add the interceptor to OkHttpClient
OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.build();
//Google service
Retrofit retrofitGoogle = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(GOOGLE_API_URL)
.client(client)
.build();
mGoogleService = retrofitGoogle.create(IGoogleBookAPI.class);
//Goodreads service
Retrofit retrofitGoodReads = new Retrofit.Builder()
.addConverterFactory(SimpleXmlConverterFactory.create())
.baseUrl(GOODREADS_API_URL)
.client(client)
.build();
mGoodreadsService = retrofitGoodReads.create(IGoodreadsAPI.class);
}
示例3: RetrofitApi
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
private RetrofitApi() {
OkHttpClient okHttpClient = createClient();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ApiConstants.API_END_POINT)
.client(okHttpClient)
.addConverterFactory(new QualifiedTypeConverterFactory(
GsonConverterFactory.create(),
SimpleXmlConverterFactory.create()
))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
buildServices(retrofit);
}
示例4: provideRestAdapter
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
@Provides
@Singleton
Retrofit provideRestAdapter(Session session) {
// LoggingInterceptor interceptor = new LoggingInterceptor(session);
HttpLoggingInterceptor interceptorHttp = new HttpLoggingInterceptor();
interceptorHttp.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(Constants.TIME_OUT_CONNECTION, TimeUnit.SECONDS); // connect timeout
// builder.interceptors().add(interceptor);
builder.interceptors().add(interceptorHttp);
OkHttpClient client = builder.build();
return new Retrofit.Builder()
.baseUrl(Constants.API_URL_TARIKI)
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
}
示例5: initializeRetrofit
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
private void initializeRetrofit(){
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl(Const.BASE_API_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
twohRetro = new Retrofit.Builder()
.baseUrl(Const.BASE_URL)
.client(client)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
示例6: getITHomeApi
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public static ITHomeApi getITHomeApi() {
if (itHomeApi == null) {
synchronized (ITHomeApi.class) {
if (itHomeApi == null) {
itHomeApi = new Retrofit.Builder()
.baseUrl("http://api.ithome.com/")
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(client)
.build()
.create(ITHomeApi.class);
}
}
}
return itHomeApi;
}
示例7: main
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public static void main(String... args) throws IOException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse().setBody("{\"name\": \"Moshi\"}"));
server.enqueue(new MockResponse().setBody("{\"name\": \"Gson\"}"));
server.enqueue(new MockResponse().setBody("<user name=\"SimpleXML\"/>"));
server.enqueue(new MockResponse().setBody("{\"name\": \"Gson\"}"));
com.squareup.moshi.Moshi moshi = new com.squareup.moshi.Moshi.Builder().build();
com.google.gson.Gson gson = new GsonBuilder().create();
MoshiConverterFactory moshiConverterFactory = MoshiConverterFactory.create(moshi);
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
SimpleXmlConverterFactory simpleXmlConverterFactory = SimpleXmlConverterFactory.create();
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/"))
.addConverterFactory(
new AnnotatedConverterFactory.Builder().add(Moshi.class, moshiConverterFactory)
.add(Gson.class, gsonConverterFactory)
.add(SimpleXml.class, simpleXmlConverterFactory)
.build())
.addConverterFactory(gsonConverterFactory)
.build();
Service service = retrofit.create(Service.class);
Library library1 = service.exampleMoshi().execute().body();
System.out.println("Library 1: " + library1.name);
Library library2 = service.exampleGson().execute().body();
System.out.println("Library 2: " + library2.name);
Library library3 = service.exampleSimpleXml().execute().body();
System.out.println("Library 3: " + library3.name);
Library library4 = service.exampleDefault().execute().body();
System.out.println("Library 4: " + library4.name);
server.shutdown();
}
示例8: SearchedBookLoader
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
SearchedBookLoader(Context context, String searchQuery) {
super(context);
this.searchQuery = searchQuery;
requestPage = 1;
retrofit = new Retrofit.Builder()
.baseUrl(GoodreadsService.BASE_URL)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
}
示例9: getRetrofitClient
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public Retrofit getRetrofitClient(String baseUrl) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
}
return retrofit;
}
示例10: NewsDataSource
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public NewsDataSource() {
tvn24Rss = new Retrofit.Builder()
.baseUrl("https://www.tvn24.pl/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build()
.create(Tvn24Rss.class);
polsatNewsRss = new Retrofit.Builder()
.baseUrl("http://www.polsatnews.pl/rss/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build()
.create(PolsatNewsRss.class);
}
示例11: createService
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
static <S> S createService(Class<S> serviceClass, String apiBaseUrl, String username, String password) {
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(apiBaseUrl)
.addConverterFactory(SimpleXmlConverterFactory.createNonStrict(Factory.persister()));
String authToken = Credentials.basic(username, password);
builder.client(createOkHttpClient(authToken));
return builder.build().create(serviceClass);
}
示例12: RetrofitRssFeedProvider
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public RetrofitRssFeedProvider() {
this.mRssFeedService = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
.build()
.create(RssFeedService.class);
}
示例13: buildRetrofit
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
private static Retrofit buildRetrofit() {
final OkHttpClient client = new OkHttpClient();
final String endpoint = BASE_URL;
return new Retrofit.Builder()
.baseUrl(endpoint)
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
}
示例14: getItHomeApi
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public static ItHomeApi getItHomeApi() {
synchronized (monitor) {
if (itHomeApi == null) {
itHomeApi = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(SimpleXmlConverterFactory.create())
.client(client)
.baseUrl("http://api.ithome.com")
.build().create(ItHomeApi.class);
}
return itHomeApi;
}
}
示例15: getClientXml
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; //导入依赖的package包/类
public static ApiEndpointInterface getClientXml() {
if (apiInterfaceXml == null) {
synchronized (LOCK_XML) {
if (apiInterfaceXml == null) {
Retrofit client = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
apiInterfaceXml = client.create(ApiEndpointInterface.class);
}
}
}
return apiInterfaceXml;
}