paulwong

          #

          Java的BIO和NIO很難懂?用代碼實(shí)踐給你看,再不懂我轉(zhuǎn)行!

          http://www.52im.net/thread-2846-1-1.html

          posted @ 2020-12-02 08:52 paulwong 閱讀(304) | 評(píng)論 (0)編輯 收藏

          SPRING DATA MONGODB 教程


          https://github.com/eugenp/tutorials/tree/master/persistence-modules/spring-data-mongodb

          posted @ 2020-11-20 14:45 paulwong 閱讀(258) | 評(píng)論 (0)編輯 收藏

          LINUX SHELL之SCL

          什么是SCL
          https://blog.51cto.com/hashlinux/1772066

          CentOS/RHEL 開發(fā)環(huán)境之 devtoolset
          http://blog.fungo.me/2016/03/centos-development-env/

          How can I make a Red Hat Software Collection persist after a reboot/logout?
          https://access.redhat.com/solutions/527703

          posted @ 2020-11-05 16:42 paulwong 閱讀(724) | 評(píng)論 (0)編輯 收藏

          Pretty print JSON using org.json library in Java

          Syntax

          public java.lang.String toString(int indentFactor) throws JSONException

          Example

          import org.json.*;
          public class JSONPrettyPrintTest {
             
          public static void main(String args[]) throws JSONException {
                String json 
          = "{" +
                              
          "Name : Jai," +
                              
          "Age : 25, " +
                              
          "Salary: 25000.00 " +
                              
          "}";
                JSONObject jsonObj 
          = new JSONObject(json);
                System.out.println(
          "Pretty Print of JSON:");
                System.out.println(jsonObj.toString(
          4)); // pretty print json
             }
          }

          Output

          Pretty Print of JSON:
          {
             "Salary": 25000,
             "Age": 25,
             "Name": "Jai"
          }

          posted @ 2020-10-28 17:17 paulwong 閱讀(263) | 評(píng)論 (0)編輯 收藏

          !!!服務(wù)器端各種安裝

          https://www.server-world.info/en/

          posted @ 2020-10-24 23:46 paulwong 閱讀(248) | 評(píng)論 (0)編輯 收藏

          install redhat rh-mariadb103

          # Install MariaDB 10.3
          yum install rh-mariadb103-mariadb-server rh-mariadb103-mariadb-server-utils -y

          # Add MariaDB 10.3 to $PATH
          scl enable rh-mariadb103 bash
          source /opt/rh/rh-mariadb103/enable

          # start 10.3 server
          chown -R mysql:mysql /var/opt/rh/rh-mariadb103/lib/mysql;
          systemctl start rh-mariadb103-mariadb

          # Upgrade tables
          mysql_upgrade -p[PASSWORD]

          # Set 10.3 to start on boot
          systemctl enable rh-mariadb103-mariadb

          # Add 10.3 to paths on reboot (and remove 10.2) 
          rm /etc/profile.d/rh-mariadb102.sh
          cp /opt/rh/rh-mariadb103/enable /etc/profile.d/rh-mariadb103.sh

          # increase max connections number
          systemctl edit rh-mariadb103-mariadb
          [Service]
          LimitNOFILE=65535
          LimitNPROC=65535

          vi /etc/opt/rh/rh-mariadb103/my.cnf
          [mysqld]
          max_connections=1000
          open_files_limit=65535

          # restart mariadb103
          systemctl daemon-reload
          systemctl restart rh-mariadb103-mariadb

          # check result
          mysql -e 'show variables like "max_connections"'

          https://www.server-world.info/en/note?os=CentOS_7&p=mariadb103&f=4

          posted @ 2020-10-24 18:02 paulwong 閱讀(380) | 評(píng)論 (0)編輯 收藏

          SPRING 中YAML文件密碼不以明文保存

          Update: for production environment, to avoid exposing the password in the command line, since you can query the processes with ps, previous commands with history, etc etc. You could:

          • Create a script like this: touch setEnv.sh
          • Edit setEnv.sh to export the JASYPT_ENCRYPTOR_PASSWORD variable

            #!/bin/bash

            export JASYPT_ENCRYPTOR_PASSWORD=supersecretz

          • Execute the file with . setEnv.sh
          • Run the app in background with mvn spring-boot:run &
          • Delete the file setEnv.sh
          • Unset the previous environment variable with: unset JASYPT_ENCRYPTOR_PASSWORD

          https://stackoverflow.com/questions/37404703/spring-boot-how-to-hide-passwords-in-properties-file

          posted @ 2020-10-20 14:59 paulwong 閱讀(471) | 評(píng)論 (0)編輯 收藏

          SPRING INTEGRATION HEADER問(wèn)題

          當(dāng)SPRING INTEGRATION的流程中從HTTP outboundGateway轉(zhuǎn)成JmsGateway時(shí),會(huì)報(bào)header的錯(cuò)誤,這時(shí)就要把相關(guān)多余的header移除。

          .headerFilter("Api-Key", "Content-Type", "X-Powered-By", "Content-Language", "Transfer-Encoding", "Cache-Control", "Keep-Alive", "Set-Cookie")

          https://stackoverflow.com/questions/50608415/cwsia0112e-the-property-name-keep-alive-is-not-a-valid-java-identifier

          posted @ 2020-10-20 14:56 paulwong 閱讀(333) | 評(píng)論 (0)編輯 收藏

          RestTemplate處理請(qǐng)求狀態(tài)碼為非200的返回?cái)?shù)據(jù)

          RestTemplate是Spring提供的用于訪問(wèn)Rest服務(wù)的客戶端,

          RestTemplate提供了多種便捷訪問(wèn)遠(yuǎn)程Http服務(wù)的方法,能夠大大提高客戶端的編寫效率。

          調(diào)用RestTemplate的默認(rèn)構(gòu)造函數(shù),RestTemplate對(duì)象在底層通過(guò)使用java.net包下的實(shí)現(xiàn)創(chuàng)建HTTP 請(qǐng)求,

          可以通過(guò)使用ClientHttpRequestFactory指定不同的HTTP請(qǐng)求方式。

          ClientHttpRequestFactory接口主要提供了兩種實(shí)現(xiàn)方式

          1、一種是SimpleClientHttpRequestFactory,使用J2SE提供的方式(既java.net包提供的方式)創(chuàng)建底層的Http請(qǐng)求連接。

          2、一種方式是使用HttpComponentsClientHttpRequestFactory方式,底層使用HttpClient訪問(wèn)遠(yuǎn)程的Http服務(wù),使用HttpClient可以配置連接池和證書等信息。

          默認(rèn)的 RestTemplate 有個(gè)機(jī)制是請(qǐng)求狀態(tài)碼非200 就拋出異常,會(huì)中斷接下來(lái)的操作。如果不想中斷對(duì)結(jié)果數(shù)據(jù)得解析,可以通過(guò)覆蓋默認(rèn)的 ResponseErrorHandler ,見下面的示例,示例中的方法中基本都是空方法,只要對(duì)hasError修改下,讓他一直返回true,即是不檢查狀態(tài)碼及拋異常了。

          package com.example.demo.web.config;

          import java.io.IOException;

          import org.springframework.context.annotation.Bean;
          import org.springframework.context.annotation.Configuration;
          import org.springframework.http.client.ClientHttpRequestFactory;
          import org.springframework.http.client.ClientHttpResponse;
          import org.springframework.http.client.SimpleClientHttpRequestFactory;
          import org.springframework.web.client.ResponseErrorHandler;
          import org.springframework.web.client.RestTemplate;

          @Configuration
          public class RestTemplateConfig {
              
              @Bean
              public RestTemplate restTemplate(ClientHttpRequestFactory factory) throws Exception {
                  RestTemplate restTemplate = new RestTemplate(factory);
                  ResponseErrorHandler responseErrorHandler = new ResponseErrorHandler() {
                      @Override
                      public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
                          return true;
                      }
                      @Override
                      public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
                      }
                  };
                  restTemplate.setErrorHandler(responseErrorHandler);
                  return restTemplate;
              }
              
              @Bean
              public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
                  SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
                  //讀取超時(shí)5秒
                  factory.setReadTimeout(5000);
                  //連接超時(shí)15秒
                  factory.setConnectTimeout(15000);
                  return factory;
              }
          }

          RestTemppate運(yùn)用實(shí)例

          package com.example.demo.web.controller;

          import org.slf4j.Logger;
          import org.slf4j.LoggerFactory;
          import org.springframework.beans.factory.annotation.Autowired;
          import org.springframework.http.ResponseEntity;
          import org.springframework.web.bind.annotation.GetMapping;
          import org.springframework.web.bind.annotation.RestController;
          import org.springframework.web.client.RestTemplate;

          import com.example.demo.domain.Book;

          @RestController
          public class TestBookController {
              private Logger logger = LoggerFactory.getLogger(getClass());
              
                @Autowired
                private RestTemplate restTemplate;
                
                @GetMapping("/testaddbook")
                public Book testAddBook() {
                        Book book = new Book();
                        ResponseEntity<Book> responseEntity = restTemplate.postForEntity( "http://localhost:8061/book", book , Book.class);
                        return responseEntity.getBody();
                }

          }

          其他方法,catch HttpStatusCodeException e.getResponseBodyAsString()
          try {
              ResponseEntity<Component> response = restTemplate.exchange(webSvcURL,
                  HttpMethod.POST, 
                  requestEntity,
                  Component.class);
          catch (HttpStatusCodeException e) {
              List<String> customHeader = e.getResponseHeaders().get("x-app-err-id");
              String svcErrorMessageID = "";
              if (customHeader != null) {
                  svcErrorMessageID = customHeader.get(0);                
              }
              throw new CustomException(e.getMessage(), e, svcErrorMessageID);
              // You can get the body too but you will have to deserialize it yourself
              
          // e.getResponseBodyAsByteArray()
              
          // e.getResponseBodyAsString()
          }

          https://stackoverflow.com/questions/7878002/resttemplate-handling-response-headers-body-in-exceptions-restclientexception

          https://stackoverflow.com/questions/38093388/spring-resttemplate-exception-handling/51805956#51805956

          posted @ 2020-10-16 16:54 paulwong 閱讀(1239) | 評(píng)論 (0)編輯 收藏

          Error handling in spring integration - How to get all the errors thrown in multiple threads and send them to the error-channel

          在SPRING INTEGRATION中,如果exception發(fā)生在各種thread里時(shí),如何將exception返回到指定的channel,之后再繞回到aggrator-channel中。

          @Bean
          public IntegrationFlow provisionUserFlow() {
          return
              IntegrationFlows.from("input.channel")
              .publishSubscribeChannel(Executors.newCachedThreadPool(),
                  s -> s.applySequence(true)
                      .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                          .handle(provisionerA, "provision")
                          .channel("aggregatorChannel")
                      )
                      .subscribe(f -> f.enrichHeaders(e -> e.header(MessageHeaders.ERROR_CHANNEL, "errorChannel", true))
                          .handle(provisionerB, "provision")
                          .channel("aggregatorChannel"))
                      )
                  .get();
          }

          @Bean
          public IntegrationFlow aggregateFlow() {
              return IntegrationFlows.from("aggregatorChannel")
                              .channel( aggregatorChannel)
                              .aggregate( a -> a.processor( collect, "aggregatingMethod"))
                              .get();
          }

          @Transformer( inputChannel = "errorChannel", outputChannel = "aggregatorChannel")
          public Message<?> errorChannelHandler(ErrorMessage errorMessage) throws RuntimeException {

              Message<?> failedMessage =  ((MessagingException) errorMessage.getPayload()).getFailedMessage();

              Exception exception = (Exception) errorMessage.getPayload();

              return  MessageBuilder.withPayload( exception.getMessage())
                                                 .copyHeadersIfAbsent( failedMessage.getHeaders() )
                                                 .build();
          }


          https://stackoverflow.com/q/46495127/11790720

          posted @ 2020-10-15 19:21 paulwong 閱讀(244) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共115頁(yè): First 上一頁(yè) 12 13 14 15 16 17 18 19 20 下一頁(yè) Last 
          主站蜘蛛池模板: 鹤庆县| 宁化县| 抚顺县| 自贡市| 灵山县| 阳高县| 留坝县| 郁南县| 普兰店市| 云浮市| 麻栗坡县| 新竹县| 康平县| 光山县| 龙州县| 玛曲县| 积石山| 革吉县| 和政县| 独山县| 安岳县| 鄂州市| 连城县| 肇东市| 河西区| 独山县| 常州市| 三穗县| 云阳县| 上虞市| 泾源县| 广德县| 黄龙县| 开化县| 县级市| 南郑县| 新竹县| 新河县| 东宁县| 茌平县| 清新县|