当前位置: 首页>>代码示例>>Java>>正文


Java RequestContext.addZuulRequestHeader方法代码示例

本文整理汇总了Java中com.netflix.zuul.context.RequestContext.addZuulRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java RequestContext.addZuulRequestHeader方法的具体用法?Java RequestContext.addZuulRequestHeader怎么用?Java RequestContext.addZuulRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.netflix.zuul.context.RequestContext的用法示例。


在下文中一共展示了RequestContext.addZuulRequestHeader方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();

    Object token = request.getHeaders("token");

    //校验token
    if (token == null || "".equals(token)) {
        logger.info("token为空,禁止访问!");
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        return null;
    } else {
        ctx.setSendZuulResponse(true);
        ctx.setResponseStatusCode(200);
    }

    //添加Basic Auth认证信息
    ctx.addZuulRequestHeader("Authorization", "Basic " + getBase64Credentials("app01", "*****"));

    return null;
}
 
开发者ID:kenly333,项目名称:service-hive,代码行数:24,代码来源:AccessTokenFilter.java

示例2: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
/**
 * filter 具体的逻辑
 */
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    String uri = request.getRequestURI();
    if (uri.equals("/hi-service/upload") || uri.equals("/zuul/hi-service/upload")) {
        return ctx;
    }
    String token = request.getHeader("x-auth-token");
    if (StringUtils.isEmpty(token)) {
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        ctx.setResponseBody("no token");
        return null;
    }
    if (!TOKEN_AUTH.equals(token)) {
        ctx.setSendZuulResponse(false);
        ctx.setResponseStatusCode(401);
        ctx.setResponseBody("token auth fail");
        return null;
    }
    ctx.addZuulRequestHeader("userInfo", "{\"name\":\"Tom\",\"age\":18}");
    return ctx;
}
 
开发者ID:yangdd1205,项目名称:spring-cloud-master,代码行数:28,代码来源:CustomAuthFilter.java

示例3: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
	RequestContext context = RequestContext.getCurrentContext();

	HttpSession session = RequestContext.getCurrentContext().getRequest().getSession(false);
	if (session == null) {
		return null;
	}

	AccessTokenRepresentation token = JSON.parse((String) session.getAttribute("token"), AccessTokenRepresentation.class);
	if (token != null) {
		context.addZuulRequestHeader("Authorization", "Bearer " + token.getAccessToken());
	}

	return null;
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:17,代码来源:AuthorizationHeaderFilter.java

