@Override public void chatLinkClicked(URI url) { String action = url.getPath(); if (action.equals("/SHOWPREVIEW")) { enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true)); enableReplacementProposal.setSelected( cfg.getBoolean(ReplacementProperty.REPLACEMENT_PROPOSAL, true)); currentMessageID = url.getQuery(); currentLinkPosition = url.getFragment(); this.setVisible(true); this.setLocationRelativeTo(chatPanel); } }
public void setLibrary(URI url) throws Exception { if (url == null) url = new URI("http://repo.jpm4j.org/"); this.host = new URLClient(url.toString()); host.setReporter(reporter); library = JSONRPCProxy.createRPC(JpmRepo.class, host, "jpm"); }
void put(final URI uri, ArtifactData data) throws Exception { reporter.trace("put %s %s", uri, data); File tmp = createTempFile(repoDir, "mtp", ".whatever"); tmp.deleteOnExit(); try { copy(uri.toURL(), tmp); byte[] sha = SHA1.digest(tmp).digest(); reporter.trace("SHA %s %s", uri, Hex.toHexString(sha)); ArtifactData existing = get(sha); if (existing != null) { reporter.trace("existing"); xcopy(existing, data); return; } File meta = new File(repoDir, Hex.toHexString(sha) + ".json"); File file = new File(repoDir, Hex.toHexString(sha)); rename(tmp, file); reporter.trace("file %s", file); data.file = file.getAbsolutePath(); data.sha = sha; data.busy = false; CommandData cmddata = parseCommandData(data); if (cmddata.bsn != null) { data.name = cmddata.bsn + "-" + cmddata.version; } else data.name = Strings.display(cmddata.title, cmddata.bsn, cmddata.name, uri); codec.enc().to(meta).put(data); reporter.trace("TD = " + data); } finally { tmp.delete(); reporter.trace("puted %s %s", uri, data); } }
@Override public HTTPResponse call() throws Exception { final HttpURLConnection hc = (HttpURLConnection) uri.toURL().openConnection(); try { hc.setDoOutput(true); hc.setRequestMethod(method.name()); hc.setRequestProperty(MimeTypes.CONTENT_TYPE, MimeTypes.APP_XML); hc.getOutputStream().write(content); hc.getOutputStream().close(); hc.setReadTimeout(SOCKET_TIMEOUT); while (!stop) { try { return new HTTPResponse(hc.getResponseCode()); } catch (final SocketTimeoutException e) { } } return null; } finally { hc.disconnect(); } }
@Override public HTTPResponse call() throws Exception { final HttpURLConnection hc = (HttpURLConnection) uri.toURL().openConnection(); hc.setReadTimeout(SOCKET_TIMEOUT); try { while (!stop) { try { final int code = hc.getResponseCode(); final InputStream input = hc.getInputStream(); final ByteList bl = new ByteList(); for (int i; (i = input.read()) != -1; ) bl.add(i); return new HTTPResponse(code, bl.toString()); } catch (final SocketTimeoutException e) { } } return null; } finally { hc.disconnect(); } }
/** * Construct a new request. * * @param request request string without the base URI * @param data data to send to the server * @param m HTTP method */ protected Put(final String request, final byte[] data, final HTTPMethod m) { uri = URI.create(BASE_URL + request); content = data; method = m; }
/** * Construct a new GET request. * * @param request request string without the base URI */ public Get(final String request) { uri = URI.create(BASE_URL + request); }