Author Archives: Robins

Spring Cloud Openfeign Get Request 405 Error [How to Solve]

KUST retrieve service

@Resource
private AuthFeignService authFeignService;

@ApiOperation("Obtain user information")
@GetMapping("/get/user")
public ResponseEntity<UserMsgDTO> getUserName(HttpServletRequest request){
    String token = request.getHeader("token");
    UserMsgDTO userMsg = authFeignService.getUserMsg(token);
    log.info("userMsg -> {}", userMsg);
    return Results.success(userMsg);
}

@FeignClient("kust-auth")
public interface AuthFeignService {
    @GetMapping("/auth/get/user")
    UserMsgDTO getUserMsg(String jwtToken);
}

KUST auth service

@ApiOperation("Get the username information in the token")
@GetMapping("/get/user")
public UserMsgDTO getUserMsg(String jwtToken){
    log.info("jwtToken -> {}", jwtToken);
    return JwtUtils.getUSerNameByJwtToken(jwtToken);
}

The error reported by the KUST retrieve service is as follows:

feign.FeignException$MethodNotAllowed: status 405 reading AuthFeignService#getUserMsg(String)

The error reported by the KUST auth service is as follows:

Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

Reason: The location of the request parameter is not specified in the feign interface, the parameter “String jwtToken” will be encapsulated in the request body by default, feign will check if the request body is empty when passing the request, if not, the Get request will be converted to Post, and the method in the accepted service kust-auth is Get, so it will naturally report an error 405
Solution is as follows: use @RequestParam(“jwtToken”) to clarify the location of the parameters, note: the string in brackets must be written, or start the error

@FeignClient("kust-auth")
public interface AuthFeignService {
    @GetMapping("/auth/get/user")
    UserMsgDTO getUserMsg(@RequestParam("jwtToken") String jwtToken);
}

Then restart and you can get the data

2022-01-25 11:28:43.577 INFO 16236 --- [nio-9001-exec-9] com. coast. search. api. v1. TokenController: userMsg --gt; UserMsgDTO(id=4, name=LIUXIAOPANG)

C#: How to Add Ink Annotation in PDF

Ink Annotation in PDF is a freehand graffiti-like shape; this type of annotation can arbitrarily specify the position and number of vertices of the shape, and through the specified vertices, the program will connect the points to draw a smooth curve. Below, we will introduce how to add this annotation in PDF through C# program code.

1. dll reference

Step 1 : Open “Solution Explorer” in Visual Studio – right mouse click “References” – “Manage NuGet Packages”.

Step 2 : Select “Browse” – enter the search content in the search box, select the search result, and click “Install”.

Step 3: Click “OK” – “Accept” in sequence, and then wait for the program to complete the installation.

Or, through official channels, download the package  Spire.PDF for .NET  to the local. After decompression, reference the Spire.Pdf.dll file in the BIN folder to the VS program.

 

2. Code example

When adding annotations, in addition to customizing the position and number of each point, you can also set ink color, line width, transparency, annotation content, name, etc. Here are the steps of the code implementation:

  • Create an object of the PdfDocument class and load the PDF document through the PdfDocument.LoadFromFile(String fileName) method.
  • Get the specified page of the PDF through the PdfDocument.Pages[int Index] property.
  • Creates a collection of objects of type int, where the elements of the collection are the ink vertices.
  • Create an instance of the PdfInkAnnotation class. And set the ink color, width, annotation content and other formats through the properties provided by this class.
  • Call the PdfAnnotationCollection.Add(PdfAnnotation annotation) method provided by the PdfPageBase.AnnotationsWidget property to add annotations to the PDF.
  • Finally, save the PDF document to the specified path through the PdfDocument.SaveToFile(string filename, FileFormat fileFormat) method.

C#

using Spire.Pdf;
 using Spire.Pdf.Annotations;
 using System.Collections.Generic;
 using System.Drawing;

namespace InkAnnotation
{
    class Program
    {
        static  void Main( string [] args)
        {
            // Load PDF document 
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile( " test.pdf " );

            // Get the first page 
            PdfPageBase pdfPage = pdf.Pages[ 0 ];

            // Set the ink coordinate point position 
            List< int []> inkList = new List< int []> ();           
             int [] intPoints = new  int []
            {
                370 , 700 ,
                 120 , 720 ,
                 110 , 760 ,
                 220 , 800 ,
                 270 , 790 ,
                 350 , 770 ,
                 350 , 670
            };
            inkList.Add(intPoints);
            // Add ink annotation to PDF page 
            PdfInkAnnotation inkannotation = new PdfInkAnnotation(inkList);
            inkannotation.Color = Color.MediumVioletRed;
            inkannotation.Border.Width = 6 ;
            inkannotation.Opacity = 0.5f ;
            inkannotation.Text = " This is an ink annotation. " ;
            inkannotation.Name = " Manager " ;     
            pdfPage.AnnotationsWidget.Add(inkannotation);

            // Save the document 
            Pdf.SaveToFile( " AddInkAnnotation.pdf " ,FileFormat.PDF);
            System.Diagnostics.Process.Start( " AddInkAnnotation.pdf " );
        }
    }
}

vb.net

Imports Spire.Pdf
 Imports Spire.Pdf.Annotations
 Imports System.Collections.Generic
 Imports System.Drawing

