小编Ron*_*nie的帖子

Spring:文件上传RESTFUL Web服务

我正在使用Spring 4.0为RESTFUL Web服务创建POC.如果我们只传递String或任何其他基本dataype,它工作正常.

@RequestMapping(value="/upload/file", method=RequestMapping.post)
public String uploadFile(@RequestParam("fileName", required=false) String fileName){
    logger.info("initialization of object");
    //----------------------------------------

     System.out.Println("name of File : " + fileName);  

    //----------------------------------------
}
Run Code Online (Sandbox Code Playgroud)

这很好用.但如果我想传递字节流或文件对象功能,我怎么能写这个具有这些参数的函数?如何编写提供传递字节流的客户端?

@RequestMapping(value="/upload/file", method=RequestMapping.post)
public String uploadFile(@RequestParam("file", required=false) byte [] fileName){
     //---------------------
     // 
}
Run Code Online (Sandbox Code Playgroud)

我尝试了这段代码但得到了415错误.

@RequestMapping(value = "/upload/file", method = RequestMethod.POST, consumes="multipart/form-data")
public @ResponseBody String uploadFileContentFromBytes(@RequestBody MultipartFormDataInput input,  Model model) {
    logger.info("Get Content. "); 
  //------------
   }  
Run Code Online (Sandbox Code Playgroud)

客户端代码 - 使用apache HttpClient

