List of usage examples for com.squareup.okhttp HttpUrl parse
public static HttpUrl parse(String url)
From source file:net.yatomiya.nicherry.services.bbs.model.URLToken.java
License:Open Source License
public static URLToken create(AnalyzedMessage message, int offset, int length, String text, String urlString) { HttpUrl url = HttpUrl.parse(urlString); if (url == null) { url = HttpUrl.parse("http://localhost/"); }//from ww w . j a va 2 s.c o m String ext = StringUtils.getExtension(HttpUtils.getPathName(url)); URLToken token = null; if (ImageURLToken.isLoadableImageExtension(ext)) { token = new ImageURLToken(message, offset, length, text, urlString); } else { try { token = new ThreadURLToken(message, offset, length, text, urlString); } catch (IllegalArgumentException e) { } } if (token == null) { token = new URLToken(message, offset, length, text, urlString); } return token; }
From source file:net.yatomiya.nicherry.services.bbs.ModelUpdateHandler.java
License:Open Source License
protected Request.Builder createRequestBuilder() { MBBSModel model = getModel();/*from ww w .j a v a 2 s.c o m*/ HttpUrl url = HttpUrl.parse(createRequestUrl()); Request.Builder builder = HttpUtils.createRequestBuilder(url, isForceUpdate ? null : new Date(model.getLastModifiedInResponseHeader())); builder.tag(this); return builder; }
From source file:net.yatomiya.nicherry.ui.handlers.SearchWebHandler.java
License:Open Source License
@Execute public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TextSelection selection) { String query = selection.getText(); query = HttpUtils.urlEncode(query);// w ww . j a v a 2 s.c o m String searchUrl = NUtils.getPreference(NPreferences.WEB_SEARCH_URL); searchUrl = searchUrl.replace(QUERY_REPLACE, query); HttpUrl url = HttpUrl.parse(searchUrl); Program.launch(url.toString()); }
From source file:org.eyeseetea.malariacare.SettingsActivity.java
License:Open Source License
/** * Logins programatically into new server to initialize sdk api * @param serverInfo// w w w .j a v a 2s . c om */ private void initLoginPrePull(ServerInfo serverInfo) { HttpUrl serverUri = HttpUrl.parse(serverInfo.getUrl()); DhisService.logInUser(serverUri, ServerAPIController.getSDKCredentials()); }
From source file:org.mariotaku.twidere.util.OAuthPasswordAuthenticator.java
License:Open Source License
public OAuthPasswordAuthenticator(final TwitterOAuth oauth, final LoginVerificationCallback loginVerificationCallback, final String userAgent) { final RestClient restClient = RestAPIFactory.getRestClient(oauth); this.oauth = oauth; this.client = (OkHttpRestClient) restClient.getRestClient(); final OkHttpClient okhttp = client.getClient(); okhttp.setCookieHandler(new CookieManager()); okhttp.networkInterceptors().add(new Interceptor() { @Override//from w w w .ja v a 2 s . com public Response intercept(Chain chain) throws IOException { final Response response = chain.proceed(chain.request()); if (!response.isRedirect()) { return response; } final String location = response.header("Location"); final Response.Builder builder = response.newBuilder(); if (!TextUtils.isEmpty(location) && !endpoint.checkEndpoint(location)) { final HttpUrl originalLocation = HttpUrl .get(URI.create("https://api.twitter.com/").resolve(location)); final HttpUrl.Builder locationBuilder = HttpUrl.parse(endpoint.getUrl()).newBuilder(); for (String pathSegments : originalLocation.pathSegments()) { locationBuilder.addPathSegment(pathSegments); } for (int i = 0, j = originalLocation.querySize(); i < j; i++) { final String name = originalLocation.queryParameterName(i); final String value = originalLocation.queryParameterValue(i); locationBuilder.addQueryParameter(name, value); } final String encodedFragment = originalLocation.encodedFragment(); if (encodedFragment != null) { locationBuilder.encodedFragment(encodedFragment); } final HttpUrl newLocation = locationBuilder.build(); builder.header("Location", newLocation.toString()); } return builder.build(); } }); this.endpoint = restClient.getEndpoint(); this.loginVerificationCallback = loginVerificationCallback; this.userAgent = userAgent; }
From source file:org.sonar.batch.report.ReportPublisher.java
License:Open Source License
@Override public void start() { reportDir = new File(projectReactor.getRoot().getWorkDir(), "batch-report"); writer = new ScannerReportWriter(reportDir); contextPublisher.init(writer);//from w w w . j a v a2 s .c om if (!analysisMode.isIssues() && !analysisMode.isMediumTest()) { String publicUrl = publicUrl(); if (HttpUrl.parse(publicUrl) == null) { throw MessageException.of("Failed to parse public URL set in SonarQube server: " + publicUrl); } } }
From source file:org.sonar.batch.report.ReportPublisher.java
License:Open Source License
@VisibleForTesting void logSuccess(@Nullable String taskId) { if (taskId == null) { LOG.info("ANALYSIS SUCCESSFUL"); } else {/* w w w . j ava 2s. c om*/ String publicUrl = publicUrl(); HttpUrl httpUrl = HttpUrl.parse(publicUrl); Map<String, String> metadata = new LinkedHashMap<>(); String effectiveKey = projectReactor.getRoot().getKeyWithBranch(); metadata.put("projectKey", effectiveKey); metadata.put("serverUrl", publicUrl); URL dashboardUrl = httpUrl.newBuilder().addPathSegment("dashboard").addPathSegment("index") .addPathSegment(effectiveKey).build().url(); metadata.put("dashboardUrl", dashboardUrl.toExternalForm()); URL taskUrl = HttpUrl.parse(publicUrl).newBuilder().addPathSegment("api").addPathSegment("ce") .addPathSegment("task").addQueryParameter("id", taskId).build().url(); metadata.put("ceTaskId", taskId); metadata.put("ceTaskUrl", taskUrl.toExternalForm()); LOG.info("ANALYSIS SUCCESSFUL, you can browse {}", dashboardUrl); LOG.info( "Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report"); LOG.info("More about the report processing at {}", taskUrl); dumpMetadata(metadata); } }
From source file:org.sonarqube.ws.client.HttpConnector.java
License:Open Source License
private HttpConnector(Builder builder, JavaVersion javaVersion) { this.baseUrl = HttpUrl.parse(builder.url.endsWith("/") ? builder.url : format("%s/", builder.url)); this.userAgent = builder.userAgent; if (isNullOrEmpty(builder.login)) { // no login nor access token this.credentials = null; } else {/* w w w . j a v a 2s . c om*/ // password is null when login represents an access token. In this case // the Basic credentials consider an empty password. this.credentials = Credentials.basic(builder.login, nullToEmpty(builder.password)); } if (builder.proxy != null) { this.okHttpClient.setProxy(builder.proxy); } // proxy credentials can be used on system-wide proxies, so even if builder.proxy is null if (isNullOrEmpty(builder.proxyLogin)) { this.proxyCredentials = null; } else { this.proxyCredentials = Credentials.basic(builder.proxyLogin, nullToEmpty(builder.proxyPassword)); } this.okHttpClient.setConnectTimeout(builder.connectTimeoutMs, TimeUnit.MILLISECONDS); this.okHttpClient.setReadTimeout(builder.readTimeoutMs, TimeUnit.MILLISECONDS); ConnectionSpec tls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledTlsVersions() .allEnabledCipherSuites().supportsTlsExtensions(true).build(); this.okHttpClient.setConnectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT)); if (javaVersion.isJava7()) { // OkHttp executes SSLContext.getInstance("TLS") by default (see // https://github.com/square/okhttp/blob/c358656/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java#L616) // As only TLS 1.0 is enabled by default in Java 7, the SSLContextFactory must be changed // in order to support all versions from 1.0 to 1.2. // Note that this is not overridden for Java 8 as TLS 1.2 is enabled by default. // Keeping getInstance("TLS") allows to support potential future versions of TLS on Java 8. try { this.okHttpClient.setSslSocketFactory( new Tls12Java7SocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault())); } catch (Exception e) { throw new IllegalStateException("Fail to init TLS context", e); } } }