public HTTPProviderFactory(Class<CredentialsProvider> pclass) throws HTTPException { this.providerclass = pclass; if(pclass != null) try { this.constructor = pclass.getConstructor(AuthScope.class); } catch (NoSuchMethodException | SecurityException e) { throw new HTTPException("HTTPProviderFactory: no proper constructor available", e); } }
public void setRequestHeader(Header h) throws HTTPException { try { headers.add(h); } catch (Exception e) { throw new HTTPException("cause", e); } }
private void acquirereadaccess() throws HTTPException { nreaders++; while(nwriters > 0) { try { wait(); } catch (InterruptedException e) { if(stop) throw new HTTPException("interrupted"); } } }
public void setMethodHeaders(List<Header> headers) throws HTTPException { try { for(Header h : headers) { this.headers.add(h); } } catch (Exception e) { throw new HTTPException(e); } }
static URI decompose(String suri) throws HTTPException { try { URI uri = new URI(suri); return uri; } catch (URISyntaxException use) { throw new HTTPException("HTTPAuthScope: illegal url: " + suri); } }
public CredentialsProvider getProvider(AuthScope scope) throws HTTPException { if(this.providerclass == null) return null; else try { CredentialsProvider cp = this.constructor.newInstance(scope); return cp; } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new HTTPException("HTTPProvider Factory failure", e); } } }
private void acquirewriteaccess() throws HTTPException { nwriters++; while(nwriters > 1) { try { wait(); } catch (InterruptedException e) { if(stop) throw new HTTPException("interrupted"); } } while(nreaders > 0) { try { wait(); } catch (InterruptedException e) { if(stop) throw new HTTPException("interrupted"); } } }
@Deprecated protected HTTPMethod setRequestHeader(Header h) throws HTTPException { try { this.headers.put(h.getName(), h.getValue()); } catch (Exception e) { throw new HTTPException("cause", e); } return this; }
@Deprecated public HTTPMethod setMethodHeaders(List<Header> headers) throws HTTPException { try { for(Header h : headers) { this.headers.put(h.getName(), h.getValue()); } } catch (Exception e) { throw new HTTPException(e); } return this; }
static protected List<Entry> // public to allow testing getDeserializedEntries(ObjectInputStream ois) throws HTTPException { try { List<Entry> entries = new ArrayList<Entry>(); int count = ois.readInt(); for(int i = 0; i < count; i++) { Entry e = (Entry) ois.readObject(); entries.add(e); } return entries; } catch (Exception e) { throw new HTTPException(e); } }
/** * Create a request, add headers, and content, * then send to HTTPSession to do the bulk of the work. * * @return statuscode */ public int execute() throws HTTPException { HttpResponse res = executeRaw(); if(res != null) return res.getStatusLine().getStatusCode(); else throw new HTTPException("HTTPMethod.execute: null response"); }
public HTTPSession(String url) throws HTTPException { try { new URL(url); } catch (MalformedURLException mue) { throw new HTTPException("Malformed URL: " + url, mue); } this.legalurl = url; try { synchronized (HTTPSession.class) { sessionClient = new DefaultHttpClient(connmgr); } if(TESTING) HTTPSession.track(this); setInterceptors(); } catch (Exception e) { throw new HTTPException("url=" + url, e); } this.execcontext = new BasicHttpContext();// do we need to modify? }
/** * @param entry * @return old entry if entry existed and was removed */ synchronized public Entry remove(Entry entry) throws HTTPException { Entry found = null; if(entry == null) throw new HTTPException("HTTPAuthStore.remove: invalid entry: " + entry); for(Entry e : rows) { if(equivalent(e, entry)) { found = e; break; } } if(found != null) rows.remove(found); return (found); }
static public ObjectInputStream // public to allow testing openobjectstream(InputStream istream, String password) throws HTTPException { try { // Create Key byte key[] = password.getBytes(Escape.utf8Charset); DESKeySpec desKeySpec = new DESKeySpec(key); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey secretKey = keyFactory.generateSecret(desKeySpec); // Create Cipher //Coverity[RISKY_CRYPTO] Cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.DECRYPT_MODE, secretKey); // Create crypto stream BufferedInputStream bis = new BufferedInputStream(istream); CipherInputStream cis = new CipherInputStream(bis, desCipher); ObjectInputStream ois = new ObjectInputStream(cis); return ois; } catch (Exception e) { throw new HTTPException(e); } }
static AuthScope uriToAuthScope(String surl) throws HTTPException { try { URI uri = HTTPUtil.parseToURI(surl); return uriToAuthScope(uri); } catch (URISyntaxException e) { throw new HTTPException(e); } }
static int putUrlAsString(String content, String url) throws HTTPException { int status = 0; try { try (HTTPMethod m = HTTPFactory.Put(url)) { m.setRequestContent(new StringEntity(content, ContentType.create("application/text", "UTF-8"))); status = m.execute(); } } catch (UnsupportedCharsetException uce) { throw new HTTPException(uce); } return status; }
static public int putUrlAsString(String content, String url) throws HTTPException { int status = 0; try { try (HTTPMethod m = HTTPFactory.Put(url);) { m.setRequestContent(new StringEntity(content, "application/text", "UTF-8")); status = m.execute(); } } catch (UnsupportedEncodingException uee) { throw new HTTPException(uee); } return status; }
static URI authscopeToURI(AuthScope authScope) throws HTTPException { try { URI url = new URI(authScope.getScheme(), null, authScope.getHost(), authScope.getPort(), "", null, null); return url; } catch (URISyntaxException mue) { throw new HTTPException(mue); } }
protected HttpRequestBase buildRequest(RequestBuilder rb, Map<Prop, Object> settings) throws HTTPException { HttpRequestBase req; RequestConfig config = buildRequestConfig(settings); rb.setConfig(config); req = (HttpRequestBase) rb.build(); if(req == null) throw new HTTPException("HTTPMethod.buildrequest: requestbuilder failed"); return req; }
public HTTPMethod(HTTPSession.Methods m, HTTPSession session, String url) throws HTTPException { if(url == null && session != null) url = session.getURL(); try { new URL(url); } catch (MalformedURLException mue) { throw new HTTPException("Malformed URL: " + url, mue); } if(session == null) { session = HTTPFactory.newSession(url); localsession = true; } this.session = session; url = HTTPSession.removeprincipal(url); this.legalurl = url; this.session.addMethod(this); this.methodclass = m; }