List of usage examples for com.squareup.okhttp Request.Builder url
HttpUrl url
To view the source code for com.squareup.okhttp Request.Builder url.
Click Source Link
From source file:net.qiujuer.common.okhttp.impl.RequestCallBuilder.java
License:Apache License
@Override public Request.Builder builderGet(String url, StrParam... strParams) { StringBuilder sb = new StringBuilder(); // Check the url is have "?" char boolean isFirst = !url.contains("?"); // Add same values isFirst = buildGetParams(sb, isFirst); // Add values if (strParams != null && strParams.length > 0) { for (StrParam strParam : strParams) { if (strParam.key != null && strParam.value != null) { if (isFirst) { isFirst = false;/*from w w w .j a va 2s. c o m*/ sb.append("?"); } else { sb.append("&"); } sb.append(strParam.key); sb.append("="); sb.append(strParam.value); } } } url += sb.toString(); Request.Builder builder = createBuilder(); builder.url(url); builder.get(); return builder; }
From source file:net.qiujuer.common.okhttp.impl.RequestCallBuilder.java
License:Apache License
@Override public Request.Builder builderPost(String url, RequestBody body) { Request.Builder builder = createBuilder(); builder.url(url); // In this we proxy the ForwardRequestBody to support Progress builder.post(new ForwardRequestBody(body)); return builder; }
From source file:net.yatomiya.e4.util.HttpUtils.java
License:Open Source License
public static Request.Builder createRequestBuilder(HttpUrl url, Date lastModifiedSince) { Request.Builder builder = new Request.Builder(); builder.url(url); addLastModifiedHeader(builder, lastModifiedSince); return builder; }
From source file:net.yatomiya.nicherry.services.bbs.PostMessageHandler.java
License:Open Source License
public Call execute(ThreadProcessor processor, boolean isSynchronous, String name, String mail, String body, Map<String, String> additionalParams) { this.processor = processor; this.isSynchronous = isSynchronous; this.name = name; this.mail = mail; this.body = body; executeTime = JUtils.getCurrentTime(); EUtils.get(EventService.class).send(BBSService.Event.Post.START, getModel()); BBSService bbsSrv = processor.getManager().getBBSService(); BBSHttpClient client = bbsSrv.getHttpClient(); ThreadId threadId = getModel().getId(); MBoard board = bbsSrv.getBoard(threadId.getBoardId()); String hostUrl = HttpUtils.getHostUrl(board.getUrl()); String postUrl = hostUrl + "/test/bbs.cgi"; Request.Builder builder = new Request.Builder(); builder.url(postUrl); Map<String, String> valueMap = new HashMap<>(); valueMap.put("bbs", threadId.getBoardId().getIdValue()); valueMap.put("key", threadId.getIdValue()); valueMap.put("time", String.valueOf((JUtils.getCurrentTime() / 1000) - 60)); valueMap.put("submit", "??"); valueMap.put("FROM", name); valueMap.put("mail", mail); valueMap.put("MESSAGE", body); if (additionalParams != null) valueMap.putAll(additionalParams); String valueStr = HttpUtils.buildFormPostData(valueMap, NConstants.CHARSET_SHIFT_JIS); builder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded; charset=Shift_JIS"), StringUtils.getBytes(valueStr, NConstants.CHARSET_SHIFT_JIS))); builder.header("Referer", board.getUrl()); Request request = builder.build(); Callback callback = new Callback() { @Override//from w w w .j ava2s. c o m public void onResponse(Response response) throws IOException { EUtils.asyncExec(() -> doOnResponse(response)); } @Override public void onFailure(Request request, IOException e) { EUtils.asyncExec(() -> doOnFailure(request, e)); } }; httpCall = client.execute(request, callback, isSynchronous); postEvent = new PostMessageEvent(name, mail, body); return httpCall; }
From source file:org.apache.nifi.processors.standard.InvokeHTTP.java
License:Apache License
private Request configureRequest(final ProcessContext context, final ProcessSession session, final FlowFile requestFlowFile, URL url) { Request.Builder requestBuilder = new Request.Builder(); requestBuilder = requestBuilder.url(url); final String authUser = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_USERNAME).getValue()); // If the username/password properties are set then check if digest auth is being used if (!authUser.isEmpty() && "false".equalsIgnoreCase(context.getProperty(PROP_DIGEST_AUTH).getValue())) { final String authPass = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_PASSWORD).getValue()); String credential = com.squareup.okhttp.Credentials.basic(authUser, authPass); requestBuilder = requestBuilder.header("Authorization", credential); }/*w w w.jav a 2 s . co m*/ // set the request method String method = trimToEmpty( context.getProperty(PROP_METHOD).evaluateAttributeExpressions(requestFlowFile).getValue()) .toUpperCase(); switch (method) { case "GET": requestBuilder = requestBuilder.get(); break; case "POST": RequestBody requestBody = getRequestBodyToSend(session, context, requestFlowFile); requestBuilder = requestBuilder.post(requestBody); break; case "PUT": requestBody = getRequestBodyToSend(session, context, requestFlowFile); requestBuilder = requestBuilder.put(requestBody); break; case "PATCH": requestBody = getRequestBodyToSend(session, context, requestFlowFile); requestBuilder = requestBuilder.patch(requestBody); break; case "HEAD": requestBuilder = requestBuilder.head(); break; case "DELETE": requestBuilder = requestBuilder.delete(); break; default: requestBuilder = requestBuilder.method(method, null); } requestBuilder = setHeaderProperties(context, requestBuilder, requestFlowFile); return requestBuilder.build(); }
From source file:org.bitcoinj_extra.net.discovery.HttpDiscovery.java
License:Apache License
@Override public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException { try {/* w ww . ja v a 2s . c om*/ HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder(); if (services != 0) url.addQueryParameter("srvmask", Long.toString(services)); Request.Builder request = new Request.Builder(); request.url(url.build()); request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version. log.info("Requesting seeds from {}", url); Response response = client.newCall(request.build()).execute(); if (!response.isSuccessful()) throw new PeerDiscoveryException( "HTTP request failed: " + response.code() + " " + response.message()); InputStream stream = response.body().byteStream(); GZIPInputStream zip = new GZIPInputStream(stream); PeerSeedProtos.SignedPeerSeeds proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip); stream.close(); return protoToAddrs(proto); } catch (PeerDiscoveryException e1) { throw e1; } catch (Exception e) { throw new PeerDiscoveryException(e); } }
From source file:org.floens.chan.core.http.DeleteHttpCall.java
License:Open Source License
@Override public void setup(Request.Builder requestBuilder) { FormEncodingBuilder formBuilder = new FormEncodingBuilder(); formBuilder.add(Integer.toString(reply.no), "delete"); if (onlyImageDelete) { formBuilder.add("onlyimgdel", "on"); }//w w w . j a va 2 s . c o m formBuilder.add("mode", "usrdel"); formBuilder.add("pwd", reply.password); requestBuilder.url(ChanUrls.getDeleteUrl(reply.board)); requestBuilder.post(formBuilder.build()); }
From source file:org.floens.chan.core.http.PassHttpCall.java
License:Open Source License
@Override public void setup(Request.Builder requestBuilder) { FormEncodingBuilder formBuilder = new FormEncodingBuilder(); formBuilder.add("act", "do_login"); formBuilder.add("id", token); formBuilder.add("pin", pin); requestBuilder.url(ChanUrls.getPassUrl()); requestBuilder.post(formBuilder.build()); }
From source file:org.floens.chan.core.http.ReplyHttpCall.java
License:Open Source License
@Override public void setup(Request.Builder requestBuilder) { boolean thread = reply.resto >= 0; password = Long.toHexString(RANDOM.nextLong()); MultipartBuilder formBuilder = new MultipartBuilder(); formBuilder.type(MultipartBuilder.FORM); formBuilder.addFormDataPart("mode", "regist"); formBuilder.addFormDataPart("pwd", password); if (thread) { formBuilder.addFormDataPart("resto", String.valueOf(reply.resto)); }// w w w .ja va 2 s . c o m formBuilder.addFormDataPart("name", reply.name); formBuilder.addFormDataPart("email", reply.options); if (!thread && !TextUtils.isEmpty(reply.subject)) { formBuilder.addFormDataPart("sub", reply.subject); } formBuilder.addFormDataPart("com", reply.comment); if (reply.captchaResponse != null) { if (reply.captchaChallenge != null) { formBuilder.addFormDataPart("recaptcha_challenge_field", reply.captchaChallenge); formBuilder.addFormDataPart("recaptcha_response_field", reply.captchaResponse); } else { formBuilder.addFormDataPart("g-recaptcha-response", reply.captchaResponse); } } if (reply.file != null) { formBuilder.addFormDataPart("upfile", reply.fileName, RequestBody.create(MediaType.parse("application/octet-stream"), reply.file)); } if (reply.spoilerImage) { formBuilder.addFormDataPart("spoiler", "on"); } requestBuilder.url(ChanUrls.getReplyUrl(reply.board)); requestBuilder.post(formBuilder.build()); if (reply.usePass) { requestBuilder.addHeader("Cookie", "pass_id=" + reply.passId); } }
From source file:org.jboss.arquillian.ce.portfwd.PortForward.java
License:Open Source License
public synchronized PortForward.Handle run(PortForwardContext context) throws Exception { Request.Builder builder = new Request.Builder(); builder.url(String.format(PORT_FWD, context.getKubernetesMaster(), context.getNodeName(), context.getNamespace(), context.getPodName())); // https://github.com/kubernetes/kubernetes/blob/149ca1ec4971c4e5850d61d54d93b3ba315261a2/pkg/api/types.go#L1986 builder.addHeader("port", String.valueOf(context.getPort())); Request request = builder.build(); List<Interceptor> interceptors = client.networkInterceptors(); final ConnectionInterceptor interceptor = new ConnectionInterceptor(); interceptors.add(interceptor);/*from w w w. ja va 2 s . c om*/ try { client.newCall(request).execute(); } finally { interceptors.remove(interceptor); } final ServerSocket server = new ServerSocket(context.getPort(), 0, InetAddress.getLocalHost()); Runnable runnable = new Runnable() { public void run() { while (server.isClosed() == false) { try { final Socket socket = server.accept(); final Socket osSocket = interceptor.getConnection().getSocket(); Runnable writer = new Runnable() { public void run() { int x; // write to OpenShift try (InputStream input = socket.getInputStream()) { while ((x = input.read()) != -1) { osSocket.getOutputStream().write(x); } } catch (IOException ignored) { } } }; new Thread(writer).start(); Runnable reader = new Runnable() { public void run() { int x; // read from OpenShift try (OutputStream output = socket.getOutputStream()) { InputStream osInput = osSocket.getInputStream(); while ((x = osInput.read()) != -1) { output.write(x); } } catch (IOException ignored) { } } }; new Thread(reader).start(); } catch (IOException e) { log.warning("Error: " + e.getMessage()); } } } }; new Thread(runnable).start(); return new Handle() { public InetAddress getInetAddress() { return server.getInetAddress(); } public void close() throws IOException { doClose(server); doClose(interceptor.getConnection().getSocket()); } }; }