小编Gab*_*iel的帖子

Spring Boot OAuth2在1.4.1版上无法正常运行

我在Spring OAuth2上使用Spring Boot 1.4.0.当我请求令牌时,服务器响应是:

  {
  "access_token": "93f8693a-22d2-4139-a4ea-d787f2630f04",
  "token_type": "bearer",
  "refresh_token": "2800ea24-bb4a-4a01-ba87-2d114c1a2235",
  "expires_in": 899,
  "scope": "read write"
  }
Run Code Online (Sandbox Code Playgroud)

当我将项目更新到Spring Boot 1.4.1时,服务器响应变为

  {
  "error": "invalid_client",
  "error_description": "Bad client credentials"
  }
Run Code Online (Sandbox Code Playgroud)

什么从版本1.4.0更改为1.4.1?我应该怎样做才能让我的请求再次发挥作用?

编辑

WebSecurityConfiguration:

 @Configuration
 @EnableWebSecurity
 public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{

 /** The client details service. */
    @Autowired
    private ClientDetailsService clientDetailsService;

    /** The password encoder. */
    @Autowired
    private PasswordEncoder passwordEncoder;

    /** The custom authentication provider. */
    @Autowired
    private CustomAuthenticationProvider customAuthenticationProvider;

    /** The o auth 2 token store service. */
    @Autowired
    private OAuth2TokenStoreService oAuth2TokenStoreService; …
Run Code Online (Sandbox Code Playgroud)

java spring-security spring-boot spring-security-oauth2

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

声纳:可能的nullpointer?

我不知道为什么Sonar认为在下一行中可能会出现NullPointer异常:

if (file == null || file.listFiles() == null || file.listFiles().length == 0) {//etc}
Run Code Online (Sandbox Code Playgroud)

你们有什么想法吗?

java exception nullpointerexception sonarqube

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

使用 GridFs 在 MongoDB 中存储 16MB 以下的文件是个好主意吗?

我知道 MongoDB 文档最多只支持 16MB。如果我想存储大于这个值的文件,我应该使用 GridFs。低于这个,他们建议改用 BSON。

我做了一个测试,保存了 33000 个文件,每个文件 10MB,使用 BSON 保存 16500 个文件,使用 GridFs 保存 16500 个文件。我使用 BSON 与 GridFs 保存和获取最后 10 个文件的结果是:

保存最后 10 个文件

为了检索最后 10 个文件,我得到了以下结果:

获取最后 10 个文件

考虑到性能,对于小于 16MB 的文件使用 GridFs 似乎仍然比使用 BSON 好。所以,问题是:为了保存任何文件(无论其大小),最好使用 GridFs?或者对于 16MB 以下的文件,应该使用 BSON 的另一个我不知道的原因?

mongodb bson gridfs

6
推荐指数
0
解决办法
470
查看次数

GestureDetector + ItemClick RecyclerView 不能一起工作

我已经找过好几次了,但我认为没有人面临着我现在面临的同样的问题。我有以下片段:

XML 片段

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">


<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical" />


</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

RecyclerView XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
    android:id="@+id/icon"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textAlignment="center"
    />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

JAVA 代码片段

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    View viewRoot = inflater.inflate(R.layout.fragment_xml, container, false);
    recyclerView = (RecyclerView) viewRoot.findViewById(R.id.recyclerview_id);

    recyclerView.setOnTouchListener(new OnSwipeTouchListener(getActivity()) {
        @Override
        public void onSwipeRight() {
            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            ft.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, …
Run Code Online (Sandbox Code Playgroud)

java android

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

Java 8 ToLongFunction何时应该使用它?

Java 8现在具有功能接口,例如ToLongFunction,它将其参数转换为long值.

我看到一个例子如下面的代码:

ToLongFunction<String> i  = (x)-> Long.parseLong(x);

System.out.println(i.applyAsLong("2"));
Run Code Online (Sandbox Code Playgroud)

问题是:为什么我要实现一个接口只是为了将一个变量转换为一个基元long,只需要调用方法Long.parseLong(x)就更简单易读了?

java java-8

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

Spring Rest with Spring Boot:上传 MultipartFile 和 Json 对象作为参数

我知道这个问题之前曾在 stackoverflow 上被问过。但是,我还没有找到使用 Postman 等实际测试服务的答案。

我遵循了文档,我的服务与文档中描述的几乎相同:

@PostMapping("/someUrl")
public ResponseEntity<Void> uploadFile(@RequestPart(name="foo", required = false) Foo foo, @RequestPart("file") MultipartFile file) {
    return new ResponseEntity<>(OK);
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用 Postman 加热我的服务时,出现以下错误:

org.springframework.web.multipart.MultipartException:当前请求不是多部分请求

在邮递员那里,我得到了以下回报

邮差

问题是:是否可以使用 Postman 调用我的服务?如果是,我缺少哪些参数?

java rest spring spring-boot

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

如何在Mule上添加1个以上的cookie?

我能够通过Mule ESB在请求的响应中添加1个cookie.但是,当我尝试使用属性"Set-Cookie"添加多个cookie时,Mule会覆盖第一个cookie并返回第二个cookie.

例如,在下面的代码片段中,我在message属性上添加了2个cookie(这是一个映射).

`String msg =  "SSID=123;domain=localhost;Path=/";
 String msg2 =  "SSAPID=456;domain=localhost;Path=/";
 message.setProperty(HttpHeaders.Names.SET_COOKIE,msg, PropertyScope.OUTBOUND);
 message.setProperty(HttpHeaders.Names.SET_COOKIE,msg2, PropertyScope.OUTBOUND);
`
Run Code Online (Sandbox Code Playgroud)

当我收到回复时,只有一个cookie:

  Message properties:
  OUTBOUND scoped properties:
    Set-Cookie=SAPID=456
    access-control-allow-credentials=true
    access-control-allow-headers=Origin, X-Requested-With, Content-Type, Accept, Cache, X-Auth-Token
    access-control-allow-methods=PATCH, PUT, POST, GET, OPTIONS, DELETE
    access-control-allow-origin=*
    access-control-max-age=10
    cache-control=no-store
    content-encoding=gzip
    content-type=application/json;charset=UTF-8
    date=Wed, 13 Jan 2016 12:26:58 GMT
    http.reason=OK
    http.status=200
    pragma=no-cache
    server=Apache-Coyote/1.1
    transfer-encoding=chunked
    vary=[Accept-Encoding, Accept-Encoding]
    x-content-type-options=nosniff
    x-xss-protections=1; mode=block
  SESSION scoped properties:
Run Code Online (Sandbox Code Playgroud)

Set-Cookie = SAPID = 456

如您所见,请求中仅返回了第二个cookie.

我怎样才能实现我想做的事情,因为这里描述的cookie规范https://tools.ietf.org/html/rfc6265#section-3.1说我可以在响应中返回超过1个Set-Cookie头.

服务器可以通过返回两个Set-Cookie头字段来存储会话标识符以及用户的首选语言

cookies mule

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