コード例 #1
0
ファイル: UriBuilderTest.java プロジェクト: YaqubGhazi/olat
  @Before
  public void setup() {
    publisher = mock(Publisher.class);
    when(publisher.getContextType()).thenReturn(ContextType.COURSE);
    when(publisher.getContextId()).thenReturn(contextId);

    uriBuilderTestObject = new UriBuilder();
    uriBuilderTestObject.setServerContextPathURI(testContextPathUri);
    Set<PublisherTypeHandler> typeHandler = new HashSet<PublisherTypeHandler>();
    typeHandler.add(new ForumNotificationTypeHandler());
    typeHandler.add(new WikiNotificationTypeHandler());
    PublisherTypeHandlerSelector typeHandlerSelector = new PublisherTypeHandlerSelector();
    typeHandlerSelector.notificationTypeHandler = typeHandler;
    uriBuilderTestObject.typeHandlerSelector = typeHandlerSelector;
  }
コード例 #2
0
ファイル: UriBuilderTest.java プロジェクト: YaqubGhazi/olat
 @Test
 public void getURIToContext_ContextType_UNKOWN() {
   Publisher publisherUnkown = mock(Publisher.class);
   when(publisherUnkown.getContextType()).thenReturn(ContextType.UNKNOWN);
   String uriToContext = uriBuilderTestObject.getURIToContext(publisherUnkown);
   assertEquals("Wrong URI with unkown type", testContextPathUri + "/url/UNKOWN/0", uriToContext);
 }
コード例 #3
0
ファイル: UriBuilderTest.java プロジェクト: YaqubGhazi/olat
 private void checkUriToContext() {
   when(publisher.getSubcontextId()).thenReturn(subContextId);
   String uriToEventSource = uriBuilderTestObject.getURIToEventSource(publisher);
   assertEquals(
       "Wrong URI with type " + publisher.getSourceType(),
       testContextPathUri + "/url/RepositoryEntry/" + contextId + "/CourseNode/" + subContextId,
       uriToEventSource);
 }
コード例 #4
0
ファイル: UriBuilderTest.java プロジェクト: YaqubGhazi/olat
 @Test
 public void getURIToContext_ContextType_COURSE() {
   String uriToContext = uriBuilderTestObject.getURIToContext(publisher);
   assertEquals(
       "Wrong URI to context",
       testContextPathUri + "/url/RepositoryEntry/" + contextId,
       uriToContext);
 }
コード例 #5
0
ファイル: TokenResource.java プロジェクト: pixelthekid/apis
 private Response sendAuthorizationCodeResponse(AuthorizationRequest authReq) {
   String uri = authReq.getRedirectUri();
   String authorizationCode = getAuthorizationCodeValue();
   authReq.setAuthorizationCode(authorizationCode);
   authorizationRequestRepository.save(authReq);
   uri = uri + appendQueryMark(uri) + "code=" + authorizationCode + appendStateParameter(authReq);
   return Response.seeOther(UriBuilder.fromUri(uri).build())
       .cacheControl(cacheControlNoStore())
       .header("Pragma", "no-cache")
       .build();
 }
コード例 #6
0
  Uri(UriBuilder builder) {
    scheme = builder.getScheme();
    authority = builder.getAuthority();
    path = builder.getPath();
    query = builder.getQuery();
    fragment = builder.getFragment();
    queryParameters =
        Collections.unmodifiableMap(Maps.newLinkedHashMap(builder.getQueryParameters()));

    StringBuilder out = new StringBuilder();

    if (scheme != null) {
      out.append(scheme).append(':');
    }
    if (authority != null) {
      out.append("//").append(authority);
      // insure that there's a separator between authority/path
      if (path != null && path.length() > 1 && !path.startsWith("/")) {
        out.append("/");
      }
    }
    if (path != null) {
      out.append(path);
    }
    if (query != null) {
      out.append('?').append(query);
    }
    if (fragment != null) {
      out.append('#').append(fragment);
    }
    text = out.toString();
  }
