當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。