Java Code Examples for org.xml.sax.InputSource#setPublicId()

The following examples show how to use org.xml.sax.InputSource#setPublicId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfiguredTestCase.java    From oodt with Apache License 2.0 6 votes vote down vote up
/**
 * Set up a test Configuration object.
 *
 * @throws Exception if an error occurs.
 */
protected void setUp() throws Exception {
	super.setUp();
	if (Configuration.configuration == null) {
		try {
			StringReader reader = new StringReader(TSTDOC);
			InputSource is = new InputSource(reader);
			is.setEncoding("UTF-8");
			is.setPublicId("-//JPL//XML EDM Test Configuration 0.0.0//EN");
			is.setSystemId("internal:test-edarc.xml");
			Configuration.configuration = new Configuration(is);
			reader.close();
		} catch (IOException ex) {
			ex.printStackTrace();
			throw new IllegalStateException("Unexpected IOException: " + ex.getMessage());
		}
	}
}
 
Example 2
Source File: XMLCatalogResolver.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Resolves an external entity. If the entity cannot be
 * resolved, this method should return <code>null</code>. This
 * method returns an input source if an entry was found in the
 * catalog for the given external identifier. It should be
 * overrided if other behaviour is required.</p>
 *
 * @param publicId the public identifier, or <code>null</code> if none was supplied
 * @param systemId the system identifier
 *
 * @throws SAXException any SAX exception, possibly wrapping another exception
 * @throws IOException thrown if some i/o error occurs
 */
public InputSource resolveEntity(String publicId, String systemId)
     throws SAXException, IOException {

    String resolvedId = null;
    if (publicId != null && systemId != null) {
        resolvedId = resolvePublic(publicId, systemId);
    }
    else if (systemId != null) {
        resolvedId = resolveSystem(systemId);
    }

    if (resolvedId != null) {
        InputSource source = new InputSource(resolvedId);
        source.setPublicId(publicId);
        return source;
    }
    return null;
}
 
Example 3
Source File: SAXSource.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Attempt to obtain a SAX InputSource object from a Source
 * object.
 *
 * @param source Must be a non-null Source reference.
 *
 * @return An InputSource, or null if Source can not be converted.
 */
public static InputSource sourceToInputSource(Source source) {

    if (source instanceof SAXSource) {
        return ((SAXSource) source).getInputSource();
    } else if (source instanceof StreamSource) {
        StreamSource ss      = (StreamSource) source;
        InputSource  isource = new InputSource(ss.getSystemId());

        isource.setByteStream(ss.getInputStream());
        isource.setCharacterStream(ss.getReader());
        isource.setPublicId(ss.getPublicId());

        return isource;
    } else {
        return null;
    }
}
 
Example 4
Source File: XMLCatalogResolver.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Resolves an external entity. If the entity cannot be
 * resolved, this method should return <code>null</code>. This
 * method returns an input source if an entry was found in the
 * catalog for the given external identifier. It should be
 * overrided if other behaviour is required.</p>
 *
 * @param publicId the public identifier, or <code>null</code> if none was supplied
 * @param systemId the system identifier
 *
 * @throws SAXException any SAX exception, possibly wrapping another exception
 * @throws IOException thrown if some i/o error occurs
 */
public InputSource resolveEntity(String publicId, String systemId)
     throws SAXException, IOException {

    String resolvedId = null;
    if (publicId != null && systemId != null) {
        resolvedId = resolvePublic(publicId, systemId);
    }
    else if (systemId != null) {
        resolvedId = resolveSystem(systemId);
    }

    if (resolvedId != null) {
        InputSource source = new InputSource(resolvedId);
        source.setPublicId(publicId);
        return source;
    }
    return null;
}
 
Example 5
Source File: XMLCatalogResolver.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Resolves an external entity. If the entity cannot be
 * resolved, this method should return <code>null</code>. This
 * method returns an input source if an entry was found in the
 * catalog for the given external identifier. It should be
 * overrided if other behaviour is required.</p>
 *
 * @param publicId the public identifier, or <code>null</code> if none was supplied
 * @param systemId the system identifier
 *
 * @throws SAXException any SAX exception, possibly wrapping another exception
 * @throws IOException thrown if some i/o error occurs
 */
public InputSource resolveEntity(String publicId, String systemId)
     throws SAXException, IOException {

    String resolvedId = null;
    if (publicId != null && systemId != null) {
        resolvedId = resolvePublic(publicId, systemId);
    }
    else if (systemId != null) {
        resolvedId = resolveSystem(systemId);
    }

    if (resolvedId != null) {
        InputSource source = new InputSource(resolvedId);
        source.setPublicId(publicId);
        return source;
    }
    return null;
}
 
