org.apache.commons.lang3.CharEncoding#UTF_8 ( )源码实例Demo

下面列出了org.apache.commons.lang3.CharEncoding#UTF_8 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test(groups = "wso2.esb", description = "Enrich / Payload Factory mediators,soap namespace is added when soap is not in use")
public void testEnrichNamespaceAdditionTestCase() throws Exception {

    String endpoint = getApiInvocationURL(API_NAME) + "/test_with_pf";
    String requestXml = "<MetaData><DateTimeSent/></MetaData>";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(endpoint);
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity resEntity = response.getEntity();

    BufferedReader rd = new BufferedReader(new InputStreamReader(resEntity.getContent()));
    String result = "";
    String line;
    while ((line = rd.readLine()) != null) {
        result += line;
    }
    Assert.assertTrue(!result.contains("http://schemas.xmlsoap.org/soap/envelope/"),
            "unnessary namespaces present in message");
}
 
源代码2 项目: cubeai   文件: MailService.java
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
源代码4 项目: scava   文件: MailService.java
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(from);
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent email to User '{}'", to);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.warn("Email could not be sent to user '{}'", to, e);
        } else {
            log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
        }
    }
}
 
源代码5 项目: httpkit   文件: HttpReader.java
public HttpReader(InputStream in)
    throws UnsupportedEncodingException
{
    this.in = in;
    this.reader = new BufferedReader(new InputStreamReader(in, CharEncoding.UTF_8));
    //依次从头读到尾
    //1.读消息签名
    if (readSignatureFully())
    {
        //2.读消息头
        if (readHeadersFully())
        {
            //3.读消息体
            if (readBodyFully())
            {
                //解析其他的额外信息 
                resolveExtraInfo();
            }
        }
    }
}
 
@Test(groups = "wso2.esb", description = "Enrich / Payload Factory mediators,soap namespace is added when soap is not in use")
public void testEnrichNamespaceAdditionTestCase() throws Exception {

    String endpoint = getApiInvocationURL(API_NAME) + "/test_with_pf";
    String requestXml = "<MetaData><DateTimeSent/></MetaData>";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(endpoint);
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity resEntity = response.getEntity();

    BufferedReader rd = new BufferedReader(new InputStreamReader(resEntity.getContent()));
    String result = "";
    String line;
    while ((line = rd.readLine()) != null) {
        result += line;
    }
    Assert.assertTrue(!result.contains("http://schemas.xmlsoap.org/soap/envelope/") , "unnessary namespaces present in message");
}
 
源代码7 项目: tutorials   文件: MailService.java
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}
 
源代码8 项目: tutorials   文件: MailService.java
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
    log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
        isMultipart, isHtml, to, subject, content);

    // Prepare message using a Spring helper
    MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    try {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
        message.setTo(to);
        message.setFrom(jHipsterProperties.getMail().getFrom());
        message.setSubject(subject);
        message.setText(content, isHtml);
        javaMailSender.send(mimeMessage);
        log.debug("Sent e-mail to User '{}'", to);
    } catch (Exception e) {
        log.warn("E-mail could not be sent to user '{}'", to, e);
    }
}
 
@Test(groups = "wso2.esb", description = "Tests Enrich Source OM Property without clone")
public void testEnrichSourceTypePropertyAndCloneFalse() throws Exception {

    String endpoint = getProxyServiceURLHttp(PROXY_NAME);

    String requestXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
            + "   <soapenv:Header/>\n" + "   <soapenv:Body>\n" + "      <payload>\n" + "         <content>\n"
            + "            <abc>\n" + "               <def>123</def>\n" + "            </abc>\n"
            + "         </content>\n" + "      </payload>\n" + "   </soapenv:Body>\n" + "</soapenv:Envelope>";

    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost(endpoint);
    httpPost.addHeader("SOAPAction", "\"urn:mediate\"");
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity resEntity = response.getEntity();

    BufferedReader rd = new BufferedReader(new InputStreamReader(resEntity.getContent()));
    String result = "";
    String line;
    while ((line = rd.readLine()) != null) {
        result += line;
    }
    Assert.assertTrue(!result.contains("payload"));
}
 
@Test(groups = "wso2.esb", description = "Tests Enrich Source OM Property without clone")
public void testEnrichSourceTypePropertyAndCloneFalse() throws Exception {

    String endpoint = getProxyServiceURLHttp(PROXY_NAME);

    String requestXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
            "   <soapenv:Header/>\n" +
            "   <soapenv:Body>\n" +
            "      <payload>\n" +
            "         <content>\n" +
            "            <abc>\n" +
            "               <def>123</def>\n" +
            "            </abc>\n" +
            "         </content>\n" +
            "      </payload>\n" +
            "   </soapenv:Body>\n" +
            "</soapenv:Envelope>";

    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost(endpoint);
    httpPost.addHeader("SOAPAction", "\"urn:mediate\"");
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);
    HttpEntity resEntity = response.getEntity();

    BufferedReader rd = new BufferedReader(new InputStreamReader(resEntity.getContent()));
    String result = "";
    String line;
    while ((line = rd.readLine()) != null) {
        result += line;
    }
    Assert.assertTrue(!result.contains("payload"));
}
 