示例4: saveHeadersAsInvocationContext

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void saveHeadersAsInvocationContext(RequestContext ctx, Span span) {
  try {
    ctx.addZuulRequestHeader(CSE_CONTEXT, JsonUtils.writeValueAsString(ctx.getZuulRequestHeaders()));
  } catch (JsonProcessingException e) {
    clientHandler.handleReceive(ctx.getResponse(), e, span);
    throw new IllegalStateException("Unable to write request headers as json to " + CSE_CONTEXT, e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:9,代码来源:TracePreZuulFilter.java

示例5: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
  RequestContext ctx = RequestContext.getCurrentContext();
  ctx.addZuulRequestHeader(SRC_MICROSERVICE, microserviceName);
  saveHeadersAsInvocationContext(ctx);
  return null;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:ContextHeaderZuulFilter.java

示例6: saveHeadersAsInvocationContext

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void saveHeadersAsInvocationContext(RequestContext ctx) {
  try {
    ctx.addZuulRequestHeader(CSE_CONTEXT, JsonUtils.writeValueAsString(ctx.getZuulRequestHeaders()));
  } catch (JsonProcessingException e) {
    throw new IllegalStateException("Unable to write request headers as json to " + CSE_CONTEXT, e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:ContextHeaderZuulFilter.java

示例7: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    String protocol = ctx.getRequest().getScheme();
    ctx.addZuulRequestHeader(HEADER_SCHEME, protocol);
    String domain = ctx.getRequest().getServerName();
    ctx.addZuulRequestHeader(HEADER_DOMAIN, domain);
    String port = String.valueOf(ctx.getRequest().getServerPort());
    ctx.addZuulRequestHeader(HEADER_PORT, port);

    String tenant = tenantMappingService.getTenants().get(domain);
    if (StringUtils.isBlank(tenant)) {
        log.debug("Domain Proxy Filter: no mapping for domain: {}", domain);
        tenant = DEFAULT_TENANT;
    }
    ctx.addZuulRequestHeader(HEADER_TENANT, tenant);
    String referer = ctx.getRequest().getHeader("referer");
    String webapp = null;
    try {
        URL url = new URL(referer);
        URI uri = new URI(url.getProtocol(), url.getAuthority(), null, null, null);
        webapp = uri.toString();
    } catch (Exception e) {
        log.debug("Error while running", e);
    }
    ctx.addZuulRequestHeader(HEADER_WEBAPP_URL, webapp);

    return null;
}
 
开发者ID:xm-online,项目名称:xm-gate,代码行数:30,代码来源:DomainRelayFilter.java

示例8: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext context = RequestContext.getCurrentContext();
    context.addZuulRequestHeader("Code-Couple-Header", "CodeCouple!");
    return null;
}
 
开发者ID:kchrusciel,项目名称:Spring-Boot-Examples,代码行数:7,代码来源:CustomFilter.java

示例9: doFilter

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
private void doFilter(RequestContext context) throws IOException, ServletException {
	HttpServletRequest request = context.getRequest();

	String path = request.getContextPath() + request.getServletPath();
	if (request.getPathInfo() != null) {
		path = path + request.getPathInfo();
	}
	logger.debug("Get the request path {}", path);
	
	
	if (path.endsWith(LOGIN_PATH) || path.endsWith(LOGOUT_PATH) || path.endsWith(LOADDB_PATH) ||
			path.contains(CONFIG_PATH) || path.contains(LOADER_PATH)) {
		// if logging in, logging out, lookup configuration, or loading the database , let the request flow
		return;
	}
	
	Cookie cookies[] = request.getCookies();
	Cookie sessionCookie = null;
	if (cookies != null) {
		for (Cookie c : cookies) {
			if (c.getName().equals(CustomerSession.SESSIONID_COOKIE_NAME)) {
				sessionCookie = c;
			}
			if (sessionCookie!=null)
				break;
		}
		String sessionId = "";
		if (sessionCookie!=null) // We need both cookie to work
			sessionId= sessionCookie.getValue().trim();
		// did this check as the logout currently sets the cookie value to "" instead of aging it out
		// see comment in LogingREST.java
		if (sessionId.equals("")) {
			logger.warn("Session id is empty");
			setFailedRequest(HttpServletResponse.SC_FORBIDDEN);
			return;
		}
		// Need the URLDecoder so that I can get @ not %40
		CustomerSession cs = getCustomerSession(sessionId);
		if (cs != null) {
			context.addZuulRequestHeader(LOGIN_USER, cs.getCustomerid());
			logger.info("Customer {} validated with session id {}", cs.getCustomerid(), sessionId);
			return;
		}
		else {
			logger.warn("No customer session found with session id {}", sessionId);
			setFailedRequest(HttpServletResponse.SC_FORBIDDEN);
			return;
		}
	}

	logger.warn("No session cookie provided");
	// if we got here, we didn't detect the session cookie, so we need to return 404
	setFailedRequest(HttpServletResponse.SC_FORBIDDEN);

}
 
开发者ID:WillemJiang,项目名称:acmeair,代码行数:56,代码来源:RESTCookieSessionFilter.java

示例10: run

import com.netflix.zuul.context.RequestContext; //导入方法依赖的package包/类
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.addZuulRequestHeader("uid", uid.toString());
    return null;
}
 
开发者ID:Clcanny,项目名称:MicroServiceDemo,代码行数:7,代码来源:ZuulFilterConfig.java


注:本文中的com.netflix.zuul.context.RequestContext.addZuulRequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。