private static void executeClient() {
    HttpClient client = new DefaultHttpClient();
    HttpPost postReqeust = new HttpPost(SERVER_URI + "/file"); …
Run Code Online (Sandbox Code Playgroud)

java rest web-services spring-mvc

18
推荐指数
1
解决办法
8万
查看次数

Java:将包含枚举的对象转换为Json对象

我使用org.json库将Object转换为Json格式.请检查以下代码段.

public enum JobStatus implements Serializable{
     INCOMPLETE,
     INPROGRESS,
     ABORTED,
     COMPLETED
}

public class Job implements Serializable {
    private string id;
    private JobStatus status;
    ...
}

...

// Create Job Object
Job job = new Job("12345", JobStatus.INPROGRESS);

// Convert and print in JSON format
System.out.println(new JSONObject(job).toString());
Run Code Online (Sandbox Code Playgroud)

它显示如下输出:

 {"id":"12345", "status" : {}}
Run Code Online (Sandbox Code Playgroud)

它显示空白并添加Curly基础.这是什么意思?有人经历过这个问题吗?

java enums json

16
推荐指数
2
解决办法
5万
查看次数

spring:从REST WebService获取Multipart文件的响应

我正在使用Spring 4.0为RESTFUL Web服务创建POC.要求是从REST WEB-Service接收MultipartFile作为响应.

REST服务控制器

@RequestMapping(value="/getcontent/file", method=RequestMapping.post)
public MultipartFile getMultipartAsFileAsObject() {

    File file = new File("src/test/resources/input.docx");
    FileInputStream input = new FileInputStream(file);
    MultipartFile multipartFile = new MockMultipartFile("file",file.getName(),
                                 "application/docx", IOUtils.toByteArray(input));

    return multipartFile        
}
Run Code Online (Sandbox Code Playgroud)

我也使用第三方客户端和Apache Http客户端来调用此服务.请仔细看看输出.

使用第三方REST客户端即.邮差

输出看起来像Json -

{
    "name" : "file",
    "originalfilename" : "sample.docx",
    "contentType" : "application/docx",
    "content" : [
                82,
                101,
                97,
                100,
                101,    
                32,
                32,
                .
                .
                .
                .
                .
            ]  
}
Run Code Online (Sandbox Code Playgroud)

Apache HTTP Client示例代码

private static void executeClient() {
HttpClient client = new DefaultHttpClient();
HttpPost postReqeust = …
Run Code Online (Sandbox Code Playgroud)

rest spring multipart

6
推荐指数
1
解决办法
9461
查看次数

Angular 2:用于 activateRoute.snapshot.queryParams[""] 的 jasmin 测试用例

我正在使用 ActiveRoute 从 url 读取一些值。

http://localhost:4200/project-test/#/add?orderId=156&customerNumber=431
Run Code Online (Sandbox Code Playgroud)

我有单独的组件来读取 ngOnInit() 方法中的值。

片段:

...

constructor(private activatedRoute: ActivatedRoute,
          public sanitizer: DomSanitizer,
          private customerAPIService : CustomerAPIService) {}

ngOnInit() {

   this.orderId = this.activatedRoute.snapshot.queryParams["orderId"];
   ...
}
Run Code Online (Sandbox Code Playgroud)

测试用例 :

import { TestBed } from '@angular/core/testing';
import { CreateCustomer } from './create-customer.component';
import { ActivatedRoute } from '@angular/router';
import { CustomerAPIService } from "app/repackaging/service/customer.api.service";

describe('CreateCustomer', () => {
  let component;

  let mockActiveRoute;
  let mockCustomerAPIService;
  let mockQueryParamMap;

  beforeEach(() => {

     mockQueryParamMap = jasmine.createSpyObj('mockQueryParamMap', ['queryParams']);
     mockActiveRoute = {queryParamMap: mockQueryParamMap};

    TestBed.configureTestingModule({
        providers …
Run Code Online (Sandbox Code Playgroud)

jasmine typescript angular

6
推荐指数
1
解决办法
7528
查看次数

Eclipse:构建 Groovy/Grail 项目期间发生错误

我已经为 eclipse kepler 3.5.1 RELEASE 安装了 GGTS 插件。我创建了简单的 grail 项目。但在建设项目时。它的获取错误

构建期间发生错误。
在项目“FirstApp”上运行构建器“Java Builder”时出错。
org.codehaus.groovy.runtime.StringGroovyMethods.plus(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;

如果我们在标记中看到,我发现了这个错误

内部编译器错误:java.lang.NoSuchMethodError:org.codehaus.groovy.runtime.StringGroovyMethods.plus(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String; 在
org.codehaus.groovy.grails.transaction.transform.TransactionalTransform.moveOriginalCodeToNewMethod(TransactionalTransform.groovy:259)  
Config.groovy /FirstApp/grails-app/conf 第 0 行 Java 问题

我正在使用 feroda 17.Eclipse Kepler。

eclipse grails

5
推荐指数
1
解决办法
5616
查看次数

RabbitMQ:在直接交换中创建动态队列

我是 RabbitMQ 的新手,我刚刚浏览了 Rabbitmq 文档(路由)。我在 Exchange 与路由键之间很困惑。我的要求是,我想动态创建多个队列。请参考下图。

 生产者将作业发送到 Exchange 并将其转发到相应的队列

前任。让我们说如果生产者为消费者 c3 创建消息,那么它应该转到 Exchange 并仅路由到队列 3 并仅由 C3 消费。目前我只需要 3 个队列,将来这个计数可能会增加。那么如何处理这种情况呢。

注意:我参考这个博客交流

我已经将 Spring hibernate 与 Rabbitmq 一起使用了。下面的代码显示了 Rabbit MQ 侦听器配置文件。

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/rabbit  
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">

<rabbit:connection-factory id="connectionFactory" host="xx.xx.10.181" username="admin" password="admin" />
<rabbit:admin connection-factory="connectionFactory" />

<!--  Create Queues -->
<rabbit:queue id="q1" name="q1.queue" durable="true" />
<rabbit:queue id="q2" name="q2.queue" durable="true"  />
<rabbit:queue id="q3" name="q3.queue" durable="true"  />

<!--create Exchange here -->
<rabbit:direct-exchange id="myExchange" name="MY Exchange">
    <rabbit:bindings>
         <rabbit:binding queue="q1" …
Run Code Online (Sandbox Code Playgroud)

java message-queue rabbitmq spring-amqp rabbitmq-exchange

5
推荐指数
0
解决办法
1581
查看次数

Java:将多部分文件发送到 RESTWebservice

我使用Spring作为技术。用于调用Web 服务的 Apache HttpClient。基本目的是上传分段文件(文件不是任何图像文件或视频文件)。但在这里我的要求略有不同。请检查下图。

在此处输入图片说明

在这里你可以看到第一个块。它是一个简单的 GUI,只有 2 个输入标签和正确的表单标签。

在第二个块中,有 RESTFul Webservice,它以 Multipart File 作为参数并对其进行处理。(到此为止已经完成了)。
现在我被困在这里。我想将此多部分文件发送到其他仅使用多部分文件的 RESTFul Web 服务。

RESTFUL Webservice 的代码片段:(评论了一些问题,需要您的建议)

@RequestMapping(value="/project/add")
public @ResponseBody String addURLListToQueue(
        @RequestParam(value = "file") MultipartFile file,
        @RequestParam(value = "id1", defaultValue = "notoken") String projectName,
        @RequestParam(value = "id2", defaultValue = "notoken") String id2,
        @RequestParam(value = "id3", defaultValue = "notoken") String id3){

HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

HttpPost httppost = new HttpPost("http://localhost:8080/fs/project/add");

// 1) Do I need to convert …
Run Code Online (Sandbox Code Playgroud)

java spring web-services httpclient apache-commons-httpclient

5
推荐指数
1
解决办法
6177
查看次数

Eclipse:shift + 8按钮不起作用

我在Eclipse中特别遇到键盘问题.我想用/**放多行注释但是使用"SHIFT + 8"根本不起作用.它不会打印任何东西.如果我们只按8按钮就会打印8.

事实上我尝试了其他组合,如"SHIFT + 1" - >打印!(感叹号).它在Eclipse中运行得非常好.

令人惊讶的是,我在其他应用程序中尝试了"SHIFT + 8"它完美无缺.我不明白为什么只有SHIFT + 8不起作用.

eclipse keyboard

5
推荐指数
1
解决办法
1907
查看次数

Openshift - 如何获取 POD 列表当前的内存使用情况

我想查看 POD 当前的内存使用情况。我尝试“oc get pods | grep elastic-*”来获取 POD 详细信息

elastic-index-5-kwz79                                       1/1       Running   0          1h
elastic-index-5-lcfzp                                       1/1       Running   0          1h
elastic-master-0                                            1/1       Running   0          1h
elastic-master-1                                            1/1       Running   0          1h
elastic-master-2                                            1/1       Running   0          1h
elastic-query-2-wspl5                                       1/1       Running   0          1h
Run Code Online (Sandbox Code Playgroud)

表显示状态和上次运行的详细信息,但我正在查找当前内存使用情况和总内存详细信息

例如 -

Name                          Total Memory         Available Memory
elastic-index-5-kwz79           1024MB                723MB
Run Code Online (Sandbox Code Playgroud)

redhat openshift openshift-origin openshift-enterprise

4
推荐指数
1
解决办法
2万
查看次数

Jquery - 如何从div标签中复制所选文本?

假设我在页面中有两个DIVS.#newsdiv和#impdiv分别.

<div id="news">
Apple is facing a lawsuit for not telling users about the amount of memory required by an upgrade       its flagship operating system.
</div>

<div id="imp">
 <!-- Empty -->
</div>
Run Code Online (Sandbox Code Playgroud)

现在我的要求是,如果我从整个句子中仅选择"Apple",那么所选部分将被复制并粘贴到div中#imp.如果复制,则会附加其他部分.

html javascript css jquery

1
推荐指数
1
解决办法
3440
查看次数

Typescript:使用Lambda函数从两个数组中查找公共对象

我正在使用Typescript解决以下问题。我想在列表中搜索对象而不是简单的字母或数字。

以下是两个数组。我想在不使用任何第三方库的情况下将公用对象放在单独的列表中

    firstArray = [
           {
               "id": 4,
               "name": "Tata"
           },
           {
               "id": 11,
               "name": "Maruti"
           },
           {
               "id": 14,
               "name": "Mahindra"
           }
        ]

        secondArray = [
           {
               "id": 4,
               "name": "Tata"
           },
           {
               "id": 11,
               "name": "Maruti"
           },
           {
               "id": 15,
               "name": "Hyundai"
           },
           {
               "id": 21,
               "name": "Honda"
           } 
        ]
        
// Get Common Elements
// I am getting blank array as output

        console.log(firstArray.filter(( make ) => secondArray.includes( make)));
Run Code Online (Sandbox Code Playgroud)

有什么好的功能或方法可以找到公地元素?

arrays typescript

1
推荐指数
1
解决办法
4252
查看次数

Elastic Search - 计数 api 显示索引的文档总数不正确

我对弹性搜索中选定索引的文档计数有点困惑,下面是索引的片段

GET /_cat/indices/zipkin-span-2020-07-30?v

health status index                  uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   zipkin-span-2020-07-30 STcY29kkT3W7Y0XybbfVTQ   1   1     264996            0     88.9mb         88.9mb
Run Code Online (Sandbox Code Playgroud)

它显示文档计数为 264996,而当我点击以下请求时,它显示的记录很少(最多 20 条记录)

GET /zipkin-span-2020-07-30/_search

{"took":774,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},
"hits":{"total":{"value":10000,"relation":"gte"},"max_score":1.0,"hits":[{.... records.....}]}}
Run Code Online (Sandbox Code Playgroud)

注意 - 我也尝试过使用滚动 api,但仍然显示相同的输出。问题 -

  1. 这个问题与重复记录有关吗?
  2. 此计数是否也考虑副本记录?

search elasticsearch zipkin elasticsearch-7

1
推荐指数
1
解决办法
6610
查看次数