源代码11 项目: livingdoc-core   文件: ClientUtils.java
/**
 * Returns an array with decoded elements from a string in base64.
 *
 * @param base64String
 * @param separator
 * @return
 * @throws UnsupportedEncodingException
 */
public static String[] decodeFromBase64(final String base64String, final String separator) throws UnsupportedEncodingException {

    // TODO Since Java 8 it can be used: java.util.Base64.getDecoder().decode(base64String);

    byte[] bytes = DatatypeConverter.parseBase64Binary(base64String);
    String decodedAuthorization = new String(bytes, CharEncoding.UTF_8);
    return separator != null ? decodedAuthorization.split(separator) : new String[]{decodedAuthorization};
}
 
源代码12 项目: attic-apex-malhar   文件: LogParser.java
@Override
public void setup(Context.OperatorContext context)
{
  objMapper = new ObjectMapper();
  encoding = encoding != null ? encoding : CharEncoding.UTF_8;
  setupLog();
}
 
源代码13 项目: micro-integrator   文件: ESBJAVA4318Testcase.java
@Test(groups = "wso2.esb", description = "cache meditor with payloads including Processing Insturctions")
public void testCacheMediatorWithPIs() throws Exception {

    String requestXml =
            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\">\n"
                    + "   <soapenv:Header>\n"
                    + "      <m:Trans xmlns:m=\"http://www.w3schools.com/transaction/\">234</m:Trans>\n"
                    + "   </soapenv:Header>\n" + "   <soapenv:Body>\n" + "      <ser:getFullQuote>\n"
                    + "         <ser:request>\n" + "            <xsd:symbol>IBM</xsd:symbol>\n"
                    + "         </ser:request>\n" + "      </ser:getFullQuote>\n" + "   </soapenv:Body>\n"
                    + "</soapenv:Envelope>";

    final String expectedValue = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope "
            + "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><b xmlns=\"http://ws"
            + ".apache.org/ns/synapse\"><?xml-multiple  array?><xyz><a xmlns=\"\">after "
            + "cache</a></xyz></b></soapenv:Body></soapenv:Envelope>";

    DefaultHttpClient httpclient = new DefaultHttpClient();

    // this is to populate the cache mediator
    HttpPost httpPost = new HttpPost(getProxyServiceURLHttp("PF"));
    httpPost.addHeader("SOAPAction", "urn:getFullQuote");
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.getEntity().writeTo(baos);
    String actualValue = baos.toString();

    // this is to get the actual cache response
    HttpPost httpPost2 = new HttpPost(getProxyServiceURLHttp("PF"));
    httpPost2.addHeader("SOAPAction", "urn:getFullQuote");
    httpPost2.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity2 = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost2.setEntity(stringEntity2);
    HttpResponse response2 = httpclient.execute(httpPost);

    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    response2.getEntity().writeTo(baos2);
    String actualValue2 = baos2.toString();
    Assert.assertEquals(actualValue2, expectedValue);
}
 
源代码14 项目: httpkit   文件: HttpWriter.java
public HttpWriter(OutputStream out)
    throws UnsupportedEncodingException
{
    super(new OutputStreamWriter(out, CharEncoding.UTF_8));
    this.out = out;
}
 
源代码15 项目: product-ei   文件: ESBJAVA4318Testcase.java
@Test(groups = "wso2.esb", description = "cache meditor with payloads including Processing Insturctions")
public void testCacheMediatorWithPIs() throws Exception {

    String requestXml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\">\n"
            + "   <soapenv:Header>\n"
            + "      <m:Trans xmlns:m=\"http://www.w3schools.com/transaction/\">234</m:Trans>\n"
            + "   </soapenv:Header>\n" + "   <soapenv:Body>\n" + "      <ser:getFullQuote>\n"
            + "         <ser:request>\n" + "            <xsd:symbol>IBM</xsd:symbol>\n"
            + "         </ser:request>\n" + "      </ser:getFullQuote>\n" + "   </soapenv:Body>\n"
            + "</soapenv:Envelope>";

    final String expectedValue = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope " +
            "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body><b xmlns=\"http://ws" +
            ".apache.org/ns/synapse\"><?xml-multiple  array?><xyz><a xmlns=\"\">after " +
            "cache</a></xyz></b></soapenv:Body></soapenv:Envelope>";

    DefaultHttpClient httpclient = new DefaultHttpClient();

    // this is to populate the cache mediator
    HttpPost httpPost = new HttpPost(getProxyServiceURLHttp("PF"));
    httpPost.addHeader("SOAPAction", "urn:getFullQuote");
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost.setEntity(stringEntity);
    HttpResponse response = httpclient.execute(httpPost);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    response.getEntity().writeTo(baos);
    String actualValue = baos.toString();

    // this is to get the actual cache response
    HttpPost httpPost2 = new HttpPost(getProxyServiceURLHttp("PF"));
    httpPost2.addHeader("SOAPAction", "urn:getFullQuote");
    httpPost2.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml;charset=UTF-8");
    HttpEntity stringEntity2 = new StringEntity(requestXml, CharEncoding.UTF_8);
    httpPost2.setEntity(stringEntity2);
    HttpResponse response2 = httpclient.execute(httpPost);

    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    response2.getEntity().writeTo(baos2);
    String actualValue2 = baos2.toString();
    Assert.assertEquals(actualValue2, expectedValue);
}
 
 同类方法