Namespace InkAnnotation
     Class Program
         Private  Shared  Sub Main(args As  String ())
             ' Load PDF document 
            Dim pdf As  New PdfDocument()
            pdf.LoadFromFile( " test.pdf " )

            ' Get the first page 
            Dim pdfPage As PdfPageBase = pdf.Pages( 0 )

            ' Set the ink coordinate point position 
            Dim inkList As  New List( Of  Integer ())()
             Dim intPoints As  Integer () = New  Integer () { 370 , 700 , 120 , 720 , 110 , 760 , _
                 220 , 800 , 270 , 790 , 350 , 770 , _
                 350 , 670 }
            inkList.Add(intPoints)
            ' Add ink annotation to PDF page 
            Dim inkannotation As  New PdfInkAnnotation(inkList)
            inkannotation.Color = Color.MediumVioletRed
            inkannotation.Border.Width = 6 
            inkannotation.Opacity = 0.5F _
            inkannotation.Text = " This is an ink annotation. " 
            inkannotation.Name = " Manager "
            pdfPage.AnnotationsWidget.Add(inkannotation)

            ' Save the document 
            pdf.SaveToFile( " AddInkAnnotation.pdf " , FileFormat.PDF)
         End Sub 
    End Class 
End Namespace

Annotation effect:

.\Objects\BH-F103.axf: Error: L6218E: Undefined symbol RCC_APB2PeriphClkCmd (referred from bsp_led.o).

1. Compilation prompt: \Objects\BH-F103.axf: Error: L6218E: Undefined symbol RCC_APB2PeriphClkCmd (referred from bsp_led.o).

2. Solution:

Check RCC_Apb2periphclkcmd press F12 or right-click to select go to definition of ‘RCC_Apb2periphclkcmd ‘, prompt the following undefined error. This indicates that this function is not defined correctly. The correct definition is “rcc_apb2periphclockcmd”.

3. Summary:

In general, when you encounter this error message, the first thing you think of is that the function is undefined or incorrectly defined. You can’t find the function and reference it.

Reference:

Wrong writing

Correct writing:

error An unexpected error occurred: “https://registry.yarnpkg.com/: self signed certificate in certificate chain”.

Elasticsearch Startup Error: main ERROR Unable to locate appender “rolling_old” for logger config “root”

Foreword: start elasticsearch in the test environment today to report an error. The error information is as follows:

main ERROR Unable to locate appender "rolling_old" for logger config "root"

It was because it was started with root for the first time. After the startup failed, it reported an error when switching users to start, because the file in the log directory belongs to root

Solution:

In the elasticsearch configuration file, find the directory where the logs are stored, change the user and group you belong to. Start it again and it's OK!
chown elk.elk -R /var/log/elasticsearch/

[Solved] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

Environment pycharm2021.1.1+python3.7+django3.2.11

When testing the project, I opened the python console and got django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

The driver is fine, the database configuration is fine, and __init__.py has added this

import pymysql

pymysql. install_as_MySQLdb()

Solution: PIP – M install mysqlclient

[Vue warn]:Error in render: “TypeError: Cannot read property ‘0’ of undefined”

Error description
I defined the seller data in the Vue component. The seller requests a JSON file through Axios. In the seller, there is a data support of array type, as follows:
//

{
"data":{
     "supports": [
          {
            "type": 0,
            "description": "Pay online with 28 or more for 5 off"
          },
          {
            "type": 1,
            "description": "20% off all VC Infinity Orange Juice"
          },
          {
            "type": 2,
            "description": "Single exciting package"
          }
    }
}

I want to get the data of “Pay online with 28 or more for 5 off” to render my elements. I use seller supports[0].description is as follows:

<template>
      <div class="suppor">
        <span>{{seller.supports[0].description}}</span>
      </div>
</template>
<script>
export default {
  name: 'Header',
  data () {
  return: {
    seller: { }
   }
  }
}
</script>

According to the above method, although I rendered the element as scheduled, I reported the following errors and warnings on the browser console.

Solution:
Add a v-if directive to the element to be rendered to determine if there is content in this array, and the warning will be lifted, because the span I want to render is contained in the div, so I add a judgment directive to the div

      <div v-if="seller.supports" class="suppor">
        <span>{{seller.supports[0].description}}</span>
      </div>

Principle Explanation.
After we define seller data in data() method, the initial data will be passed to the component first, before axios request to the data, the component will read the data in seller and render it, but at this time seller is an empty object, seller.supports is also undefined, so if I use [0], it will report a typeerror error, but after that, axios requests the data and the element is rendered further, but the console error warning is still there.
When I add a judgment, I prevent the behavior of taking a value with an index to a ubdefined value.

[Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

After changing the environment recently, the docker reported an error when installing mysql8. The solution is as follows

Find my.cnf to modify

# Add the data
[client]
# Default character set
#default-character-set=utf8
socket= /var/run/mysqld/mysqld.sock 

[mysql]
# Default character set
#default-character-set=utf8
socket= /var/run/mysqld/mysqld.sock #### Here the original configuration is written above [client]
#socket= /storage/db/mysql/mysql.sock
[mysqld]
#
server-id=01
port=3306
## Turn on binary logging
log-bin=mysql-slave-bin
## relay_log configuration relay log
relay_log=edu-mysql-relay-bin
# Ignore case
lower_case_table_names=1

pid-file= /var/run/mysqld/mysqld.pid

socket= /var/run/mysqld/mysqld.sock
#socket= /storage/db/mysql/mysql.sock
# Database data storage directory
datadir= /var/lib/mysql

secure-file-priv= NULL

# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links=0
# Maximum number of links
max_connections=200
# Maximum number of failures
max_connect_errors=10
# Default time zone
default-time_zone='+8:00'

character-set-client-handshake=FALSE

character_set_server=utf8mb4

# default-character-set=utf8

collation-server=utf8mb4_unicode_ci

init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'

# Default authentication with 'mysql_native_password' plugin
default_authentication_plugin= mysql_native_password

# Custom config should go here
!includedir /etc/mysql/conf.d/