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


Java HttpContext类代码示例

本文整理汇总了Java中com.sun.jersey.api.core.HttpContext的典型用法代码示例。如果您正苦于以下问题:Java HttpContext类的具体用法?Java HttpContext怎么用?Java HttpContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpContext类属于com.sun.jersey.api.core包,在下文中一共展示了HttpContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRun

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
protected Run createRun(Sequence<Corpus> plan, HttpContext httpContext, MultivaluedMap<String,String> formParams, FormDataMultiPart formData, AlvisNLPExecutor executor, String... excludedParams) throws IOException {
	Run result = new Run(rootProcessingDir, plan, executor);
	if (formData != null) {
		setFormParams(formData, result, excludedParams);
	}
	if (formParams != null) {
		setMultivaluedMapParams(formParams, result, excludedParams);
	}
	if (httpContext != null) {
		HttpRequestContext requestContext = httpContext.getRequest();
		MultivaluedMap<String,String> params = requestContext.getQueryParameters();
		setMultivaluedMapParams(params, result, excludedParams);
	}
	result.write();
	return result;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:RunLauncher.java

示例2: annotate_POST_MULTIPART

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@POST
@Path("/plans/{plan}/{sync:sync|async}")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response annotate_POST_MULTIPART(
		@Context ServletContext servletContext,
		@Context HttpContext httpContext,
		@PathParam("plan") String planName,
		@PathParam("sync") String sync,
		@FormDataParam("text") @DefaultValue("") String text,
		@FormDataParam("sourcedb") @DefaultValue("") String sourcedb,
		@FormDataParam("sourceid") @DefaultValue("") String sourceid,
		FormDataMultiPart formData
		) throws Exception {
	return annotate(servletContext, httpContext, planName, text, sourcedb, sourceid, null, formData, sync.equals("async"));
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:16,代码来源:PubAnnotation.java

示例3: annotate

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
private Response annotate(
		ServletContext servletContext,
		HttpContext httpContext,
		String planName,
		String text,
		String sourcedb,
		String sourceid,
		MultivaluedMap<String,String> formParams,
		FormDataMultiPart formData,
		boolean async
		) throws Exception {
	Sequence<Corpus> plan = planBuilder.buildPlan(planName);
	AlvisNLPExecutor executor = getExecutor(servletContext);
	Run run = createRun(plan, httpContext, formParams, formData, executor, "text", "sourcedb", "sourceid");
	injectInputText(run, text, sourcedb, sourceid);
	planBuilder.setParams(run, plan);
	planBuilder.check(plan);
	run.execute(servletContext, planBuilder, async);
	if (async) {
		return fetch(run.getId());
	}
	return createSyncRunResponse(run);
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:24,代码来源:PubAnnotation.java

示例4: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public AuthenticationVO getValue(HttpContext c) {
	// if (c.getRequest().getAuthenticationScheme() == HttpRequestContext.BASIC_AUTH) {
	String authHeaderValue = c.getRequest().getHeaderValue(HttpRequestContext.AUTHORIZATION);
	String[] credentials = null;
	if (authHeaderValue != null) {
		credentials = JsUtil.decodeBase64(authHeaderValue.replaceFirst("[B|b]asic ", "")).split(":", 2);
	}
	AuthenticationVO result;
	if (credentials != null && credentials.length == 2) {
		result = new AuthenticationVO(credentials[0], credentials[1], null, WebUtil.getRemoteHost(request));
	} else {
		result = new AuthenticationVO();
		result.setHost(WebUtil.getRemoteHost(request));
	}
	return result;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:18,代码来源:BasicAuthenticationProvider.java

示例5: if

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
/**
 * Returns the client ID from a request.  See {@link HttpMethodFilter} for an explanation of why the client ID
 * handling is the way it is.
 * @param request The request
 * @param httpContext The HTTP context of the request
 * @return The client ID extracted from the request.  For GET requests the ID comes from the {@code clientId}
 * query parameter and for POST requests it's a form parameter.
 * @see HttpMethodFilter
 */
/* package */ static String getClientId(ContainerRequest request, HttpContext httpContext) {
  List<String> clientIds = null;
  ExtendedUriInfo uriInfo = httpContext.getUriInfo();
  // try to get the client ID from the query params (for a GET request)
  MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
  clientIds = queryParameters.get(LongPollingServlet.CLIENT_ID);
  if (clientIds == null || clientIds.size() != 1) {
    // try to get the client ID from the form params (in case it's a POST request disguised as a GET)
    clientIds = httpContext.getRequest().getFormParameters().get(LongPollingServlet.CLIENT_ID, String.class);
  }
  if (clientIds == null || clientIds.size() != 1) {
    return null;
  } else {
    return clientIds.get(0);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:FilterUtils.java

示例6: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public Principal getValue(HttpContext httpContext) {
  Principal principal = httpContext.getRequest().getUserPrincipal();
  if (principal == null) {
    final String user = httpContext.getRequest().getQueryParameters().getFirst(USER_NAME_PARAM);
    if (user != null) {
      principal = new Principal() {
        @Override
        public String getName() {
          return new UserParam(user).value();
        }
      };
    }
  }
  if (principal != null) {
    MDC.put("user", principal.getName());
  }
  return principal;
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:20,代码来源:UserProvider.java

示例7: principalUser

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void principalUser() {
  MDC.remove("user");
  HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
  Mockito.when(request.getUserPrincipal()).thenReturn(new Principal() {
    @Override
    public String getName() {
      return "bar";
    }
  });
  HttpContext context = Mockito.mock(HttpContext.class);
  Mockito.when(context.getRequest()).thenReturn(request);
  UserProvider up = new UserProvider();
  assertEquals(up.getValue(context).getName(), "bar");
  assertEquals(MDC.get("user"), "bar");
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:18,代码来源:TestUserProvider.java

示例8: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public T getValue(HttpContext c) {
    try {
        final Optional<T> result = authenticator.authenticate(null);
        if (result.isPresent()) {
            return result.get();
        }
    } catch (AuthenticationException e) {
        LOGGER.warn("Error authenticating credentials", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }


    if (required) {
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED)
                .entity("Credentials are required to access this resource.")
                .type(MediaType.TEXT_PLAIN_TYPE)
                .build());
    }
    return null;
}
 
开发者ID:guggens,项目名称:log-dropwizard-eureka-mongo-sample,代码行数:22,代码来源:NullAuthProvider.java

示例9: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public Principal getValue(HttpContext httpContext) {
  Principal principal = httpContext.getRequest().getUserPrincipal();
  if (principal == null) {
    final String user = httpContext.getRequest().getQueryParameters()
        .getFirst(USER_NAME_PARAM);
    if (user != null) {
      principal = new Principal() {
        @Override
        public String getName() {
          return new UserParam(user).value();
        }
      };
    }
  }
  if (principal != null) {
    MDC.put("user", principal.getName());
  }
  return principal;
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:21,代码来源:UserProvider.java

示例10: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public String getValue(HttpContext httpContext) {
    List<String> headers = httpContext.getRequest().getRequestHeader(correlatorHeader);
    if ( (headers != null) && (headers.size() > 0) ) {
        if (headers.size() == 1) {
            LOGGER.debug("correlator found {}:", headers.get(0));
            MDC.put("client", headers.get(0));
            return headers.get(0);
        } else {
            LOGGER.error("Too many Correlator Headers {}:", correlatorHeader, headers);
            throw new WebApplicationException(Response.Status.BAD_REQUEST);
        }
    } else {
        LOGGER.debug("correlator not found");
        return null;
    }
}
 
开发者ID:telefonicaid,项目名称:fiware-keypass,代码行数:18,代码来源:CorrelatorProvider.java

示例11: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public T getValue(HttpContext context) {
    final Optional<String> service = getServiceFromPath(context.getUriInfo());
    if (!service.isPresent()) {
        return null;
    }

    final Optional<String> token = getToken(context.getRequest());
    if (token.isPresent()) {
        final String method = context.getRequest().getMethod();
        final boolean readRequest = HttpMethod.GET.equals(method);

        final Optional<T> result = authenticateToken(service.get(), token.get(), readRequest);
        if (result.isPresent()) {
            return result.get();
        }
    }

    if (required) {
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED)
            .entity("Credentials are required to access this resource.")
            .type(MediaType.TEXT_PLAIN_TYPE).build());
    }

    return null;
}
 
开发者ID:yammer,项目名称:backups,代码行数:27,代码来源:TokenAuthInjectable.java

示例12: getValue

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public T getValue(HttpContext httpContext) {
    final Cookie cookie = httpContext.getRequest().getCookies().get(this.cookie);

    if (cookie != null) {
        final String value = cookie.getValue();
        try {
            final Optional<T> result = authenticator.authenticate(value);
            if (result.isPresent()) {
                return result.get();
            }
        } catch (AuthenticationException e) {
            e.printStackTrace();
        }
    }

    if (required) {
        throw new WebApplicationException(
                Response.status(Response.Status.UNAUTHORIZED)
                        .entity("Credentials are required to access this resource")
                        .type(MediaType.TEXT_PLAIN_TYPE)
                        .build());
    }

    return null;
}
 
开发者ID:plant42,项目名称:dropwizard-cookie-authprovider,代码行数:27,代码来源:CookieAuthProvider.java

示例13: testDispatchesWithEmptyIterator

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Test
public void testDispatchesWithEmptyIterator() {
    RequestDispatcher dispatcherMock = createStrictMock(RequestDispatcher.class);
    Object resource = new Object();
    HttpContext httpContext = createStrictMock(HttpContext.class);

    dispatcherMock.dispatch(resource, httpContext);

    replay(dispatcherMock);

    ResourceMethodDispatchWrapperChainImpl chain =
        new ResourceMethodDispatchWrapperChainImpl(Lists.<ResourceMethodDispatchWrapper>newArrayList().iterator(),
            dispatcherMock);

    chain.wrapDispatch(resource, httpContext);

    verify(dispatcherMock);
}
 
开发者ID:palominolabs,项目名称:jersey-guice-dispatch-wrapper,代码行数:19,代码来源:ResourceMethodDispatchWrapperChainImplTest.java

示例14: testIteratesThenDispatches

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Test
public void testIteratesThenDispatches() {
    RequestDispatcher dispatcherMock = createStrictMock(RequestDispatcher.class);
    Object resource = new Object();
    HttpContext httpContext = createStrictMock(HttpContext.class);

    dispatcherMock.dispatch(resource, httpContext);

    replay(dispatcherMock);

    ArrayList<ResourceMethodDispatchWrapper> list = Lists.newArrayList();
    CountingRequestMethodDispatchWrapper wrapper1 = new CountingRequestMethodDispatchWrapper();
    list.add(wrapper1);
    CountingRequestMethodDispatchWrapper wrapper2 = new CountingRequestMethodDispatchWrapper();
    list.add(wrapper2);
    ResourceMethodDispatchWrapperChainImpl chain =
        new ResourceMethodDispatchWrapperChainImpl(list.iterator(),
            dispatcherMock);

    chain.wrapDispatch(resource, httpContext);

    verify(dispatcherMock);

    assertEquals(1, wrapper1.counter);
    assertEquals(1, wrapper2.counter);
}
 
开发者ID:palominolabs,项目名称:jersey-guice-dispatch-wrapper,代码行数:27,代码来源:ResourceMethodDispatchWrapperChainImplTest.java

示例15: createDispatchWrapper

import com.sun.jersey.api.core.HttpContext; //导入依赖的package包/类
@Override
public ResourceMethodDispatchWrapper createDispatchWrapper(AbstractResourceMethod am) {
    EnabledState state = MetricAnnotationFeatureResolver.getState(am, new TimingMetricsAnnotationChecker());

    if (state == EnabledState.OFF ||
        (state == EnabledState.UNSPECIFIED && !jerseyMetricsConfig.isTimingEnabledByDefault())) {
        return null;
    }

    Class<?> resourceClass = am.getResource().getResourceClass();
    String metricId = namer.getMetricBaseName(am);
    final Timer timer = metricsRegistry.timer(MetricRegistry.name(resourceClass, metricId + " timer"));
    return new ResourceMethodDispatchWrapper() {
        @Override
        public void wrapDispatch(Object resource, HttpContext context, ResourceMethodDispatchWrapperChain chain) {

            final Timer.Context time = timer.time();
            try {
                chain.wrapDispatch(resource, context);
            } finally {
                time.stop();
            }
        }
    };
}
 
开发者ID:palominolabs,项目名称:jersey-metrics-filter,代码行数:26,代码来源:MetricsWrapperFactory.java


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