Example 6
Source File: XMLCatalogResolver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>Resolves an external entity. If the entity cannot be
 * resolved, this method should return <code>null</code>. This
 * method returns an input source if an entry was found in the
 * catalog for the given external identifier. It should be
 * overrided if other behaviour is required.</p>
 *
 * @param publicId the public identifier, or <code>null</code> if none was supplied
 * @param systemId the system identifier
 *
 * @throws SAXException any SAX exception, possibly wrapping another exception
 * @throws IOException thrown if some i/o error occurs
 */
public InputSource resolveEntity(String publicId, String systemId)
     throws SAXException, IOException {

    String resolvedId = null;
    if (publicId != null && systemId != null) {
        resolvedId = resolvePublic(publicId, systemId);
    }
    else if (systemId != null) {
        resolvedId = resolveSystem(systemId);
    }

    if (resolvedId != null) {
        InputSource source = new InputSource(resolvedId);
        source.setPublicId(publicId);
        return source;
    }
    return null;
}
 
Example 7
Source File: CatalogResolver.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  }

  return null;
}
 
Example 8
Source File: CatalogResolver.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  }

  return null;
}
 
Example 9
Source File: SystemIdResolver.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws IOException {
  if (systemId == null) {
    return null;
  }
  try {
    final URI uri = resolveRelativeURI(baseURI, systemId);
    
    // check schema and resolve with ResourceLoader
    if (RESOURCE_LOADER_URI_SCHEME.equals(uri.getScheme())) {
      String path = uri.getPath(), authority = uri.getAuthority();
      if (!RESOURCE_LOADER_AUTHORITY_ABSOLUTE.equals(authority)) {
        path = path.substring(1);
      }
      try {
        final InputSource is = new InputSource(loader.openResource(path));
        is.setSystemId(uri.toASCIIString());
        is.setPublicId(publicId);
        return is;
      } catch (RuntimeException re) {
        // unfortunately XInclude fallback only works with IOException, but openResource() never throws that one
        throw new IOException(re.getMessage(), re);
      }
    } else {
      throw new IOException("Cannot resolve absolute systemIDs / external entities (only relative paths work): " + systemId);
    }
  } catch (URISyntaxException use) {
    throw new IOException("An URI syntax problem occurred during resolving systemId: " + systemId, use);
  }
}
 
Example 10
Source File: XMLCatalogResolver.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
  * <p>Resolves an external entity. If the entity cannot be
  * resolved, this method should return <code>null</code>. This
  * method returns an input source if an entry was found in the
  * catalog for the given external identifier. It should be
  * overrided if other behaviour is required.</p>
  *
  * @param name the identifier of the external entity
  * @param publicId the public identifier, or <code>null</code> if none was supplied
  * @param baseURI the URI with respect to which relative systemIDs are interpreted.
  * @param systemId the system identifier
  *
  * @throws SAXException any SAX exception, possibly wrapping another exception
  * @throws IOException thrown if some i/o error occurs
  */
 public InputSource resolveEntity(String name, String publicId,
     String baseURI, String systemId) throws SAXException, IOException {

     String resolvedId = null;

     if (!getUseLiteralSystemId() && baseURI != null) {
         // Attempt to resolve the system identifier against the base URI.
         try {
             URI uri = new URI(new URI(baseURI), systemId);
             systemId = uri.toString();
         }
         // Ignore the exception. Fallback to the literal system identifier.
         catch (URI.MalformedURIException ex) {}
     }

     if (publicId != null && systemId != null) {
         resolvedId = resolvePublic(publicId, systemId);
     }
     else if (systemId != null) {
         resolvedId = resolveSystem(systemId);
     }

     if (resolvedId != null) {
         InputSource source = new InputSource(resolvedId);
         source.setPublicId(publicId);
         return source;
     }
     return null;
}
 
Example 11
Source File: PluggableSchemaResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public InputSource resolveEntity(String publicId, String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public id [" + publicId +
				"] and system id [" + systemId + "]");
	}

	if (systemId != null) {
		String resourceLocation = getSchemaMappings().get(systemId);
		if (resourceLocation != null) {
			Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
			try {
				InputSource source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isDebugEnabled()) {
					logger.debug("Found XML schema [" + systemId + "] in classpath: " + resourceLocation);
				}
				return source;
			}
			catch (FileNotFoundException ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Couldn't find XML schema [" + systemId + "]: " + resource, ex);
				}
			}
		}
	}
	return null;
}
 
