Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.provider.springmvc.reference;

import java.net.URI;

import org.springframework.web.client.RestTemplate;

public abstract class AcceptableRestTemplate extends RestTemplate {
abstract boolean isAcceptable(String uri);
abstract boolean isAcceptable(URI uri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package io.servicecomb.provider.springmvc.reference;

import java.lang.reflect.Type;
import java.net.URI;
import java.util.Arrays;

import org.springframework.web.client.CseHttpMessageConverter;
import org.springframework.web.client.RequestCallback;
import org.springframework.web.client.RestTemplate;

public class CseRestTemplate extends RestTemplate {
import io.servicecomb.common.rest.RestConst;

public class CseRestTemplate extends AcceptableRestTemplate {
public CseRestTemplate() {
setMessageConverters(Arrays.asList(new CseHttpMessageConverter()));
setRequestFactory(new CseClientHttpRequestFactory());
Expand All @@ -43,4 +45,14 @@ protected <T> RequestCallback httpEntityCallback(Object requestBody, Type respon
CseRequestCallback cseCallback = new CseRequestCallback(requestBody, callback);
return cseCallback;
}

@Override
boolean isAcceptable(String uri) {
return uri.startsWith(RestConst.URI_PREFIX);
}

@Override
boolean isAcceptable(URI uri) {
return RestConst.SCHEME.equals(uri.getScheme());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.provider.springmvc.reference;

import java.net.URI;

public class DefaultAcceptableRestTemplate extends AcceptableRestTemplate {
@Override
boolean isAcceptable(String uri) {
return true;
}

@Override
boolean isAcceptable(URI uri) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
import org.springframework.web.client.RestTemplate;

public final class RestTemplateBuilder {
private static RestTemplateWrapper wrapper = new RestTemplateWrapper();

private RestTemplateBuilder() {
}

public static RestTemplate create() {
return new RestTemplateWrapper();
return wrapper;
}

public static void addAcceptableRestTemplate(AcceptableRestTemplate restTemplate) {
wrapper.addAcceptableRestTemplate(restTemplate);
}
}
Loading