List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:at.sti2.spark.handler.ImpactoriumHandler.java
@Override public void invoke(Match match) throws SparkwaveHandlerException { /*/*from www . j a v a 2 s .c o m*/ * TODO Remove this. This is an ugly hack to stop Impactorium handler of sending thousands of matches regarding the same event. * ******************************************************/ long timestamp = (new Date()).getTime(); if (timestamp - twoMinutesPause < 120000) return; twoMinutesPause = timestamp; /* *****************************************************/ String baseurl = handlerProperties.getValue("baseurl"); logger.info("Invoking impactorium at base URL " + baseurl); //Define report id value String reportId = "" + (new Date()).getTime(); //HTTP PUT the info-object id HttpClient httpclient = new DefaultHttpClient(); HttpPut httpPut = new HttpPut(baseurl + "/info-object"); try { StringEntity infoObjectEntityRequest = new StringEntity( "<info-object name=\"Report " + reportId + " \"/>", "UTF-8"); httpPut.setEntity(infoObjectEntityRequest); HttpResponse response = httpclient.execute(httpPut); logger.info("[CREATING REPORT] Status code " + response.getStatusLine()); //First invocation succeeded if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity infoObjectEntityResponse = response.getEntity(); //Something has been returned, let's see what is in it if (infoObjectEntityResponse != null) { String infoObjectResponse = EntityUtils.toString(infoObjectEntityResponse); logger.debug("InfoObject response " + infoObjectResponse); //Extract info-object identifier String infoObjectReportId = extractInfoObjectIdentifier(infoObjectResponse); if (infoObjectReportId == null) { logger.error("Info object report id " + infoObjectReportId); } else { logger.info("Info object report id " + infoObjectReportId); //Format the output for the match final List<TripleCondition> conditions = handlerProperties.getTriplePatternGraph() .getConstruct().getConditions(); final String ntriplesOutput = match.outputNTriples(conditions); //HTTP PUT the data httpPut = new HttpPut(baseurl + "/info-object/" + infoObjectReportId + "/data/data.nt"); StringEntity dataEntityRequest = new StringEntity(ntriplesOutput, "UTF-8"); httpPut.setEntity(dataEntityRequest); response = httpclient.execute(httpPut); logger.info("[STORING DATA] Status code " + response.getStatusLine()); //First invocation succeeded if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)) throw new SparkwaveHandlerException("Could not write data."); } } } } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); } catch (ClientProtocolException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:bixo.fetcher.LoggingFetcher.java
@Override public FetchedDatum get(ScoredUrlDatum datum) throws BaseFetchException { String url = datum.getUrl();/*from w ww. j a v a 2s. co m*/ Payload payload = datum.getPayload(); logPayload(url, payload); // Create a simple HTML page here, where we fill in the URL as // the field, and return that as the BytesWritable. we could add // more of the datum values to the template if we cared. try { return makeFetchedDatum(url, String.format(HTML_TEMPLATE, url), payload); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Should never happen", e); } catch (MalformedURLException e) { throw new UrlFetchException(url, e.getMessage()); } }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public <T> T executeHttpAndReturn(final HttpRequestBase request, final ResponseHandlerWithError<T> handler, final Object failureMessage) throws CouchDBException { final String url = request.getURI().toString(); try {//from ww w . j ava 2s .c om final T result = client.execute(request, handler); if (result == null && handler.getError() != null) { throw handler.getError(); } return result; } catch (final UnsupportedEncodingException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final ClientProtocolException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final IOException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } finally { cleanup(request); } }
From source file:com.qut.middleware.esoe.sso.plugins.artifact.data.impl.ArtifactDaoBase.java
public void resolveArtifact(Artifact artifact) throws ArtifactBindingException { try {/*from w ww. j ava2 s.c om*/ byte[] base64MessageHandle = Base64.encodeBase64(artifact.getMessageHandle()); String messageHandle = new String(base64MessageHandle, "UTF-8"); Artifact retrieved = this.resolveArtifact(messageHandle); artifact.setDocument(retrieved.getDocument()); artifact.setAudience(retrieved.getAudience()); } catch (UnsupportedEncodingException e) { throw new ArtifactBindingException( "Unable to create message handle base64 string, the required encoding is not supported. Error: " + e.getMessage(), e); } }
From source file:AIR.Common.Web.WebValueCollection.java
public String toString(boolean urlencoded, Map<String, Object> excludeKeys) { int count = this.size(); if (count == 0) { return ""; }//from www . j ava2 s. c om StringBuilder builder = new StringBuilder(); MapIterator iter = this.mapIterator(); while (iter.hasNext()) { String key = (String) iter.getKey(); if (((excludeKeys == null) || (key == null)) || (excludeKeys.get(key) == null)) { String str3; if (urlencoded) { try { byte[] utf8Bytes = key.getBytes("UTF8"); key = new String(utf8Bytes, "UTF8"); } catch (UnsupportedEncodingException e) { _logger.error(e.getMessage()); key = null; } } String str2 = !StringUtils.isEmpty(key) ? (key + "=") : ""; if (builder.length() > 0) { builder.append('&'); } Object value = iter.getValue(); if (value instanceof List) { List list = (List) value; int num3 = (list != null) ? list.size() : 0; if (num3 == 1) { builder.append(str2); str3 = list.get(0).toString(); if (urlencoded) { try { byte[] utf8Bytes = str3.getBytes("UTF8"); str3 = new String(utf8Bytes, "UTF8"); } catch (UnsupportedEncodingException e) { _logger.error(e.getMessage()); str3 = null; } } builder.append(str3); } else if (num3 == 0) { builder.append(str2); } else { for (int j = 0; j < num3; j++) { if (j > 0) { builder.append('&'); } builder.append(str2); str3 = list.get(j).toString(); if (urlencoded) { try { byte[] utf8Bytes = str3.getBytes("UTF8"); str3 = new String(utf8Bytes, "UTF8"); } catch (UnsupportedEncodingException e) { _logger.error(e.getMessage()); str3 = null; } } builder.append(str3); } } } else { builder.append(str2); str3 = value.toString(); if (urlencoded) { try { byte[] utf8Bytes = str3.getBytes("UTF8"); str3 = new String(utf8Bytes, "UTF8"); } catch (UnsupportedEncodingException e) { _logger.error(e.getMessage()); str3 = null; } } builder.append(str3); } } } return builder.toString(); }
From source file:com.silverpeas.attachment.web.AttachmentEntity.java
public void withSharedUri(String baseURI, String token) { URI sharedUri;//from ww w .java 2s .com try { sharedUri = string2URI(baseURI + "sharing/attachments/" + instanceId + "/" + token + "/" + id + "/" + URLEncoder.encode(logicalName, CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { Logger.getLogger(NodeEntity.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex.getMessage(), ex); } this.sharedUri = sharedUri; }
From source file:com.silverpeas.attachment.web.AttachmentEntity.java
public void withUri(String baseURI) { URI privateUri;//from w w w .j av a 2s . com try { privateUri = string2URI(baseURI + "private/attachments/" + instanceId + "/" + id + "/" + URLEncoder.encode(logicalName, CharEncoding.UTF_8)); } catch (UnsupportedEncodingException ex) { Logger.getLogger(NodeEntity.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex.getMessage(), ex); } this.uri = privateUri; }
From source file:org.commonjava.couch.io.CouchHttpClient.java
public void executeHttp(final HttpRequestBase request, final Integer expectedStatus, final Object failureMessage) throws CouchDBException { final String url = request.getURI().toString(); try {/* ww w .j a v a 2 s. c o m*/ final HttpResponse response = client.execute(request); final StatusLine statusLine = response.getStatusLine(); if (expectedStatus != null && statusLine.getStatusCode() != expectedStatus) { final HttpEntity entity = response.getEntity(); final CouchError error = serializer.toError(entity); throw new CouchDBException("%s: %s.\nHTTP Response: %s\nError: %s", failureMessage, url, statusLine, error); } } catch (final UnsupportedEncodingException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final ClientProtocolException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } catch (final IOException e) { throw new CouchDBException("%s: %s.\nReason: %s", e, failureMessage, url, e.getMessage()); } finally { cleanup(request); } }
From source file:com.sm.transport.netty.ClientAsynHandler.java
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { // construct response if (e.getMessage() instanceof Request) { Request req = (Request) e.getMessage(); logger.info("receive " + req.toString() + " from " + e.getRemoteAddress().toString()); AsynReq async = map.get(req.getHeader().getVersion()); if (async != null) { int i = 0; boolean exited = false; // add logic to fix local host concurrency issue while (true) { async.getLock().lock();/*from w w w. j av a 2s .c om*/ try { if (async.isEntered() || i > 400) { async.setResponse(new Response(req.getHeader().toString())); if (req.getPayload().length > 0) { //the first byte indicate error flag, 1 is error if (req.getPayload()[0] == 1) { async.getResponse().setError(true); try { String error = new String(req.getPayload(), 1, req.getPayload().length - 1, "UTF-8"); async.getResponse().setPayload(req.getHeader().toString() + " " + error); } catch (UnsupportedEncodingException ex) { logger.error(ex.getMessage()); } } } else logger.warn("request payload len = 0 " + req.getHeader()); async.getReady().signal(); exited = true; } } finally { async.getLock().unlock(); } i++; if (exited) break; else { try { Thread.sleep(5); } catch (InterruptedException ex) { //do nothing } } //else } //while } //if != null else logger.warn(req.getHeader().toString() + " is not longer in map"); } else { logger.warn(e.getMessage().getClass().getName() + " is not supported " + e.getChannel().getRemoteAddress().toString()); } }
From source file:org.geosdi.geoplatform.connector.server.request.GPPostConnectorRequest.java
private void preparePostMethod() throws IllegalParameterFault, JAXBException, ServerInternalFault { super.prepareHttpParams(); this.postMethod = new HttpPost(super.serverURI); try {//from w w w . jav a2 s . c o m this.postMethod.setEntity(this.preparePostEntity()); } catch (UnsupportedEncodingException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ UnsupportedEncodingException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** UnsupportedEncodingException ***"); } }