本文整理汇总了Java中org.eclipse.jetty.util.B64Code.encode方法的典型用法代码示例。如果您正苦于以下问题:Java B64Code.encode方法的具体用法?Java B64Code.encode怎么用?Java B64Code.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.util.B64Code
的用法示例。
在下文中一共展示了B64Code.encode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWeakETag
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
public String getWeakETag()
{
try
{
StringBuilder b = new StringBuilder(32);
b.append("W/\"");
String name=getName();
int length=name.length();
long lhash=0;
for (int i=0; i<length;i++)
lhash=31*lhash+name.charAt(i);
B64Code.encode(lastModified()^lhash,b);
B64Code.encode(length()^lhash,b);
b.append('"');
return b.toString();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
示例2: HostedGraphiteSender
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
public HostedGraphiteSender(String apiKey) {
source = Util.source();
// Create an https capable http client.
SslContextFactory sslContextFactory = new SslContextFactory();
httpClient = new HttpClient(sslContextFactory);
HttpField agent = new HttpField("User-Agent", "app-server-metrics/" +
(getClass().getPackage().getImplementationVersion() != null ? getClass().getPackage().getImplementationVersion() : "development"));
httpClient.setUserAgentField(agent);
try {
httpClient.start();
} catch (Exception e) {
log.error(e);
}
this.authHeader = "Basic " + B64Code.encode(apiKey);
}
示例3: hashKey
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
public static String hashKey(String key)
{
try
{
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(key.getBytes("UTF-8"));
md.update(MAGIC);
return new String(B64Code.encode(md.digest()));
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
示例4: getUrl
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
/**
* Simple logic to perform a authenticated GET request
*
* @param url
* @param timeout
* @return
*/
private String getUrl(String url, int timeout) {
url += (url.contains("?") ? "&" : "?") + "timestamp=" + System.currentTimeMillis();
startHttpClient(client);
Request request = client.newRequest(url).timeout(TIMEOUT, TimeUnit.MILLISECONDS);
AutelisConfiguration configuration = getConfig().as(AutelisConfiguration.class);
String user = configuration.user;
String password = configuration.password;
String basicAuthentication = "Basic " + B64Code.encode(user + ":" + password, StringUtil.__ISO_8859_1);
request.header(HttpHeader.AUTHORIZATION, basicAuthentication);
try {
ContentResponse response = request.send();
int statusCode = response.getStatus();
if (statusCode != HttpStatus.OK_200) {
logger.debug("Method failed: {}", response.getStatus() + " " + response.getReason());
return null;
}
return response.getContentAsString();
} catch (Exception e) {
logger.debug("Could not make http connection", e);
}
return null;
}
示例5: setupServer
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
@BeforeClass
public static void setupServer() throws Exception {
// start a local HTTP proxy using Jetty server
server = new Server();
/*
final SSLContextParameters contextParameters = new SSLContextParameters();
final SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(contextParameters.createSSLContext());
ServerConnector connector = new ServerConnector(server, sslContextFactory);
*/
ServerConnector connector = new ServerConnector(server);
connector.setHost(HTTP_PROXY_HOST);
server.addConnector(connector);
final String authenticationString = "Basic "
+ B64Code.encode(HTTP_PROXY_USER_NAME + ":" + HTTP_PROXY_PASSWORD, StringUtil.__ISO_8859_1);
ConnectHandler connectHandler = new ConnectHandler() {
@Override
protected boolean handleAuthentication(HttpServletRequest request, HttpServletResponse response, String address) {
// validate proxy-authentication header
final String header = request.getHeader(PROXY_AUTHORIZATION.toString());
if (!authenticationString.equals(header)) {
LOG.warn("Missing header " + PROXY_AUTHORIZATION);
// ask for authentication header
response.setHeader(PROXY_AUTHENTICATE.toString(), String.format("Basic realm=\"%s\"", HTTP_PROXY_REALM));
return false;
}
LOG.info("Request contains required header " + PROXY_AUTHORIZATION);
return true;
}
};
server.setHandler(connectHandler);
LOG.info("Starting proxy server...");
server.start();
httpProxyPort = connector.getLocalPort();
LOG.info("Started proxy server on port {}", httpProxyPort);
}
示例6: toBasicAuth
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
public String toBasicAuth() {
return "Basic " + B64Code.encode(_user + ":" + _password);
}
示例7: getUsernameAndPassEncoded
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
protected static String getUsernameAndPassEncoded() {
return "Basic " + B64Code.encode("cash1981" + ":" + "foo", StringUtil.__ISO_8859_1);
}
示例8: getAdminEncoded
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
protected static String getAdminEncoded() {
return "Basic " + B64Code.encode("admin" + ":" + "foo", StringUtil.__ISO_8859_1);
}
示例9: getItchiEncoded
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
protected static String getItchiEncoded() {
return "Basic " + B64Code.encode("Itchi" + ":" + "foo", StringUtil.__ISO_8859_1);
}
示例10: getValue
import org.eclipse.jetty.util.B64Code; //导入方法依赖的package包/类
private final String getValue(String user, String password) {
String encoding = StringUtil.__ISO_8859_1;
String value = "Basic " + B64Code.encode(user + ":" + password, encoding);
return value;
}