OkHttpClient defaultHttpClient = new OkHttpClient.Builder() .addInterceptor( new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request request = chain.request().newBuilder() .addHeader("Accept", "Application/JSON").build(); return chain.proceed(request); } }).build();
public String messagesToJson(List<Message> messages) { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.registerTypeAdapter(Message.class, new MessageAdapter()).create(); return gson.toJson(messages); }
public EnterpriseBean localBean() { setLocalBean(new Empty()); return this; } }
public EjbLocalRef(final EjbReference ref) { this.ejbRefName = ref.getName(); this.ejbRefType = ref.getEjbRefType(); this.ejbLink = ref.getEjbLink(); this.mappedName = ref.getMappedName(); setDescriptions(ref.getDescriptions()); this.injectionTarget = ref.getInjectionTarget(); this.local = ref.getInterface(); this.localHome = ref.getHome(); }
@XmlElement(name = "message-driven-destination") public void setMessageDrivenDestination(final MessageDrivenDestination value) { if (activationConfig == null) activationConfig = new ActivationConfig(); final DestinationType destinationType = value.getDestinationType(); if (destinationType != null) { activationConfig.addProperty("destinationType", destinationType.getvalue()); } final SubscriptionDurability subscriptionDurability = value.getSubscriptionDurability(); if (subscriptionDurability != null) { activationConfig.addProperty("subscriptionDurability", subscriptionDurability.getvalue()); } }
@Override public boolean add(final PersistenceContextRef value) { if (!PersistenceContextType.EXTENDED.equals(value.getPersistenceContextType()) && !super.contains(value)) { return super.add(value); } return false; }
private static <R extends JndiReference> boolean isExtendedPersistenceContext(final R b) { return b instanceof PersistenceContextRef && PersistenceContextType.EXTENDED.equals(((PersistenceContextRef) b).getPersistenceContextType()); }
@Override public boolean afterOthers(WebFragmentEntry entry) { WebFragment webFragment = entry.getWebFragment(); if (webFragment.getOrdering() != null) { OrderingOrdering after = webFragment.getOrdering().getAfter(); if (after != null) { return after.getOthers() != null; } } return false; }
@XmlElement(name = "message-driven-destination") public void setMessageDrivenDestination(final MessageDrivenDestination value) { if (activationConfig == null) activationConfig = new ActivationConfig(); final DestinationType destinationType = value.getDestinationType(); if (destinationType != null) { activationConfig.addProperty("destinationType", destinationType.getvalue()); } final SubscriptionDurability subscriptionDurability = value.getSubscriptionDurability(); if (subscriptionDurability != null) { activationConfig.addProperty("subscriptionDurability", subscriptionDurability.getvalue()); } }
@Override public boolean add(final PersistenceContextRef value) { if (!PersistenceContextType.EXTENDED.equals(value.getPersistenceContextType()) && !super.contains(value)) { return super.add(value); } return false; }
private static <R extends JndiReference> boolean isExtendedPersistenceContext(final R b) { return b instanceof PersistenceContextRef && PersistenceContextType.EXTENDED.equals(((PersistenceContextRef) b).getPersistenceContextType()); }
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .header("Cache-Control", String.format("max-age=%d, only-if-cached, max-stale=%d", 120, 0)) .build(); } };
private boolean isExtented(final PersistenceContextRef ref) { final PersistenceContextType type = ref.getPersistenceContextType(); return type != null && type.equals(PersistenceContextType.EXTENDED); }
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .removeHeader("Pragma") .header("Cache-Control", String.format("max-age=%d", 60)) .build(); } };
OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request newRequest = chain.request().newBuilder() .addHeader("X-TOKEN", "VAL") .build(); return chain.proceed(newRequest); } }) .build(); Picasso picasso = new Picasso.Builder(context) .downloader(new OkHttp3Downloader(client)) .build();
OkHttpClient okClient = new OkHttpClient.Builder() .addInterceptor( new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request original = chain.request(); // Request customization: add request headers Request.Builder requestBuilder = original.newBuilder() .header("Authorization", token) .method(original.method(), original.body()); Request request = requestBuilder.build(); return chain.proceed(request); } }) .build();
public WebServiceClient() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(10, TimeUnit.SECONDS); client.setReadTimeout(30, TimeUnit.SECONDS); client.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { return onOnIntercept(chain); } }); Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .client(client) .build(); webService = retrofit.create(WebService.class); }
OkHttpClient httpClient = new OkHttpClient.Builder() .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Builder ongoing = chain.request().newBuilder(); ongoing.addHeader("Accept", "application/json;versions=1"); if (isUserLoggedIn()) { ongoing.addHeader("Authorization", getToken()); } return chain.proceed(ongoing.build()); } }) .build(); Retrofit retrofit = new Retrofit.Builder() // ... extra config .client(httpClient) .build();
.addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException {