List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:fr.paris.lutece.portal.business.user.attribute.AdminUserFieldFilter.java
/** * Build url attributes/* w w w . jav a2 s .c o m*/ * @param url The url item */ public void setUrlAttributes(UrlItem url) { for (AdminUserField userField : _listUserFields) { try { url.addParameter( PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE + userField.getAttribute().getIdAttribute(), URLEncoder.encode(userField.getValue(), AppPropertiesService.getProperty(PROPERTY_ENCODING_URL))); } catch (UnsupportedEncodingException e) { AppLogService.error(e.getMessage(), e); } } }
From source file:net.shopxx.plugin.abcPayment.AbcPaymentPlugin.java
@Override public String getNotifyMessage(PaymentPlugin.NotifyMethod notifyMethod, HttpServletRequest request) { try {//from www . jav a 2 s. c o m return PaymentPlugin.NotifyMethod.async.equals(notifyMethod) ? "<URL>" + getNotifyUrl(PaymentPlugin.NotifyMethod.sync) + "?MSG=" + URLEncoder.encode(request.getParameter("MSG"), "UTF-8") + "</URL>" : null; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:org.jboss.pnc.integration.BuildTasksRestTest.java
@Test public void shouldTriggerBuildExecution() { HttpPost request = new HttpPost(url + "/pnc-rest/rest/build-tasks/execute-build"); request.addHeader(getAuthenticationHeaderApache()); BuildExecutionConfiguration buildExecutionConfig = BuildExecutionConfiguration.build(1, "test-content-id", 1, "mvn clean install", "jboss-modules", "scm-url", "f18de64523d5054395d82e24d4e28473a05a3880", "1.0.0.redhat-1", "origin-scm-url", false, "dummy-docker-image-id", "dummy.repo.url/repo", SystemImageType.DOCKER_IMAGE, BuildType.MVN, false, null, new HashMap<>(), false, null); BuildExecutionConfigurationRest buildExecutionConfigurationRest = new BuildExecutionConfigurationRest( buildExecutionConfig);//from w ww . j a v a 2 s.c om List<NameValuePair> requestParameters = new ArrayList<>(); requestParameters.add( new BasicNameValuePair("buildExecutionConfiguration", buildExecutionConfigurationRest.toString())); try { request.setEntity(new UrlEncodedFormEntity(requestParameters)); } catch (UnsupportedEncodingException e) { log.error("Cannot prepare request.", e); Assert.fail("Cannot prepare request." + e.getMessage()); } log.info("Executing request {} with parameters: {}", request.getRequestLine(), requestParameters); int statusCode = -1; try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) { try (CloseableHttpResponse response = httpClient.execute(request)) { statusCode = response.getStatusLine().getStatusCode(); Assert.assertEquals("Received error response code. Response: " + printEntity(response), 200, statusCode); } } catch (IOException e) { Assertions.fail("Cannot invoke remote endpoint.", e); } }
From source file:org.mitre.stixwebtools.services.TaxiiService.java
/** * Makes a poll request from a Taxii server to get a Taxii document. * /*from ww w . ja va2 s .co m*/ * @param serverUrl * @param collection * @param subId * @param beginStr * @param endStr * @return */ public String getTaxiiDocument(URI serverUrl, String collection, String subId, String beginStr, String endStr) { HttpClient taxiiClient = getTaxiiClient("gatekeeper.mitre.org", 80); ObjectFactory factory = new ObjectFactory(); PollRequest pollRequest = factory.createPollRequest().withMessageId(MessageHelper.generateMessageId()) .withCollectionName(collection); if (!subId.isEmpty()) { pollRequest.setSubscriptionID(subId); } else { pollRequest.withPollParameters(factory.createPollParametersType()); } if (!beginStr.isEmpty()) { try { pollRequest.setExclusiveBeginTimestamp( DatatypeFactory.newInstance().newXMLGregorianCalendar(beginStr)); } catch (DatatypeConfigurationException eeeee) { } } if (!endStr.isEmpty()) { try { pollRequest .setExclusiveBeginTimestamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(endStr)); } catch (DatatypeConfigurationException eeeee) { } } String content; try { Object responseObj = taxiiClient.callTaxiiService(serverUrl, pollRequest); content = taxiiXml.marshalToString(responseObj, true); /*if (responseObj instanceof DiscoveryResponse) { DiscoveryResponse dResp = (DiscoveryResponse) responseObj; //processDiscoveryResponse(dResp); } else if (responseObj instanceof StatusMessage) { StatusMessage sm = (StatusMessage) responseObj; //processStatusMessage(sm); }*/ } catch (JAXBException e) { content = e.getMessage(); } catch (UnsupportedEncodingException eee) { content = eee.getMessage(); } catch (IOException eeee) { content = eeee.getMessage(); } return content; }
From source file:es.pentalo.apps.RBPiCameraControl.API.RBPiCamera.java
private HttpEntity getEntityPost(String url, List<Command> commands) { Log.d(TAG, url);/*ww w .ja va 2 s. com*/ Gson gson = new Gson(); String json = gson.toJson(commands); Log.d(TAG, json); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpost = new HttpPost(url); StringEntity se; try { se = new StringEntity(json); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); return null; } httpost.setEntity(se); httpost.setHeader("Accept", "application/json"); httpost.setHeader("Content-type", "application/json"); try { HttpResponse response = httpclient.execute(httpost); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response.getEntity(); } else { Log.w(TAG, "HTTP Response: " + String.valueOf(response.getStatusLine().getStatusCode())); return null; } } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage()); return null; } catch (IOException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:com.redhat.rhn.frontend.xmlrpc.serializer.ConfigRevisionSerializer.java
protected void addEncodedFileContent(ConfigRevision rev, SerializerHelper helper) { try {/* ww w . j av a2 s .c o m*/ helper.add(CONTENTS, new String(Base64.encodeBase64(rev.getConfigContent().getContents()), "UTF-8")); } catch (UnsupportedEncodingException e) { String msg = "Following errors were encountered " + "when creating the config file.\n" + e.getMessage(); throw new FaultException(1023, "ConfgFileError", msg); } helper.add(CONTENTS_ENC64, Boolean.TRUE); if (!rev.getConfigContent().isBinary()) { helper.add(MACRO_START, rev.getConfigContent().getDelimStart()); helper.add(MACRO_END, rev.getConfigContent().getDelimEnd()); } }
From source file:fr.paris.lutece.portal.business.user.attribute.AdminUserFieldFilter.java
/** * Build url attributes//from ww w . j a v a 2 s . co m * @return the url attributes */ public String getUrlAttributes() { StringBuilder sbUrlAttributes = new StringBuilder(); for (AdminUserField userField : _listUserFields) { try { sbUrlAttributes.append(CONSTANT_ESPERLUETTE + PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE + userField.getAttribute().getIdAttribute() + CONSTANT_EQUAL + URLEncoder.encode( userField.getValue(), AppPropertiesService.getProperty(PROPERTY_ENCODING_URL))); } catch (UnsupportedEncodingException e) { AppLogService.error(e.getMessage(), e); } } return sbUrlAttributes.toString(); }
From source file:com.sm.transport.grizzly.ClientFilter.java
@Override public NextAction handleRead(FilterChainContext ctx) throws IOException { // Peer address is used for non-connected UDP Connection :) final Object peerAddress = ctx.getAddress(); final Request req = ctx.getMessage(); logger.info("receive " + req.getHeader().toString() + " from " + ctx.getAddress().toString() + " payload len " + (req.getPayload() == null ? 0 : req.getPayload().length)); 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();/*w w w. jav a2s . c o m*/ 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"); //Request req = new Request( req.getHeader(), new byte[] {0} ); //ctx.write(peerAddress, req, null); return ctx.getStopAction(); }
From source file:com.oneteam.framework.android.net.HttpPostConnection.java
@Override public void connect() { HttpPost httpPost = new HttpPost(mUrl); if (mParamsMap != null && mParamsMap.size() > 0) { ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(mParamsMap.values()); try {//from w ww. ja v a2 s . c o m httpPost.setEntity(new UrlEncodedFormEntity(params)); } catch (UnsupportedEncodingException e) { Logger.w("Failure while establishing url connection as unsupported encoding error > " + e.getMessage()); e.printStackTrace(); } } super.connect(httpPost); }
From source file:edu.rowan.app.fragments.FoodCommentFragment.java
/** * Setup the view and set the button action when clicked *//* ww w . ja v a2 s .co m*/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.food_comment_layout, container, false); Button submit = (Button) view.findViewById(R.id.commentButton); final EditText commentField = (EditText) view.findViewById(R.id.commentField); submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hideKeyboard(commentField); JsonQueryManager jsonManager = JsonQueryManager.getInstance(getActivity()); Map<String, String> params = new HashMap<String, String>(); String comment = commentField.getText().toString(); comment = comment.replaceAll("<.*>", ""); userComment = comment; try { comment = java.net.URLEncoder.encode(comment, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); } params.put(FoodRatingFragment.FOOD_ENTRY_ID, foodEntryId); params.put(FoodRatingFragment.USER_ID, userId); params.put(COMMENT_PARAM, comment); jsonManager.requestJson(FOOD_COMMENT_ADDR, params, FoodCommentFragment.this); } }); return view; }