Tag Archives: Restful

Uniapp Use vant Weapp icon Module Error [How to Fix]

1. Abnormal information

11:43:21.725 Module build failed (from ./node_modules/postcss-loader/src/index.js):
11:43:21.725 SyntaxError
11:43:21.735 (36:10521) Unclosed bracket
11:43:21.736   34 | 
11:43:21.741   35 | 
11:43:21.742 > 36 | @import '../common/index.css';.van-icon{text-rendering:auto;-webkit-font-smoothing:antialiased;font:normal normal normal 14px/1

 

Solution:

Modify /wxcomponents/vant/icon/index wxss

The following figure in the format (“woff2”) after the url in front of a space, you need to modify two places

IE8 browser Webloader will always go uploaderror and report error: http

When using Baidu webloader, the IE8 browser will always use the uploaderror when debugging

uploader.on( 'uploadError', function( file,reason ) {
     alert(reason) ;
});

The reason error is http. The reason is:
the reason why JSON is returned when it is returned in the background.

The backend of webuploader cannot return json, convert json to string type, take com.alibaba.fastjson.JSONObject as an example,
com.alibaba.fastjson.JSONObject.toJSONString([json or object data]);

[Solved] Error while extracting response for type [] and content type []…

When resttemplate is used to request restful interface, the returned JSON data will always be parsed into XML data for processing under specific circumstances, and then the error in the title will appear:

Error while extracting response for type [] and content type [application/xml;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ‘5’ (code 53) in content after ‘<‘ (malformed start element?).
at [row,col {unknown-source}]: [1,15395]; nested exception is com. fasterxml. jackson. databind. JsonMappingException: Unexpected character ‘5’ (code 53) in content after ‘<‘ (malformed start element?).

According to the error information, it seems that the response header marks the return type as [application/XML; charset = UTF-8], but the actual situation is that all the returned data is [application/JSON; charset = UTF-8].

After tracing the resttemplate source code, it is found that the instance created by new resttemplate (httprequestfactory()) will have 7 Converters:

Continue to track the exchange of the resttemplate. When performing type conversion on the response, all converters in the current instance will be iterated, and then select a converter that supports the current type for execution. Use canread to judge:

At this time, the problem is found. Under certain circumstances, the contenttype of the response header is read as “application/XML”. However, the real data at this time is still in JSON format. Therefore, if the converter for XML format is deleted, the iterator will look for the next executable converter, mappingjackson2httpmessageconverter. Or change the order of the two to reduce the priority of XML.

Solution:

1: Delete XML converter

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate template = new RestTemplate(httpRequestFactory());
        // Exclude xml parsing converters to avoid parsing json data as xml
        List<HttpMessageConverter<?>> collect = template.getMessageConverters().stream().filter(m -> !(m instanceof MappingJackson2XmlHttpMessageConverter)).collect(Collectors.toList());
        template.setMessageConverters(collect);
        return template;
    }

2: Reduce XML converter priority

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate template = new RestTemplate(httpRequestFactory());
        // Turn down the priority of xml parsing
        int xml = 0, json = 0;
        List<HttpMessageConverter<?>> messageConverters = template.getMessageConverters();
        for (int i = 0; i < messageConverters.size(); i++) {
            HttpMessageConverter<?> h = messageConverters.get(i);
            if (h instanceof MappingJackson2XmlHttpMessageConverter) {
                xml = i;
            } else if (h instanceof MappingJackson2HttpMessageConverter) {
                json = i;
            }
        }
        Collections.swap(template.getMessageConverters(), xml, json);

        return template;
    }

After asynchronous file import and springboot multipartfile upload, the @async asynchronous processing reports an error: nosuchfileexception

First question

When there is a large amount of data in Excel, the process of Java background parsing may take a long time, but users do not need to wait. At this time, consider the asynchronous import of files

There are several ways to implement the file asynchronous method. Here, it is implemented by specifying the asynchronous thread pool, that is, @ async (“thread pool name”) annotates the asynchronous method.

However, after testing, it is found that the annotations of this annotation are also annotated, but the asynchronous effect cannot be realized.

After several twists and turns, it is found that asynchronous methods can call non asynchronous methods, which can achieve asynchronous effect; First, non asynchronous methods call asynchronous methods, which will fail. What is said here is in the same Java class.

In different Java classes, the above problems do not exist

The second problem
uses the asynchronous method to receive files through the controller and process them in the service layer. At this time, the controller has returned the results of successful execution. The rest is to analyze and store them in the service layer. Unexpectedly, an error is reported in the service

java.nio.file.NoSuchFileException: D:\UserData\Temp\undertow.1407321862395783323.8400\undertow4517937229384702645upload

Methods in controller

@PostMapping("/test")
public R<String> test(MultipartFile file) {
	testService.test(file);
	return R.success("successful to import");
}

Methods in service

@Async("asyncImportExecutor")
public void test(MultipartFile file) {
    try {
        EasyExcelUtil.read(file.getInputStream(), Test.class, this::executeImport)
                    .sheet().doRead();
    } catch (Exception ex) {
        log.error("[test]Asynchronous import exceptions:", ex);
    }
}

When I saw this exception nosuchfileexception, I was stunned. The test was conducted through postman, so I began to suspect the problem of postman. After troubleshooting, there was no problem with postman and path, and the asynchronous call process was OK

Then think of the abnormal prompt, that is, the file can not be found. According to the printed log, it can’t be found locally. Then there was the following writing

Methods in controller

@PostMapping("/test")
public R<String> test(MultipartFile file) {
	try {
		testService.test(file.getInputStream());
	} catch (IOException e) {
		log.error("[test]Exception log:", e);
		return R.fail("Import failed");
	}
	return R.success("Import successful");
}

Methods in service

@Async("asyncImportExecutor")
public void test(InputStream file) {
    try {
        EasyExcelUtil.read(file, Test.class, this::executeImport)
                    .sheet().doRead();
    } catch (Exception ex) {
        log.error("[test]Asynchronous import exceptions:", ex);
    }
}

So you don’t report mistakes
later, I debugged and found that the temporary file was generated by the multipartfile object in the controller layer. I had been writing the synchronization method, and I didn’t notice that the multipartfile object would generate a temporary file. Later, it was found that after the result returned in the controller, there was no temporary file.

Error summary:
because the asynchronous method is used, there will be a main thread and an asynchronous thread. After uploading a file, an instance of multipartfile type will be formed and a temporary file will be generated. At this time, it is in the main thread. After the instance of multipartfile is handed over to the asynchronous thread for processing, the temporary file will be destroyed by springboot (spring). The above exception will appear when you go to getinputstream in the asynchronous thread.

The following method is to take the InputStream stream as the input parameter, so the file cannot be found.

Solve the problem of flag error valueerror: View function did not return a response

Today, we use Python to implement the restful interface of Flask, and then call it wrong.

ValueError: View function did not return a response

The code is as follows:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

      param = request.json

      print(param)

The reason for the error is that the restful interface of flag must have a return value.

Therefore, modify the code to add the return value:

Add: return XXXX

For example:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

    try:

        if not request.json:

            return jsonify({'code': -1, 'message': 'request is not json'})

        param = request.json

        return jsonify({'code': 0, 'status': 'running'})

    except Exception as e:

        print(e)

        return jsonify({'code': -1, 'error_message':e})