コード例 #7
0
  /**
   * Derived from Harmony Resolves a given url relative to this url. Resolution rules are the same
   * as for {@code java.net.URI.resolve(URI)}
   */
  public Uri resolve(Uri relative) {
    if (relative == null) {
      return null;
    }
    if (relative.isAbsolute()) {
      return relative;
    }

    UriBuilder result;
    if (StringUtils.isEmpty(relative.path)
        && relative.scheme == null
        && relative.authority == null
        && relative.query == null
        && relative.fragment != null) {
      // if the relative URI only consists of fragment,
      // the resolved URI is very similar to this URI,
      // except that it has the fragement from the relative URI.
      result = new UriBuilder(this);
      result.setFragment(relative.fragment);
    } else if (relative.scheme != null) {
      result = new UriBuilder(relative);
    } else if (relative.authority != null) {
      // if the relative URI has authority,
      // the resolved URI is almost the same as the relative URI,
      // except that it has the scheme of this URI.
      result = new UriBuilder(relative);
      result.setScheme(scheme);
    } else {
      // since relative URI has no authority,
      // the resolved URI is very similar to this URI,
      // except that it has the query and fragment of the relative URI,
      // and the path is different.
      result = new UriBuilder(this);
      result.setFragment(relative.fragment);
      result.setQuery(relative.query);
      String relativePath = (relative.path == null) ? "" : relative.path;
      if (relativePath.startsWith("/")) { // $NON-NLS-1$
        result.setPath(relativePath);
      } else {
        // resolve a relative reference
        int endindex = path.lastIndexOf('/') + 1;
        result.setPath(normalizePath(path.substring(0, endindex) + relativePath));
      }
    }
    Uri resolved = result.toUri();
    validate(resolved);
    return resolved;
  }
コード例 #8
0
ファイル: UriBuilderTest.java プロジェクト: YaqubGhazi/olat
 @Test
 public void getURIToSourceEntry_Forum() {
   when(publisher.getSourceType()).thenReturn(ForumNotificationTypeHandler.FORUM_SOURCE_TYPE);
   when(publisher.getSubcontextId()).thenReturn(subContextId);
   String uriToSourceEntry = uriBuilderTestObject.getURIToSourceEntry(publisher, sourceEntryId);
   assertEquals(
       "Wrong URI with type " + publisher.getSourceType(),
       testContextPathUri
           + "/url/RepositoryEntry/"
           + contextId
           + "/CourseNode/"
           + subContextId
           + "/Message/"
           + sourceEntryId,
       uriToSourceEntry);
 }
コード例 #9
0
ファイル: TokenResource.java プロジェクト: pixelthekid/apis
 private Response sendImplicitGrantResponse(
     AuthorizationRequest authReq, AccessToken accessToken) {
   String uri = authReq.getRedirectUri();
   String fragment =
       String.format(
               "access_token=%s&token_type=bearer&expires_in=%s&scope=%s",
               accessToken.getToken(),
               accessToken.getExpiresIn(),
               StringUtils.join(authReq.getGrantedScopes(), ','))
           + appendStateParameter(authReq);
   if (authReq.getClient().isIncludePrincipal()) {
     fragment += String.format("&principal=%s", authReq.getPrincipal().getDisplayName());
   }
   return Response.seeOther(UriBuilder.fromUri(uri).fragment(fragment).build())
       .cacheControl(cacheControlNoStore())
       .header("Pragma", "no-cache")
       .build();
 }
コード例 #10
0
 @Before
 public void setup() {
   uriBuilder.serverContextPathURI = "/test";
   mailChannel.setMailService(mailServiceConcordionMock);
   notificationServiceImpl.notifyDelegate.channelChain.setMailChannel(mailChannel);
 }
コード例 #11
0
  public static void main(String[] args) {

    java.net.URI serviceURI = UriBuilder.fromUri("http://localhost:8080/jaxrs").build();

    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource weatherService = client.resource(serviceURI);

    String weatherResult =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Rain")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult2 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult3 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/12345")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult);
    System.out.println(weatherResult2);
    System.out.println(weatherResult3);

    MultivaluedMap formData = new MultivaluedMapImpl();
    formData.add("temperature", "25");
    formData.add("humidity", "15%");
    formData.add("rain", "false");
    formData.add("zipCode", "94043");

    String response =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .type("application/x-www-form-urlencoded")
            .post(String.class, formData);

    System.out.println(response);

    String weatherResult4 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult4);

    String weatherResult5 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_XML)
            .get(String.class);

    System.out.println(weatherResult5);
  }
コード例 #12
0
ファイル: ServerRunning.java プロジェクト: rumale/uaa
 public UriBuilder buildUri(String url) {
   return UriBuilder.fromUri(url.startsWith("http:") ? url : getUrl(url));
 }