我在Zuul有一个场景,URL路由的服务也可能已关闭.因此,响应主体在JSON主体响应中被抛出500 HTTP Status和ZuulException.
{
"timestamp": 1459973637928,
"status": 500,
"error": "Internal Server Error",
"exception": "com.netflix.zuul.exception.ZuulException",
"message": "Forwarding error"
}
Run Code Online (Sandbox Code Playgroud)
我想要做的就是自定义或删除JSON响应,并可能更改HTTP状态代码.
我试图用@ControllerAdvice创建一个异常处理程序,但处理程序没有抓住异常.
更新:
所以我扩展了Zuul过滤器,我可以看到它在执行错误后进入run方法,然后如何更改响应.以下是我到目前为止所得到的.我在某处读到了有关SendErrorFilter的内容,但我如何实现它以及它做了什么?
public class CustomFilter extends ZuulFilter {
@Override
public String filterType() {
return "post";
}
@Override
public int filterOrder() {
return 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
final RequestContext ctx = RequestContext.getCurrentContext();
final HttpServletResponse response = ctx.getResponse();
if (HttpStatus.INTERNAL_SERVER_ERROR.value() == ctx.getResponse().getStatus()) {
try {
response.sendError(404, "Error Error"); //trying to change …Run Code Online (Sandbox Code Playgroud) 所以我将Hystrix-AMQP的依赖项添加到我的服务中,日志文件变得疯狂,它只是继续记录指标的东西.我需要那个罐子才能将它与涡轮AMQP一起使用.
这是我在hystrix的gradle中所拥有的: -
compile ("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.6.RELEASE")
compile ('org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.6.RELEASE')
compile ('org.springframework.cloud:spring-cloud-netflix-hystrix-amqp:1.0.7.RELEASE')
compile ('com.netflix.hystrix:hystrix-javanica:1.5.2')
Run Code Online (Sandbox Code Playgroud)
这是继续在我的日志中生成它继续运行: -
2016-05-03 13:49:14.698 INFO [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Continued span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Stopped span: MilliSpan(begin=1462308554698, end=1462308554698, name=execution(HystrixStreamTask.sendMetrics()), traceId=21825112-0c71-4c6a-a9ca-51b11a21e4e5, parents=[], spanId=053946b5-7287-41f4-8579-d048655f41ea, remote=false, annotations={/messaging/headers/id=e1cc5042-1a5c-e3f9-6f3c-de936d1aa959, /messaging/headers/timestamp=1462308554698, /messaging/payload/type=java.lang.String, /messaging/payload/size=592}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.698 INFO [LogMessage=Starting span: MilliSpan(begin=1462308554698, end=0, name=execution(HystrixStreamTask.gatherMetrics()), traceId=6cc342bb-9693-493a-8fa8-8a17c2ff06c3, parents=[], spanId=10cdee69-22f8-43ab-883f-3e09b29ab6fb, remote=false, annotations={}, processId=null, timelineAnnotations=[])]
2016-05-03 13:49:14.699 INFO [LogMessage=Continued …Run Code Online (Sandbox Code Playgroud) 我正在调用bitbucket API来获取repo中的所有文件.我已达到这样的程度,我可以获取repo中所有文件夹的列表,并对repo中的所有根文件夹进行第一次API调用,并获取所有文件夹的前1000个文件列表.
但问题是bitbucket api一次只能给我每个文件夹1000个文件.
我需要附加一个查询参数&start = nextPageStart并再次进行调用,直到它为null并且每个API的isLastPage为true.如何使用以下代码实现这一目标?
我从第一次调用api获得nextPageStart.请参阅下面的API响应.
下面是我到目前为止的代码.
任何帮助或指导表示赞赏.
来自每个文件夹调用的各个API的响应.
{
"values": [
"/src/js/abc.js",
"/src/js/efg.js",
"/src/js/ffg.js",
...
],
"size": 1000,
"isLastPage": false,
"start": 0,
"limit": 1000,
"nextPageStart": 1000
}
Run Code Online (Sandbox Code Playgroud)
函数,我进行异步调用以获取文件列表
export function getFilesList() {
const foldersURL: any[] = [];
getFoldersFromRepo().then((response) => {
const values = response.values;
values.forEach((value: any) => {
//creating API URL for each folder in the repo
const URL = 'https://bitbucket.abc.com/stash/rest/api/latest/projects/'
+ value.project.key + '/repos/' + value.slug + '/files?limit=1000';
foldersURL.push(URL);
});
return foldersURL;
}).then((res) => {
// …Run Code Online (Sandbox Code Playgroud) 我在反应应用程序中使用auth0进行LinkedIn身份验证.我在设置localhost:3000/upload中设置了回调网址,在用户登录后localhost:3000/login跳转,他们将重定向到localhost:3000/upload.但是,我总是收到此错误:url localhost:3000/login不在回调网址列表中.为什么auth0会在登录后返回到您刚刚登录的页面.不应该是一些不同的URL.它对我来说没有意义.
编辑:
export default class AuthService {
constructor(clientId, domain) {
// Configure Auth0
const options = {
allowedConnections: ['linkedin'],
auth: {
params: {responseType: 'code'}
}
};
this.lock = new Auth0Lock(clientId, domain, options)
// Add callback for lock `authenticated` event
this.lock.on('authenticated', this._doAuthentication.bind(this))
// binds login functions to keep this context
this.login = this.login.bind(this)
this.loggedIn = this.loggedIn.bind(this)
}
_doAuthentication(authResult){
// Saves the user token
console.log(authResult);
this.setToken(authResult.idToken)
this.lock.getProfile(authResult.idToken, (error, profile) => {
if (error) { …Run Code Online (Sandbox Code Playgroud) 我正在部署一个使用 next.js 到 openshift 的节点项目,我在其中设置了环境变量 MY_ENV。我已将publicRuntimeConfig配置添加到 next.config.js 以访问它的客户端。它在我的本地工作,但是当它的容器化和部署publicRuntimeConfig是undefined.
这是我从 next.config.js 的配置
module.exports = {
publicRuntimeConfig: { // Will be available on both server and client
isProd: process.env.MY_ENV ? process.env.MY_ENV.includes('prod'): false,
isStaging: process.env.MY_ENV ? process.env.MY_ENV.includes('staging') : false
},
webpack: (config, { dev }) => {
const eslintRule = {
test: /\.js$/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: dev,
},
};
const cssRule = {
test: /\.css$/,
use: {
loader: 'css-loader',
options: { …Run Code Online (Sandbox Code Playgroud) 我正在尝试实施Turbine AMQP来整合从多个服务到Hystrix Dashboard的所有流.
所以我在gradle文件中添加了几个依赖项,之后由于某种原因我无法启动我的应用程序.
来自启动的LOGS,我看到异常.
[LogMessage=Application startup failed]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bindingService' defined in class path resource [org/springframework/cloud/stream/config/ChannelBindingServiceConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.cloud.stream.binder.BinderFactory]: Error creating bean with name 'binderFactory' defined in class path resource [org/springframework/cloud/stream/config/BinderFactoryConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.cloud.stream.binder.BinderTypeRegistry]: Error creating bean with name 'binderTypeRegistry' defined in class path resource [org/springframework/cloud/stream/config/BinderFactoryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed …Run Code Online (Sandbox Code Playgroud) turbine spring-boot hystrix spring-cloud spring-cloud-stream
简单我有一个看起来像这样的对象,它直接从我的chrome浏览器中的存储过程返回.我怎样才能删除那些说null出来的javascript/angular 2?
我正在使用微服务架构构建Rest api.我有多个api用户,我们已经进入多个项目.除了我无法将面向用户的用户映射到zuul中的应用程序URL之外,我还准备好了其他所有内容.
面向网址的用户是:user/v1/accountholders/{id}/cards,我的应用程序的实际网址是/ user-cards/v1/accountholders/{id}/cards.
这里的id是路径变量.下面是其他类似的api url,所以如果有一种方法在zuul中一般配置它们.此外,应用程序URL的上下文根也是Eureka中的项目名称.
Other similar urls are:
client side:- /user/v1/accountholders/{id}/cards/{cardid}
application:- /user-cards/v1/accountholders/{id}/cards/{cardid}
client side:- /user/v1/accountholders
application:- /user-cardholder/v1/accountholder
client side:- /user/v1/accountholders
application:- /user-cardholder/v1/accountholder
client side:- /user/v1/accountholders/{id}
application:- /user-cardholder/v1/accountholders/{id}
client side:- /user/v1/accountholders/{id}/accounts
application:- /user-accounts/v1/accountholders/{id}/accounts
client side:- /user/v1/accountholders/{id}/accounts/{accid}
application:- /user-accounts/v1/accountholders/{id}/accounts/{accid}
Run Code Online (Sandbox Code Playgroud)
需要一些帮助来在zuul的属性或yml文件中进行设置.我还没有能够在映射中取得任何进展.任何输入都会有所帮助.
解决: - 从@Daniel获得输入后(这是接受的答案)这是我在zuul配置中使用的: -
zuul:
routes:
User-Cards:
path: /user/v1/accountholders/*/cards/**
url: http://desktop-uvkv1ed:9999/user-cards/v1/accountholders
User-Transactions1:
path: /user/v1/accountholders/*/transactions
url: http://desktop-uvkv1ed:5555/user-transactions/v1/accountholders
service-id: User-Transactions
User-Transactions2:
path: /user/v1/accountholders/*/accounts/*/transactions
url: http://desktop-uvkv1ed:5555/user-transactions/v1/accountholders
service-id: User-Transactions
User-Accounts:
path: /user/v1/accountholders/*/accounts/**
url: http://desktop-uvkv1ed:7777/user-accounts/v1/accountholders
User-Cardholders:
path: /user/v1/accountholders/**
url: http://desktop-uvkv1ed:8888/user-cardholders/v1/accountholders
Run Code Online (Sandbox Code Playgroud) spring-boot microservices spring-cloud netflix-eureka netflix-zuul
我的微服务需要使用双向 ssl。每个微服务都是一个 Spring Boot 应用程序,注释为:
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
@EnableZuulProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
每个 yml 对 eureka/ribbon 都有类似的配置:
eureka:
client:
service-url:
defaultZone: ${EUREKA_CLIENT_SERVICEURL_PROTOCOL:http}://${EUREKA_CLIENT_SERVICEURL_HOST:192.168.99.100}:${EUREKA_CLIENT_SERVICEURL_PORT:8761}/eureka/
instance:
secure-virtual-host-name: ${spring.application.name}
prefer-ip-address: true
non-secure-port-enabled: ${EUREKA_NON_SECURE_PORT_ENABLED:false}
secure-port-enabled: ${EUREKA_SECURE_PORT_ENABLED:true}
secure-port: ${server.port}
ribbon:
IsSecure: true
eureka:
enabled: true
Run Code Online (Sandbox Code Playgroud)
每个微服务都有一个控制器,该控制器公开用于各种功能的 REST API。
当一个微服务需要调用另一个微服务端点时,我尝试通过创建该微服务的客户端接口来实现:
@FeignClient(name = "user", configuration = FeignConfiguration.class, url = "https://user")
public interface UserClient {
@RequestMapping(method = RequestMethod.GET, value = "/test")
String testUser();
}
Run Code Online (Sandbox Code Playgroud)
这是 Feign 配置:
@Configuration …Run Code Online (Sandbox Code Playgroud) 我已经用MongoDB Image设置了一个docker。默认情况下,没有设置密码。我创建了一个用户并为其分配了角色,效果很好。但是问题在于,无需身份验证仍然可以建立连接。
使用身份验证>正确的用户名,正确的密码->已连接进行连接
使用身份验证连接>用户名正确,密码错误->连接失败
未经身份验证的连接>已连接
我要第三点停止工作。
spring-cloud ×5
javascript ×3
spring-boot ×3
docker ×2
hystrix ×2
java ×2
netflix-zuul ×2
node.js ×2
reactjs ×2
amqp ×1
angular ×1
async.js ×1
auth0 ×1
mongodb ×1
netflix ×1
next.js ×1
node-request ×1
object ×1
openshift ×1
spring ×1
turbine ×1
typescript ×1