Package org.apache.shindig.common.uri

Examples of org.apache.shindig.common.uri.Uri


    assertTrue(resource.isProxyCacheable());
  }

  @Test(expected=IllegalArgumentException.class)
  public void loadFileNothingAvailable() throws Exception {
    Uri nilUri = new UriBuilder().setScheme("file").setPath("/does/not/exist.js").toUri();
    loader.load(nilUri, null);
    fail("Should have failed indicating could not find: " + nilUri.toString());
  }
View Full Code Here


    assertTrue(resource.isProxyCacheable());
  }

  @Test
  public void loadUriInline() throws Exception {
    Uri uri = Uri.parse("http://apache.org/resource.js");
    Map<String, String> attribs = Maps.newHashMap();
    attribs.put("inline", "true");
    mockFetcher(uri, URL_JS);
    FeatureResource resource = loader.load(uri, attribs);
    assertEquals(URL_JS, resource.getContent());
View Full Code Here

    assertFalse(resource.isExternal());
  }

  @Test
  public void loadUriInlineFetcherFailure() throws Exception {
    Uri uri = Uri.parse("http://apache.org/resource.js");
    Map<String, String> attribs = Maps.newHashMap();
    attribs.put("inline", "true");
    expect(fetcher.fetch(eq(new HttpRequest(uri))))
        .andThrow(new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT));
    replay(fetcher);
View Full Code Here

  }

  @Test
  public void loadUriExtern() throws Exception {
    String theUrl = "http://apache.org/resource.js";
    Uri uri = Uri.parse(theUrl);
    Map<String, String> attribs = Maps.newHashMap();
    mockFetcher(uri, URL_JS);
    FeatureResource resource = loader.load(uri, attribs);
    assertEquals(theUrl, resource.getContent());
    assertEquals(theUrl, resource.getDebugContent());
View Full Code Here

  private OAuthCallbackGenerator createRealCallbackGenerator() {
    return new OAuthCallbackGenerator() {
      public String generateCallback(OAuthFetcherConfig fetcherConfig, String baseCallback,
          HttpRequest request, OAuthResponseParams responseParams) {
        SecurityToken st = request.getSecurityToken();
        Uri activeUrl = Uri.parse(st.getActiveUrl());
        assertEquals(GADGET_MAKE_REQUEST_URL, activeUrl.toString());
        assertEquals(GadgetTokenStoreTest.DEFAULT_CALLBACK, baseCallback);
        return new UriBuilder()
            .setScheme("http")
            .setAuthority(activeUrl.getAuthority())
            .setPath("/realcallback")
            .toString();
      }
    };
  }
View Full Code Here

  static class DummyGadgetSpecFactory implements GadgetSpecFactory {
    private final static String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Module><ModulePrefs title=\"\"><OAuth2><Service name=\"serviceName\" scope=\"testScope\"></Service></OAuth2></ModulePrefs><Content type=\"html\"></Content></Module>";

    public GadgetSpec getGadgetSpec(final GadgetContext context) throws GadgetException {
      final Uri contextUri = context.getUrl();
      if ((contextUri != null) && (contextUri.toString().equals(MockUtils.GADGET_URI1))) {
        return new GadgetSpec(context.getUrl(), DummyGadgetSpecFactory.xml);
      }

      throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR);
    }
View Full Code Here

  private void setupRequest(String str) throws Exception {
    setupRequest(str, true);
  }

  private void setupRequest(String str, boolean ldSafe) throws Exception {
    Uri uri = Uri.parse(str);

    expect(request.getScheme()).andReturn(uri.getScheme());
    expect(request.getServerName()).andReturn(uri.getAuthority());
    expect(request.getServerPort()).andReturn(80);
    expect(request.getRequestURI()).andReturn(uri.getPath());
    expect(request.getQueryString()).andReturn(uri.getQuery());
    expect(request.getHeader("Host")).andReturn(uri.getAuthority());
    expect(proxyUriManager.process(uri)).andReturn(proxyUri);
    expect(lockedDomainService.isSafeForOpenProxy(uri.getAuthority())).andReturn(ldSafe);
  }
View Full Code Here

      throws GadgetException {
    Map<String,FeatureNode> featureMapBuilder = Maps.newHashMap();

    try {
      for (String location : resourceList) {
        Uri uriLoc = getComponentUri(location);

        if (uriLoc.getScheme() != null && uriLoc.getScheme().equals(RESOURCE_SCHEME)) {
          List<String> resources = Lists.newArrayList();

          // Load as resource using ResourceLoader.
          location = uriLoc.getPath();
          if (location.startsWith("/")) {
            // Accommodate res:// URIs.
            location = location.substring(1);
          }
          if (LOG.isLoggable(Level.INFO)) {
            LOG.logp(Level.INFO, classname, "register",
                MessageKeys.LOAD_RESOURCES_FROM, new Object[] {uriLoc.toString()});
          }
          if (location.endsWith(".txt")) {
            // Text file contains a list of other resource files to load
            for (String resource : CRLF_SPLITTER.split(resourceLoader.getResourceContent(location))) {
              if (resource.charAt(0) != '#') {
                // Skip commented lines.
                resource = getComponentUri(resource).getPath();
                resources.add(resource);
              }
            }
          } else {
            resources.add(location);
          }

          loadResources(resources, featureMapBuilder);
        } else {
          // Load files in directory structure.
          if (LOG.isLoggable(Level.INFO)) {
            LOG.logp(Level.INFO, classname, "register",
                MessageKeys.LOAD_FILES_FROM, new Object[] {location});
          }
          loadFile(fileSystem.getFile(uriLoc.getPath()), featureMapBuilder);
        }
      }
      return ImmutableMap.copyOf(featureMapBuilder);
    } catch (IOException e) {
      throw new GadgetException(GadgetException.Code.INVALID_PATH, e);
View Full Code Here

        if (LOG.isLoggable(Level.FINE)) {
          LOG.fine("Processing resource: " + resource);
        }

        String content = resourceLoader.getResourceContent(resource);
        Uri parent = new UriBuilder().setScheme(RESOURCE_SCHEME).setPath(resource).toUri();
        loadFeature(parent, content, featureMapBuilder);
      }
    } catch (IOException e) {
      throw new GadgetException(GadgetException.Code.INVALID_PATH, e);
    }
View Full Code Here

      if (featureFile.isDirectory()) {
        // Traverse into subdirectories.
        loadFile(featureFile, featureMapBuilder);
      } else if (featureFile.getName().toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
        String content = featureFile.getContent();
        Uri parent = Uri.fromJavaUri(featureFile.toURI());
        loadFeature(parent, content, featureMapBuilder);
      } else {
        if (LOG.isLoggable(Level.FINEST)) {
          LOG.finest(featureFile.getAbsolutePath() + " doesn't seem to be an XML file.");
        }
View Full Code Here

TOP

Related Classes of org.apache.shindig.common.uri.Uri

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.