List of usage examples for java.net MalformedURLException getLocalizedMessage
public String getLocalizedMessage()
From source file:eu.codeplumbers.cosi.api.tasks.UnregisterDeviceTask.java
@Override protected String doInBackground(Void... voids) { URL urlO = null;//from www . jav a 2 s.co m try { urlO = new URL(url + Device.registeredDevice().getLogin()); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(false); conn.setDoInput(true); conn.setRequestMethod("DELETE"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); if (result == "") { Device.registeredDevice().delete(); new Delete().from(Call.class).execute(); new Delete().from(Note.class).execute(); new Delete().from(Sms.class).execute(); new Delete().from(Place.class).execute(); new Delete().from(File.class).execute(); errorMessage = ""; } else { errorMessage = result; } in.close(); conn.disconnect(); } catch (MalformedURLException e) { errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { errorMessage = e.getLocalizedMessage(); } catch (IOException e) { errorMessage = e.getLocalizedMessage(); } return errorMessage; }
From source file:net.sourceforge.mavenhippo.AbstractHippoMojo.java
protected ClassLoader getProjectClassloader() throws MojoExecutionException { try {// w ww . j a va 2s .c o m if (projectClassloader == null) { Set<Artifact> artifacts = project.getArtifacts(); List<URL> urls = new ArrayList<URL>(); for (Artifact artifact : artifacts) { urls.add(artifact.getFile().toURI().toURL()); } if (getLog().isDebugEnabled()) { for (URL url : urls) { getLog().debug("Project dependency URL: " + url.toString()); } } projectClassloader = new URLClassLoader(urls.toArray(new URL[0]), this.getClass().getClassLoader()); } return projectClassloader; } catch (MalformedURLException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:com.markuspage.jbinrepoproxy.standalone.transport.sun.URLConnectionTransportClientImpl.java
@Override public TransportFetch httpGetOtherFile(String uri) { TransportFetch result;//from w w w .ja va 2s . co m try { final URL url = new URL(serverURL + uri); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setAllowUserInteraction(false); final int responseCode = conn.getResponseCode(); final String responseMessage = conn.getResponseMessage(); InputStream responseIn = conn.getErrorStream(); if (responseIn == null) { responseIn = conn.getInputStream(); } // Read the body to the output if OK otherwise to the error message final byte[] body = IOUtils.toByteArray(responseIn); result = new TransportFetch(responseCode, responseMessage, body); } catch (MalformedURLException ex) { LOG.error("Malformed URL", ex); result = new TransportFetch(500, ex.getLocalizedMessage(), null); } catch (IOException ex) { LOG.error("IO error", ex); result = new TransportFetch(500, ex.getLocalizedMessage(), null); } return result; }
From source file:com.markuspage.jbinrepoproxy.standalone.transport.sun.URLConnectionTransportClientImpl.java
@Override public TransportFetch httpGetTheFile() { TransportFetch result;/*from ww w. j a va 2 s. c om*/ try { final URL url = new URL(serverURL + theFileURI); final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setAllowUserInteraction(false); final int responseCode = conn.getResponseCode(); final String responseMessage = conn.getResponseMessage(); InputStream responseIn = conn.getErrorStream(); if (responseIn == null) { responseIn = conn.getInputStream(); } // Read the body to the output if OK otherwise to the error message final byte[] body = IOUtils.toByteArray(responseIn); this.targetResponse = new TargetResponse(responseCode, conn.getHeaderFields(), body); result = new TransportFetch(responseCode, responseMessage, body); } catch (MalformedURLException ex) { LOG.error("Malformed URL", ex); result = new TransportFetch(500, ex.getLocalizedMessage(), null); } catch (IOException ex) { LOG.error("IO error", ex); result = new TransportFetch(500, ex.getLocalizedMessage(), null); } return result; }
From source file:org.kuali.mobility.events.dao.EventsDaoUMImpl.java
public List<Event> loadEventsForCategory(final String campus, final String categoryId) { LOG.debug("Loading event feed for category " + categoryId); if (null == getEvents() || getEvents().isEmpty()) { LOG.debug("Events list was empty, creating a new one."); //setEvents( new ArrayList<Event>() ); }//from ww w. j av a 2 s .c o m if (null == getCategories() || getCategories().isEmpty()) { LOG.debug("Category list was empty, initializing a new one."); initData(campus); } List<Event> newEvents = new ArrayList<Event>(); Category category = (Category) CollectionUtils.find(getCategories(), new CategoryPredicate(campus, categoryId)); ; if (category != null) { LOG.debug("Found category object for id " + categoryId); XStream xstream = new XStream(); xstream.processAnnotations(UMEventReader.class); xstream.processAnnotations(UMEvent.class); xstream.processAnnotations(UMSponsor.class); UMEventReader eventReader = null; try { URL url = new URL(category.getUrlString() + "&_type=xml"); LOG.debug("Mapping events from url: " + category.getUrlString()); if (url != null) { eventReader = (UMEventReader) xstream.fromXML(url); } } catch (MalformedURLException mue) { LOG.error(mue.getLocalizedMessage()); } LOG.debug("check eventReader " + (eventReader == null ? "null" : "mnot null")); LOG.debug("check eventReader.getEvents " + (eventReader.getEvents() == null ? "null" : "mnot null")); if (eventReader != null && eventReader.getEvents() != null) { for (UMEvent e : eventReader.getEvents()) { LOG.debug("processing e " + e.getTitle()); Event newEvent = (Event) getApplicationContext().getBean("event"); newEvent.setEventId(e.getId()); newEvent.setCategory(category); newEvent.setTitle(e.getTitle()); newEvent.setDisplayStartTime(e.getTimeBegin()); //Saket's Addition newEvent.setType(e.getType()); newEvent.setDisplayStartDate(e.getDateBegin()); newEvent.setLocation(e.getBuildingName()); newEvent.setLink(e.getUrl()); try { if (e.getTsBegin() != null && e.getTsBegin().isEmpty() == false) { newEvent.setStartDate(sdf.parse(e.getTsBegin())); } if (e.getTsEnd() != null && e.getTsEnd().isEmpty() == false) { newEvent.setEndDate(sdf.parse(e.getTsEnd())); } } catch (ParseException e1) { LOG.error(e1.getLocalizedMessage()); } newEvent.setDisplayEndTime(e.getTimeEnd()); newEvent.setDisplayEndDate(e.getDateEnd()); List<String> myDescription = new ArrayList<String>(); myDescription.add(e.getDescription()); newEvent.setDescription(myDescription); List<EventContact> myContacts = new ArrayList<EventContact>(); for (UMSponsor f : e.getSponsors()) { EventContact newContact = (EventContact) getApplicationContext().getBean("eventContact"); newContact.setName(f.getGroupName()); newContact.setUrl(f.getWebsite()); myContacts.add(newContact); } newEvent.setContact(myContacts); LOG.debug("CONTACT " + newEvent.getContact()); newEvents.add(newEvent); } } } return (newEvents); }
From source file:eu.codeplumbers.cosi.api.tasks.RegisterDeviceTask.java
@Override protected Device doInBackground(Void... voids) { URL urlO = null;//from w w w . ja v a 2 s. co m try { urlO = new URL(url); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod("POST"); OutputStream os = conn.getOutputStream(); os.write(deviceString.getBytes("UTF-8")); os.flush(); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONObject jsonObject = new JSONObject(result); if (jsonObject != null) { if (jsonObject.has("login")) { resultDevice = new Device(); resultDevice.setUrl(url.replace("/device/", "")); //Log.d(getClass().getName(), "Token="+jsonObject.getString("login")); resultDevice.setLogin(jsonObject.getString("login")); resultDevice.setPassword(jsonObject.getString("password")); resultDevice.setPermissions(jsonObject.getString("permissions")); resultDevice.setFirstSyncDone(false); resultDevice.setSyncCalls(false); resultDevice.setSyncContacts(false); resultDevice.setSyncFiles(false); resultDevice.setSyncNotes(false); resultDevice.save(); } else { errorMessage = jsonObject.getString("error"); } } in.close(); conn.disconnect(); } catch (MalformedURLException e) { errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { errorMessage = e.getLocalizedMessage(); } catch (IOException e) { errorMessage = e.getLocalizedMessage(); } catch (JSONException e) { errorMessage = e.getLocalizedMessage(); } return resultDevice; }
From source file:eu.codeplumbers.cosi.api.tasks.DeleteFileTask.java
private String deleteFileRequest(File file) { String result = ""; URL urlO = null;/*from w ww . j a va 2 s. c o m*/ try { urlO = new URL(url + file.getRemoteId() + "/"); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(false); conn.setDoInput(true); conn.setRequestMethod("DELETE"); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); result = writer.toString(); in.close(); conn.disconnect(); } catch (MalformedURLException e) { result = e.getLocalizedMessage(); } catch (ProtocolException e) { result = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { result = e.getLocalizedMessage(); } return result; }
From source file:eu.codeplumbers.cosi.api.tasks.DeleteDocumentTask.java
@Override protected String doInBackground(Void... voids) { URL urlO = null;// w ww. ja v a 2s. c o m try { urlO = new URL(url + remoteId + "/"); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(false); conn.setDoInput(true); conn.setRequestMethod("DELETE"); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); result = writer.toString(); in.close(); conn.disconnect(); } catch (MalformedURLException e) { result = "error"; e.printStackTrace(); errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } return result; }
From source file:uk.ac.ox.oucs.vle.SearchServiceImpl.java
@Override public SearchResultsWrapper select(String query) throws IOException { HttpURLConnection connection = null; try {//from w w w . j a va 2s. co m URL serverAddress = new URL(getSolrUrl() + "select?" + query); connection = (HttpURLConnection) serverAddress.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.connect(); } catch (MalformedURLException e) { log.error(e.getLocalizedMessage()); } return new SearchResultsWrapper(connection); }
From source file:org.geoserver.geofence.gui.server.service.impl.WorkspacesManagerServiceImpl.java
public PagingLoadResult<WorkspaceModel> getWorkspaces(int offset, int limit, String remoteURL, GSInstanceModel gsInstance) throws ApplicationException { List<WorkspaceModel> workspacesListDTO = new ArrayList<WorkspaceModel>(); workspacesListDTO.add(new WorkspaceModel("*")); if ((remoteURL != null) && !remoteURL.equals("*") && !remoteURL.contains("?")) { try {//from w w w. j av a 2s .c o m GeoServerRESTReader gsreader = new GeoServerRESTReader(remoteURL, gsInstance.getUsername(), gsInstance.getPassword()); RESTWorkspaceList workspaces = gsreader.getWorkspaces(); if ((workspaces != null) && !workspaces.isEmpty()) { Iterator<RESTShortWorkspace> wkIT = workspaces.iterator(); while (wkIT.hasNext()) { RESTShortWorkspace workspace = wkIT.next(); workspacesListDTO.add(new WorkspaceModel(workspace.getName())); } } } catch (MalformedURLException e) { logger.error(e.getLocalizedMessage(), e); throw new ApplicationException(e.getLocalizedMessage(), e); } } return new RpcPageLoadResult<WorkspaceModel>(workspacesListDTO, 0, workspacesListDTO.size()); }