本文整理汇总了Java中ca.nrc.cadc.net.NetUtil类的典型用法代码示例。如果您正苦于以下问题:Java NetUtil类的具体用法?Java NetUtil怎么用?Java NetUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NetUtil类属于ca.nrc.cadc.net包,在下文中一共展示了NetUtil类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteObservation
import ca.nrc.cadc.net.NetUtil; //导入依赖的package包/类
protected void deleteObservation(String uri, Subject subject, Integer expectedResponse, String expectedMessage)
throws Exception {
log.debug("start delete on " + uri);
// extract the path from the uri
String urlPath = uri.substring(uri.indexOf(SCHEME) + SCHEME.length());
HttpURLConnection conn = openConnection(subject, urlPath);
conn.setRequestMethod("DELETE");
int response = conn.getResponseCode();
String message = conn.getResponseMessage();
if (response != 200) {
message = NetUtil.getErrorBody(conn).trim();
}
log.debug("delete response: " + message + " (" + response + ")");
if (expectedResponse != null) {
Assert.assertEquals("Wrong response", expectedResponse.intValue(), response);
}
if (expectedMessage != null) {
Assert.assertNotNull(message);
Assert.assertEquals("Wrong response message", expectedMessage, message);
}
conn.disconnect();
}
示例2: testCaomPackage
import ca.nrc.cadc.net.NetUtil; //导入依赖的package包/类
@Test
public void testCaomPackage()
{
try
{
ClassLoader loader = Observation.class.getClassLoader();
String cname = Observation.class.getName();
String pname = Observation.class.getPackage().getName();
String path = cname.replace('.', '/') + ".class";
log.debug("pkg: " + pname + " class: " + cname + " -> path: " + path);
URL url = loader.getResource(path);
final File cnameFile = new File(url.getPath());
final File actual;
log.info("Observation class filepath: "
+ cnameFile.getAbsolutePath());
if (cnameFile.exists())
{
actual = cnameFile;
}
else
{
actual = new File(NetUtil.decode(cnameFile.getAbsolutePath()));
}
final File dir = actual.getParentFile();
doPackage(pname, dir);
}
catch(Exception unexpected)
{
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
示例3: sendObservation
import ca.nrc.cadc.net.NetUtil; //导入依赖的package包/类
protected void sendObservation(String method, final Observation observation, final Subject subject, Integer expectedResponse, String expectedMessage,
String path)
throws Exception {
log.debug("start " + method.toLowerCase() + " on " + observation.toString());
String urlPath = path;
if (urlPath == null) {
// extract the path from the observation
urlPath = observation.getURI().getURI().getSchemeSpecificPart();
}
HttpURLConnection conn = openConnection(subject, urlPath);
conn.setRequestMethod(method);
conn.setRequestProperty("Content-Type", TEXT_XML);
OutputStream out = conn.getOutputStream();
log.debug("write: " + observation);
ByteCountOutputStream bcos = new ByteCountOutputStream(out);
ObservationWriter writer = new ObservationWriter();
writer.write(observation, bcos);
log.debug(" wrote: " + bcos.getByteCount() + " bytes");
int response = -1;
try {
log.debug("getResponseCode()");
response = conn.getResponseCode();
log.debug("getResponseCode() returned " + response);
} catch (IOException ex) {
if (expectedResponse != null && expectedResponse == 413) {
log.warn("expected 413 and getResponseCode() threw " + ex + ": known issue in JDK http lib");
}
return;
}
String message = conn.getResponseMessage();
if (response != 200) {
message = NetUtil.getErrorBody(conn).trim();
}
log.debug(method.toLowerCase() + " response: " + message + " (" + response + ")");
if (expectedResponse != null) {
Assert.assertEquals("Wrong response", expectedResponse.intValue(), response);
}
if (expectedMessage != null) {
Assert.assertNotNull(message);
if (expectedResponse != null && expectedResponse == 400) {
// service provides extra info so check the start only
message = message.substring(0, expectedMessage.length());
}
Assert.assertEquals("Wrong response message", expectedMessage, message);
}
conn.disconnect();
}
示例4: createURL
import ca.nrc.cadc.net.NetUtil; //导入依赖的package包/类
protected String createURL(URI uri) {
// Temporary: because the VOSpace client doesn't support
// cutouts through document posting, create cutout urls
// using synctrans
try {
// check if authMethod has been set
AuthMethod am = this.authMethod;
if (am == null) {
am = AuthenticationUtil.getAuthMethod(AuthenticationUtil.getCurrentSubject());
}
if (am == null) {
am = AuthMethod.ANON;
}
URI vuri = getVOSURI(uri);
RegistryClient registryClient = new RegistryClient();
URL baseURL = registryClient.getServiceURL(getServiceURI(vuri), Standards.VOSPACE_SYNC_21, am);
String scheme = baseURL.getProtocol();
String protocol = null;
if (scheme.equalsIgnoreCase("http")) {
protocol = PROTOCOL_HTTP_GET;
} else {
protocol = PROTOCOL_HTTPS_GET;
}
StringBuilder query = new StringBuilder();
query.append(baseURL);
query.append("?");
query.append("TARGET=").append(NetUtil.encode(vuri.toString()));
query.append("&");
query.append("DIRECTION=").append(NetUtil.encode(pullFromVoSpaceValue));
query.append("&");
query.append("PROTOCOL=").append(NetUtil.encode(protocol));
return query.toString();
} catch (Throwable t) {
throw new RuntimeException("failed to convert " + uri, t);
}
}