Skip to content

Commit

Permalink
Fix GroupVersionCondition bug & Refine exception message process
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Jul 30, 2024
1 parent 3a72599 commit 42f4d60
Show file tree
Hide file tree
Showing 66 changed files with 855 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class RestConfig implements Serializable {
* If enabled, a method mapped to "/users" also matches to "/users/".
* <p>The default value is {@code true}.
*/
private boolean trailingSlashMatch;
private Boolean trailingSlashMatch;

/**
* Whether path matching uses suffix pattern matching (".*").
Expand All @@ -41,14 +41,14 @@ public class RestConfig implements Serializable {
* inferred from the URL suffix, e.g., ".json" for "application/json".
* <p>The default value is {@code true}.
*/
private boolean suffixPatternMatch;
private Boolean suffixPatternMatch;

/**
* Whether path matching should be case-sensitive.
* If enabled, a method mapped to "/users" won't match to "/Users/".
* <p>The default value is {@code true}.
*/
private boolean caseSensitiveMatch;
private Boolean caseSensitiveMatch;

/**
* The parameter name that can be used to specify the response format.
Expand All @@ -62,27 +62,27 @@ public class RestConfig implements Serializable {
@Nested
private CorsConfig cors;

public boolean isTrailingSlashMatch() {
public Boolean getTrailingSlashMatch() {
return trailingSlashMatch;
}

public void setTrailingSlashMatch(boolean trailingSlashMatch) {
public void setTrailingSlashMatch(Boolean trailingSlashMatch) {
this.trailingSlashMatch = trailingSlashMatch;
}

public boolean isSuffixPatternMatch() {
public Boolean getSuffixPatternMatch() {
return suffixPatternMatch;
}

public void setSuffixPatternMatch(boolean suffixPatternMatch) {
public void setSuffixPatternMatch(Boolean suffixPatternMatch) {
this.suffixPatternMatch = suffixPatternMatch;
}

public boolean isCaseSensitiveMatch() {
public Boolean getCaseSensitiveMatch() {
return caseSensitiveMatch;
}

public void setCaseSensitiveMatch(boolean caseSensitiveMatch) {
public void setCaseSensitiveMatch(Boolean caseSensitiveMatch) {
this.caseSensitiveMatch = caseSensitiveMatch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,49 @@
@DubboService
public class GreeterServiceImpl implements GreeterService {

private static final Logger LOG = LoggerFactory.getLogger(GreeterServiceImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(GreeterServiceImpl.class);

@Override
public HelloReply sayHello(HelloRequest request) {
LOG.info("Received sayHello request: {}", request.getName());
LOGGER.info("Received sayHello request: {}", request.getName());
return toReply("Hello " + request.getName());
}

@Override
public CompletableFuture<String> sayHelloAsync(String name) {
LOG.info("Received sayHelloAsync request: {}", name);
LOGGER.info("Received sayHelloAsync request: {}", name);
return CompletableFuture.supplyAsync(() -> "Hello " + name);
}

@Override
public void sayHelloServerStream(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
LOG.info("Received sayHelloServerStream request");
LOGGER.info("Received sayHelloServerStream request");
for (int i = 1; i < 6; i++) {
LOG.info("sayHelloServerStream onNext: {} {} times", request.getName(), i);
LOGGER.info("sayHelloServerStream onNext: {} {} times", request.getName(), i);
responseObserver.onNext(toReply("Hello " + request.getName() + ' ' + i + " times"));
}
LOG.info("sayHelloServerStream onCompleted");
LOGGER.info("sayHelloServerStream onCompleted");
responseObserver.onCompleted();
}

@Override
public StreamObserver<HelloRequest> sayHelloBiStream(StreamObserver<HelloReply> responseObserver) {
LOG.info("Received sayHelloBiStream request");
LOGGER.info("Received sayHelloBiStream request");
return new StreamObserver<HelloRequest>() {
@Override
public void onNext(HelloRequest request) {
LOG.info("sayHelloBiStream onNext: {}", request.getName());
LOGGER.info("sayHelloBiStream onNext: {}", request.getName());
responseObserver.onNext(toReply("Hello " + request.getName()));
}

@Override
public void onError(Throwable throwable) {
LOG.error("sayHelloBiStream onError", throwable);
LOGGER.error("sayHelloBiStream onError", throwable);
}

@Override
public void onCompleted() {
LOG.info("sayHelloBiStream onCompleted");
LOGGER.info("sayHelloBiStream onCompleted");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.dubbo.rpc.protocol.tri.h12" level="debug"/>
<Logger name="org.apache.dubbo.rpc.protocol.tri.rest" level="debug"/>
<Logger name="org.apache.dubbo.remoting.http12" level="debug"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,49 @@

public class GreeterServiceImpl implements GreeterService {

private static final Logger LOG = LoggerFactory.getLogger(GreeterServiceImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(GreeterServiceImpl.class);

@Override
public HelloReply sayHello(HelloRequest request) {
LOG.info("Received sayHello request: {}", request.getName());
LOGGER.info("Received sayHello request: {}", request.getName());
return toReply("Hello " + request.getName());
}

@Override
public CompletableFuture<String> sayHelloAsync(String name) {
LOG.info("Received sayHelloAsync request: {}", name);
LOGGER.info("Received sayHelloAsync request: {}", name);
return CompletableFuture.supplyAsync(() -> "Hello " + name);
}

@Override
public void sayHelloServerStream(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
LOG.info("Received sayHelloServerStream request");
LOGGER.info("Received sayHelloServerStream request");
for (int i = 1; i < 6; i++) {
LOG.info("sayHelloServerStream onNext: {} {} times", request.getName(), i);
LOGGER.info("sayHelloServerStream onNext: {} {} times", request.getName(), i);
responseObserver.onNext(toReply("Hello " + request.getName() + ' ' + i + " times"));
}
LOG.info("sayHelloServerStream onCompleted");
LOGGER.info("sayHelloServerStream onCompleted");
responseObserver.onCompleted();
}

@Override
public StreamObserver<HelloRequest> sayHelloBiStream(StreamObserver<HelloReply> responseObserver) {
LOG.info("Received sayHelloBiStream request");
LOGGER.info("Received sayHelloBiStream request");
return new StreamObserver<HelloRequest>() {
@Override
public void onNext(HelloRequest request) {
LOG.info("sayHelloBiStream onNext: {}", request.getName());
LOGGER.info("sayHelloBiStream onNext: {}", request.getName());
responseObserver.onNext(toReply("Hello " + request.getName()));
}

@Override
public void onError(Throwable throwable) {
LOG.error("sayHelloBiStream onError", throwable);
LOGGER.error("sayHelloBiStream onError", throwable);
}

@Override
public void onCompleted() {
LOG.info("sayHelloBiStream onCompleted");
LOGGER.info("sayHelloBiStream onCompleted");
}
};
}
Expand Down
3 changes: 3 additions & 0 deletions dubbo-demo/dubbo-demo-triple/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.dubbo.rpc.protocol.tri.h12" level="debug"/>
<Logger name="org.apache.dubbo.rpc.protocol.tri.rest" level="debug"/>
<Logger name="org.apache.dubbo.remoting.http12" level="debug"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ParameterMeta;
import org.apache.dubbo.rpc.protocol.tri.rest.util.AbstractRestToolKit;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.ParamConverter;

final class JaxrsRestToolKit extends AbstractRestToolKit {
Expand All @@ -46,19 +44,11 @@ public int getDialect() {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Object convert(Object value, ParameterMeta parameter) {
if (MultivaluedMap.class.isAssignableFrom(parameter.getType())) {
if (value instanceof MultivaluedMap) {
return value;
}
return typeConverter.convert(value, MultivaluedHashMap.class);
}

ParamConverter converter = paramConverterFactory.getParamConverter(
parameter.getType(), parameter.getGenericType(), parameter.getRawAnnotations());
if (converter != null) {
return value instanceof String ? converter.fromString((String) value) : converter.toString(value);
}

return super.convert(value, parameter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.protocol.tri.rest.support.jaxrs;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.protocol.tri.rest.argument.ArgumentConverter;
import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ParameterMeta;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;

@Activate(onClass = "javax.ws.rs.core.MultivaluedMap")
public class MultivaluedMapCreator implements ArgumentConverter<Integer, MultivaluedMap<?, ?>> {

@Override
public MultivaluedMap<?, ?> convert(Integer value, ParameterMeta parameter) {
return new MultivaluedHashMap<>(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multivalued-map-creator=org.apache.dubbo.rpc.protocol.tri.rest.support.jaxrs.MultivaluedMapCreator
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,17 @@ class RestProtocolTest extends BaseServiceTest {
path | output
'/convertTest?user=3,sam' | '{"id":3,"name":"sam"}'
}

def "MultivaluedMap test"() {
expect:
TestRequest request = new TestRequest(
path: path,
contentType: MediaType.APPLICATION_FROM_URLENCODED,
body: body
)
runner.post(request) == output
where:
path | body | output
'/multivaluedMapTest' | 'name=1&name=2&age=8' | '{"name":[1,2],"age":[8]}'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MultivaluedMap;

import org.jboss.resteasy.annotations.Form;

Expand All @@ -37,4 +38,8 @@ public interface JaxrsDemoService {
@GET
@Path("/convertTest")
User convertTest(@QueryParam("user") User user);

@POST
@Path("/multivaluedMapTest")
MultivaluedMap<String, Integer> multiValueMapTest(MultivaluedMap<String, Integer> params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.dubbo.rpc.protocol.tri.rest.support.jaxrs.service;

import javax.ws.rs.core.MultivaluedMap;

public class JaxrsDemoServiceImpl implements JaxrsDemoService {

@Override
Expand All @@ -32,4 +34,9 @@ public User getTest(User user) {
public User convertTest(User user) {
return user;
}

@Override
public MultivaluedMap<String, Integer> multiValueMapTest(MultivaluedMap<String, Integer> params) {
return params;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.dubbo.rpc.protocol.tri.stream.StreamUtils" level="error"/>
<Logger name="org.apache.dubbo.rpc.protocol.tri.h12" level="debug"/>
<Logger name="org.apache.dubbo.rpc.protocol.tri.rest" level="debug"/>
<Logger name="org.apache.dubbo.remoting.http12" level="debug"/>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.rpc.protocol.tri.rest.support.spring;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.protocol.tri.rest.argument.ArgumentConverter;
import org.apache.dubbo.rpc.protocol.tri.rest.mapping.meta.ParameterMeta;

import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

@Activate(onClass = "org.springframework.util.MultiValueMap")
public class MultiValueMapCreator implements ArgumentConverter<Integer, MultiValueMap<?, ?>> {

@Override
public MultiValueMap<?, ?> convert(Integer value, ParameterMeta parameter) {
return new LinkedMultiValueMap<>(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected Object resolveValue(NamedValueMeta meta, HttpRequest request, HttpResp

@Override
protected Object resolveCollectionValue(NamedValueMeta meta, HttpRequest request, HttpResponse response) {
return request.parts();
return meta.type() == byte[].class ? request.part(meta.name()) : request.parts();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multi-value-map-creator=org.apache.dubbo.rpc.protocol.tri.rest.support.spring.MultiValueMapCreator
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ class RestProtocolTest extends BaseServiceTest {
'/spring/beanBodyTest?age=2' | '[{"id":1,"name":"g1"},{"id":2,"name":"g2"}]' | '[{"id":1,"name":"g1"},{"id":2,"name":"g2"}]'
}

def "multiValueMap test"() {
expect:
runner.get(path) contains output
where:
path | output
'/spring/multiValueMapTest?name=1&name=2&age=8' | '{"name":[1,2],"age":[8]}'
}

def "urlEncodeForm test"() {
given:
def request = new TestRequest(
Expand Down
Loading

0 comments on commit 42f4d60

Please sign in to comment.