本文整理汇总了Java中sun.net.www.HeaderParser.findValue方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderParser.findValue方法的具体用法?Java HeaderParser.findValue怎么用?Java HeaderParser.findValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.net.www.HeaderParser
的用法示例。
在下文中一共展示了HeaderParser.findValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
static boolean check (HeaderParser p, String[][]expect) {
Iterator keys = p.keys();
Iterator vals = p.values();
boolean empty = true;
for (int j=0; keys.hasNext(); j++) {
empty = false;
String key = (String)keys.next();
String ival = (String)vals.next();
String val = p.findValue (key);
if (val == null && ival == null)
continue;
if (!val.equals(ival)) {
throw new RuntimeException ("Error " + val + "/" + ival);
}
if (!expect[j][0].equals (key)) {
throw new RuntimeException ("Error "+key+"/" + expect[j][0]);
}
if (expect[j][1] != null && !expect[j][1].equals (val)) {
throw new RuntimeException ("Error "+val+"/" + expect[j][1]);
}
}
return empty;
}
示例2: create
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
public static DigestResponse create(String raw) {
String username, realm, nonce, nc, uri, response, cnonce,
algorithm, qop, opaque;
HeaderParser parser = new HeaderParser(raw);
username = parser.findValue("username");
realm = parser.findValue("realm");
nonce = parser.findValue("nonce");
nc = parser.findValue("nc");
uri = parser.findValue("uri");
cnonce = parser.findValue("cnonce");
response = parser.findValue("response");
algorithm = parser.findValue("algorithm");
qop = parser.findValue("qop");
opaque = parser.findValue("opaque");
return new DigestResponse(realm, username, nonce, cnonce, nc, uri,
algorithm, qop, opaque, response);
}
示例3: isAuthorizationStale
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
/**
* Check if the header indicates that the current auth. parameters are stale.
* If so, then replace the relevant field with the new value
* and return true. Otherwise return false.
* returning true means the request can be retried with the same userid/password
* returning false means we have to go back to the user to ask for a new
* username password.
*/
@Override
public boolean isAuthorizationStale (String header) {
HeaderParser p = new HeaderParser (header);
String s = p.findValue ("stale");
if (s == null || !s.equals("true"))
return false;
String newNonce = p.findValue ("nonce");
if (newNonce == null || "".equals(newNonce)) {
return false;
}
params.setNonce (newNonce);
return true;
}
示例4: main
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
public static void main (String args[]) {
HeaderParser hp = new HeaderParser (test);
String r1 = hp.findValue ("nonce");
if (r1 == null || !r1.equals ("Ovqrpw==b20ff3b0ea3f3a18f1d6293331edaafdb98f5bef")) {
throw new RuntimeException ("first findValue returned wrong result: " + r1);
}
r1 = hp.findValue ("AlGoRiThm");
if (r1 == null || !r1.equals ("MD5")) {
throw new RuntimeException ("second findValue returned wrong result: " + r1);
}
}
示例5: setHeaders
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
/**
* Set header(s) on the given connection.
* @param conn The connection to apply the header(s) to
* @param p A source of header values for this connection, if needed.
* @param raw Raw header values for this connection, if needed.
* @return true if all goes well, false if no headers were set.
*/
@Override
public boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
params.setNonce (p.findValue("nonce"));
params.setOpaque (p.findValue("opaque"));
params.setQop (p.findValue("qop"));
String uri="";
String method;
if (type == PROXY_AUTHENTICATION &&
conn.tunnelState() == HttpURLConnection.TunnelState.SETUP) {
uri = HttpURLConnection.connectRequestURI(conn.getURL());
method = HTTP_CONNECT;
} else {
try {
uri = conn.getRequestURI();
} catch (IOException e) {}
method = conn.getMethod();
}
if (params.nonce == null || authMethod == null || pw == null || realm == null) {
return false;
}
if (authMethod.length() >= 1) {
// Method seems to get converted to all lower case elsewhere.
// It really does need to start with an upper case letter
// here.
authMethod = Character.toUpperCase(authMethod.charAt(0))
+ authMethod.substring(1).toLowerCase();
}
String algorithm = p.findValue("algorithm");
if (algorithm == null || "".equals(algorithm)) {
algorithm = "MD5"; // The default, accoriding to rfc2069
}
params.setAlgorithm (algorithm);
// If authQop is true, then the server is doing RFC2617 and
// has offered qop=auth. We do not support any other modes
// and if auth is not offered we fallback to the RFC2069 behavior
if (params.authQop()) {
params.setNewCnonce();
}
String value = getHeaderValueImpl (uri, method);
if (value != null) {
conn.setAuthenticationProperty(getHeaderName(), value);
return true;
} else {
return false;
}
}
示例6: checkResponse
import sun.net.www.HeaderParser; //导入方法依赖的package包/类
public void checkResponse (String header, String method, String uri)
throws IOException {
char[] passwd = pw.getPassword();
String username = pw.getUserName();
boolean qop = params.authQop();
String opaque = params.getOpaque();
String cnonce = params.cnonce;
String nonce = params.getNonce ();
String algorithm = params.getAlgorithm ();
int nccount = params.getNCCount ();
String ncstring=null;
if (header == null) {
throw new ProtocolException ("No authentication information in response");
}
if (nccount != -1) {
ncstring = Integer.toHexString (nccount).toUpperCase();
int len = ncstring.length();
if (len < 8)
ncstring = zeroPad [len] + ncstring;
}
try {
String expected = computeDigest(false, username,passwd,realm,
method, uri, nonce, cnonce, ncstring);
HeaderParser p = new HeaderParser (header);
String rspauth = p.findValue ("rspauth");
if (rspauth == null) {
throw new ProtocolException ("No digest in response");
}
if (!rspauth.equals (expected)) {
throw new ProtocolException ("Response digest invalid");
}
/* Check if there is a nextnonce field */
String nextnonce = p.findValue ("nextnonce");
if (nextnonce != null && ! "".equals(nextnonce)) {
params.setNonce (nextnonce);
}
} catch (NoSuchAlgorithmException ex) {
throw new ProtocolException ("Unsupported algorithm in response");
}
}