Example 12
Source File: ValidatorHandlerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
Example 13
Source File: CatalogResolver.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  }

  return null;
}
 
Example 14
Source File: ResolvingXMLFilter.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  } else {
    return null;
  }
}
 
Example 15
Source File: ResolvingParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  } else {
    return null;
  }
}
 
Example 16
Source File: ResolvingXMLFilter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  } else {
    return null;
  }
}
 
Example 17
Source File: InputSourceTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testSetPublicIdGetPublicId() {
    InputSource i = new InputSource();

    i.setPublicId("Foo");
    assertEquals("Foo", i.getPublicId());

    i.setPublicId(null);
    assertNull(i.getPublicId());
}
 
Example 18
Source File: PluggableSchemaResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException {
	if (logger.isTraceEnabled()) {
		logger.trace("Trying to resolve XML entity with public id [" + publicId +
				"] and system id [" + systemId + "]");
	}

	if (systemId != null) {
		String resourceLocation = getSchemaMappings().get(systemId);
		if (resourceLocation != null) {
			Resource resource = new ClassPathResource(resourceLocation, this.classLoader);
			try {
				InputSource source = new InputSource(resource.getInputStream());
				source.setPublicId(publicId);
				source.setSystemId(systemId);
				if (logger.isTraceEnabled()) {
					logger.trace("Found XML schema [" + systemId + "] in classpath: " + resourceLocation);
				}
				return source;
			}
			catch (FileNotFoundException ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Could not find XML schema [" + systemId + "]: " + resource, ex);
				}
			}
		}
	}
	return null;
}
 
Example 19
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testSAXSourcePAYLOAD() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<SAXSource> disp = service.createDispatch(PORT_NAME, SAXSource.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");

    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    InputSource inputSource = new InputSource(is);
    inputSource.setPublicId(getClass()
                                .getResource("resources/GreetMeDocLiteralSOAPBodyReq.xml").toString());
    inputSource.setSystemId(inputSource.getPublicId());
    SAXSource saxSourceReq = new SAXSource(inputSource);
    assertNotNull(saxSourceReq);
    SAXSource saxSourceResp = disp.invoke(saxSourceReq);
    assertNotNull(saxSourceResp);
    String expected = "Hello TestSOAPInputMessage";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp).contains(expected));

    // Test oneway
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq1.xml");
    InputSource inputSource1 = new InputSource(is1);
    inputSource1.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq1.xml").toString());
    inputSource1.setSystemId(inputSource1.getPublicId());
    SAXSource saxSourceReq1 = new SAXSource(inputSource1);
    assertNotNull(saxSourceReq1);
    disp.invokeOneWay(saxSourceReq1);

    // Test async polling
    InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq2.xml");
    InputSource inputSource2 = new InputSource(is2);
    inputSource2.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq2.xml").toString());
    inputSource2.setSystemId(inputSource2.getPublicId());
    SAXSource saxSourceReq2 = new SAXSource(inputSource2);
    assertNotNull(saxSourceReq2);
    Response<SAXSource> response = disp.invokeAsync(saxSourceReq2);
    SAXSource saxSourceResp2 = response.get();
    assertNotNull(saxSourceResp2);
    String expected2 = "Hello TestSOAPInputMessage2";
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp2).contains(expected2));

    // Test async callback
    InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq3.xml");
    InputSource inputSource3 = new InputSource(is3);
    inputSource3.setPublicId(getClass()
                             .getResource("resources/GreetMeDocLiteralSOAPBodyReq3.xml").toString());
    inputSource3.setSystemId(inputSource3.getPublicId());
    SAXSource saxSourceReq3 = new SAXSource(inputSource3);
    assertNotNull(saxSourceReq3);

    TestSAXSourceHandler tssh = new TestSAXSourceHandler();
    Future<?> fd = disp.invokeAsync(saxSourceReq3, tssh);
    assertNotNull(fd);
    waitForFuture(fd);

    String expected3 = "Hello TestSOAPInputMessage3";
    SAXSource saxSourceResp3 = tssh.getSAXSource();
    assertNotNull(saxSourceResp3);
    assertTrue("Expected: " + expected, StaxUtils.toString(saxSourceResp3).contains(expected3));
}
 
Example 20
Source File: ResolvingXMLFilter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1,
                                   "Failed to create InputSource ("
                                   + e.toString()
                                   + ")", resolved);
      return null;
    }
  } else {
    return null;
  }
}