下面列出了java.net.MalformedURLException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void postNewReview(String title, String body, int reviewRating) {
if (!isNetworkAvailable()) {
showToast("Network Not Available");
return;
}
showProgressDialog();
HashMap<String, Object> parameters = new HashMap();
parameters.put(LFSConstants.LFSPostBodyKey, body);
parameters.put(LFSConstants.LFSPostTitleKey, title);
parameters.put(LFSConstants.LFSPostTypeReview, reviewRating);
parameters
.put(LFSConstants.LFSPostType, LFSConstants.LFSPostTypeReview);
parameters.put(LFSConstants.LFSPostUserTokenKey, LFSConfig.USER_TOKEN);
if (imgObj != null)
parameters.put(LFSConstants.LFSPostAttachment,
(new JSONArray().put(imgObj)).toString());
try {
WriteClient.postContent(
LFSConfig.COLLECTION_ID, null, LFSConfig.USER_TOKEN,
parameters, new writeclientCallback());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/**
* Test method for {@link
* com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#initialise(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgressInterface,
* com.sldeditor.common.data.GeoServerConnection)}. Test method for {@link
* com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#connect()}.
*/
@Test
public void testInitialiseWithInvalidConnection() {
GeoServerClient client = new GeoServerClient();
GeoServerConnection invalidTestConnection = new GeoServerConnection();
invalidTestConnection.setConnectionName("Invalid Test Connection");
try {
invalidTestConnection.setUrl(new URL("http://invalid.url.com"));
} catch (MalformedURLException e) {
e.printStackTrace();
fail(e.getMessage());
}
client.initialise(null, invalidTestConnection);
assertFalse(client.connect());
assertEquals(invalidTestConnection, client.getConnection());
}
private List<WebDavFile> parseDir(String s) {
List<WebDavFile> list = new ArrayList<>();
Document document = Jsoup.parse(s);
Elements elements = document.getElementsByTag("d:response");
String baseUrl = getUrl().endsWith("/") ? getUrl() : getUrl() + "/";
for (Element element : elements) {
String href = element.getElementsByTag("d:href").get(0).text();
if (!href.endsWith("/")) {
String fileName = href.substring(href.lastIndexOf("/") + 1);
WebDavFile webDavFile;
try {
webDavFile = new WebDavFile(baseUrl + fileName);
webDavFile.setDisplayName(fileName);
webDavFile.setUrlName(href);
list.add(webDavFile);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
return list;
}
@Override
public void actionPerformed(ActionEvent evt) {
XJFileChooser fileChooser = MainFrame.getFileChooser();
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.setDialogTitle("Choose a BDM file");
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setResource(
CorpusQualityAssurance.class.getName() + ".BDMfile");
int res = fileChooser.showOpenDialog(CorpusQualityAssurance.this);
if (res != JFileChooser.APPROVE_OPTION) { return; }
try {
bdmFileUrl = fileChooser.getSelectedFile().toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/**
* Builds the URL used to talk to the weather server using latitude and longitude of a
* location.
*
* @param latitude The latitude of the location
* @param longitude The longitude of the location
* @return The Url to use to query the weather server.
*/
private static URL buildUrlWithLatitudeLongitude(Double latitude, Double longitude) {
Uri weatherQueryUri = Uri.parse(FORECAST_BASE_URL).buildUpon()
.appendQueryParameter(LAT_PARAM, String.valueOf(latitude))
.appendQueryParameter(LON_PARAM, String.valueOf(longitude))
.appendQueryParameter(FORMAT_PARAM, format)
.appendQueryParameter(UNITS_PARAM, units)
.appendQueryParameter(DAYS_PARAM, Integer.toString(numDays))
.build();
try {
URL weatherQueryUrl = new URL(weatherQueryUri.toString());
Log.v(TAG, "URL: " + weatherQueryUrl);
return weatherQueryUrl;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
private String getNS(LDAPReferralException ref) {
String refURL = ref.getReferrals()[0];
LDAPUrl url;
try {
url = new LDAPUrl(refURL);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
String ns = this.hostToNS.get(url.getHost() + ":" + url.getPort());
return ns;
}
public static void main(String[] args) {
String[] urls = {"iiop://[::1]:2809",
"iiop://[::1]",
"iiop://:2890",
"iiop://129.158.2.2:80"
};
for (int u = 0; u < urls.length; u++) {
try {
IiopUrl url = new IiopUrl(urls[u]);
Vector addrs = url.getAddresses();
for (int i = 0; i < addrs.size(); i++) {
Address addr = (Address)addrs.elementAt(i);
System.out.println("================");
System.out.println("url: " + urls[u]);
System.out.println("host: " + addr.host);
System.out.println("port: " + addr.port);
System.out.println("version: " + addr.major
+ " " + addr.minor);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
URL[] urlsa = new URL[1];
URL[] urlsb = new URL[1];
try {
String testDir = System.getProperty("test.classes", ".");
String sep = System.getProperty("file.separator");
urlsa[0] = new URL("file://" + testDir + sep + "SA" + sep);
urlsb[0] = new URL("file://" + testDir + sep + "SB" + sep);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// Set up Classloader delegation hierarchy
saLoader = new DelegatingLoader(urlsa);
sbLoader = new DelegatingLoader(urlsb);
String[] saClasses = { "comSA.SupBob", "comSA.Alice" };
String[] sbClasses = { "comSB.SupAlice", "comSB.Bob" };
saLoader.setDelegate(sbClasses, sbLoader);
sbLoader.setDelegate(saClasses, saLoader);
// test one-way delegate
String testType = args[0];
if (testType.equals("one-way")) {
test("comSA.Alice", "comSA.SupBob");
} else if (testType.equals("cross")) {
// test cross delegate
test("comSA.Alice", "comSB.Bob");
} else {
System.out.println("ERROR: unsupported - " + testType);
}
}
public void testLookupDeserializesUpdateAtToDate() throws Throwable {
final String responseContent = "{\"id\":\"an id\",\"updatedAt\":\"2000-01-01T07:59:59.000Z\"}";
MobileServiceClient client = null;
try {
client = new MobileServiceClient(appUrl, getInstrumentation().getTargetContext());
} catch (MalformedURLException e) {
e.printStackTrace();
}
// Add a filter to handle the request and create a new json
// object with an id defined
client = client.withFilter(getTestFilter(responseContent));
// Create get the MobileService table
MobileServiceTable<UpdatedAtType> msTable = client.getTable(UpdatedAtType.class);
try {
// Call the lookUp method
UpdatedAtType entity = msTable.lookUp("an id").get();
// Asserts
if (entity == null) {
fail("Expected result");
} else {
assertTrue(entity instanceof UpdatedAtType);
GregorianCalendar calendar = new GregorianCalendar(2000, 00, 01, 07, 59, 59);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
assertEquals("an id", entity.Id);
assertEquals(calendar.getTime(), entity.UpdatedAt);
}
} catch (Exception exception) {
fail(exception.getMessage());
}
}
@Override
public Resource loadAsResource(String keyName) {
try {
URL url = new URL(getBaseUrl() + keyName);
Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
public OperaUser(String userName, int timeOfWaitInSeconds) {
super(userName, timeOfWaitInSeconds);
OperaOptions options = new OperaOptions();
options.setBinary("/usr/bin/opera");
DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();
capabilities.setAcceptInsecureCerts(true);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
options.addArguments("--use-fake-ui-for-media-stream");
options.addArguments("--use-fake-device-for-media-stream");
capabilities.setCapability(OperaOptions.CAPABILITY, options);
String REMOTE_URL = System.getProperty("REMOTE_URL_OPERA");
if (REMOTE_URL != null) {
log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
try {
this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
log.info("Using local web driver");
this.driver = new OperaDriver(capabilities);
}
this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
this.configureDriver();
}
public TextureURL(String url)
{
this.textureID = -1;
try
{
this.url = new URL(StringReplacer.replacePlaceholders(url));
}
catch (MalformedURLException e)
{
CustomMainMenu.INSTANCE.logger.log(Level.ERROR, "Invalid URL: " + url);
e.printStackTrace();
}
new LoadTextureURL(this).start();
}
private GlideUrl buildGlideUrl(String url) {
if (TextUtils.isEmpty(url)) {
return null;
} else {
String referer = null;
String host = null;
try {
URL urlObj = new URL(url);
host = urlObj.getHost();
referer = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
} catch (MalformedURLException e) {
e.printStackTrace();
}
LazyHeaders.Builder builder = new LazyHeaders.Builder()
.addHeader("Accept-Language", "zh-CN,zh;q=0.9,zh-TW;q=0.8")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
if (referer != null) {
builder.addHeader("Referer", referer);
builder.addHeader("Host", host);
}
return new GlideUrl(url, builder.build());
}
}
/**
* Load a text file into a String
*
* @param url The url to load file from
* @return file contents as a string
*/
public static String loadFile(String url) {
try {
return loadFile(new URL(url));
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
public static URL getUrl(MCRPIRegistrationInfo info) {
String url = "http://localhost:8291/deriv_0001/" + info.getAdditional();
try {
return new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
LOGGER.error("Malformed URL: {}", url);
}
return null;
}
public ClassPathDirEntry(Path root, Executor executor) {
super(root, executor);
try {
URL url = root.toUri().toURL();
setLoader(new URLClassLoader(new URL[]{url}));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private static void crawlPage(String url) { //recursive method
try {
URL page = new URL(url);
//Authenticator.setDefault( new MyAuthenticator()); // todo keystore/truststore pass
HttpsURLConnection http = (HttpsURLConnection)page.openConnection();
http.setAllowUserInteraction(true);
http.setRequestMethod("GET");
http.connect();
InputStream is = http.getInputStream();
Scanner s = new Scanner(is);
String temp_data = "";
while (s.hasNext()) {
temp_data += s.nextLine() + "\n";
}
s.close();
is.close();
while (temp_data.contains("class=\"monster\">")) {
String monster_section = getStringBetween(temp_data, "class=\"monster\">", "</table>");
parseMonsterSection(monster_section);
temp_data = trimUntil(temp_data, "</table>");
}
if (temp_data.contains("Go to next page")) {
String next_url_segment = getStringBetween(temp_data, "<li class=\"pager-next\"><a href=\"", "\" title=\"Go to next page");
String next_url = BASE_URL + next_url_segment;
crawlPage(next_url);
} else {
System.out.println("Finished crawling section.");
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
System.out.println("Error parsing URL: " + url);
return;
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Error reading from URL: " + ioe.getLocalizedMessage());
return;
}
}
public void load(TreeNode node) {
this.loadSong = (SongNode) node;
DefaultMutableTreeNode mutablenode = (DefaultMutableTreeNode) node;
File songFile = (File) mutablenode.getUserObject();
loadSongName = songFile.getName();
try {
audio = songFile.toURI().toURL();
this.HTTPFlag = false;
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Override
public File getImagesDirectory() {
try {
URL imagesUrl = new URL(getUrl(), "images");
File result = new File(imagesUrl.getPath());
return result;
} catch (MalformedURLException e) {
if (!GPLogger.log(e)) {
e.printStackTrace(System.err);
}
throw new RuntimeException(e);
}
}
public void testDeleteUsingIdShouldReturnTheExpectedRequestUrl() throws Throwable {
// Container to store callback's results and do the asserts.
final ResultsContainer container = new ResultsContainer();
// Object to insert
final int personId = 10;
final String tableName = "MyTableName";
MobileServiceClient client = null;
try {
client = new MobileServiceClient(appUrl, getInstrumentation().getTargetContext());
} catch (MalformedURLException e) {
e.printStackTrace();
}
// Add a filter to handle the request and create a new json
// object with an id defined
client = client.withFilter(new ServiceFilter() {
@Override
public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) {
container.setRequestUrl(request.getUrl());
// call onResponse with the mocked response
final SettableFuture<ServiceFilterResponse> resultFuture = SettableFuture.create();
resultFuture.set(new ServiceFilterResponseMock());
return resultFuture;
}
});
// Create get the MobileService table
MobileServiceJsonTable msTable = client.getTable(tableName);
// Call the delete method
try {
msTable.delete(personId).get();
Assert.assertTrue("Opperation should have succeded", true);
} catch (Exception exception) {
Assert.assertTrue("Opperation should have succeded", false);
}
assertEquals(this.appUrl + "tables/" + tableName + "/" + personId, container.getRequestUrl());
}