예제 #1
0
  public DefaultAuthenticator(@NotNull ErrorReceiver receiver, @NotNull File authfile)
      throws BadCommandLineException {
    this.errReceiver = receiver;
    this.proxyUser = System.getProperty("http.proxyUser");
    this.proxyPasswd = System.getProperty("http.proxyPassword");

    if (authfile != null) {
      this.authFile = authfile;
      this.giveError = true;
    }

    if (!authFile.exists()) {
      try {
        error(
            new SAXParseException(
                WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND(
                    authFile.getCanonicalPath(), defaultAuthfile),
                null));
      } catch (IOException e) {
        error(
            new SAXParseException(
                WscompileMessages.WSIMPORT_FAILED_TO_PARSE(authFile, e.getMessage()), null));
      }
      return;
    }

    if (!authFile.canRead()) {
      error(
          new SAXParseException(
              "Authorization file: " + authFile + " does not have read permission!", null));
      return;
    }
    parseAuth();
  }
예제 #2
0
  /*
   * If source and target namespace are also passed in,
   * then if the mex resolver is found and it cannot get
   * the data, wsimport attempts to add ?wsdl to the
   * address and retrieve the data with a normal http get.
   * This behavior should only happen when trying a
   * mex request first.
   */
  private @Nullable Element getFromMetadataResolver(String systemId, Exception ex) {
    // try MEX
    MetaDataResolver resolver;
    ServiceDescriptor serviceDescriptor = null;
    for (MetadataResolverFactory resolverFactory :
        ServiceFinder.find(MetadataResolverFactory.class)) {
      resolver = resolverFactory.metadataResolver(options.entityResolver);
      try {
        serviceDescriptor = resolver.resolve(new URI(systemId));
        // we got the ServiceDescriptor, now break
        if (serviceDescriptor != null) break;
      } catch (URISyntaxException e) {
        throw new ParseException(e);
      }
    }

    if (serviceDescriptor != null) {
      errorReceiver.warning(
          new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
      return parseMetadata(systemId, serviceDescriptor);
    } else {
      errorReceiver.error(
          null,
          WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(
              ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)),
          ex);
    }
    return null;
  }
예제 #3
0
  private void parseAuth() {
    errReceiver.info(
        new SAXParseException(WscompileMessages.WSIMPORT_READING_AUTH_FILE(authFile), null));

    BufferedReader in;
    try {
      in = new BufferedReader(new InputStreamReader(new FileInputStream(authFile), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      error(new SAXParseException(e.getMessage(), null));
      return;
    } catch (FileNotFoundException e) {
      error(
          new SAXParseException(
              WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND(authFile, defaultAuthfile), null, e));
      return;
    }
    String text;
    LocatorImpl locator = new LocatorImpl();
    try {
      int lineno = 1;

      locator.setSystemId(authFile.getCanonicalPath());

      while ((text = in.readLine()) != null) {
        locator.setLineNumber(lineno++);
        try {
          URL url = new URL(text);
          String authinfo = url.getUserInfo();

          if (authinfo != null) {
            int i = authinfo.indexOf(':');

            if (i >= 0) {
              String user = authinfo.substring(0, i);
              String password = authinfo.substring(i + 1);
              authInfo.add(new AuthInfo(new URL(text), user, password));
            } else {
              error(
                  new SAXParseException(
                      WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(url), locator));
            }
          } else {
            error(
                new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(url), locator));
          }

        } catch (NumberFormatException e) {
          error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), locator));
        }
      }
      in.close();
    } catch (IOException e) {
      error(
          new SAXParseException(
              WscompileMessages.WSIMPORT_FAILED_TO_PARSE(authFile, e.getMessage()), locator));
    }
  }
예제 #4
0
    @Override
    public InputSource resolveEntity(String publicId, String systemId)
        throws SAXException, IOException {
      InputSource inputSource = null;

      if (options.entityResolver != null) {
        inputSource = options.entityResolver.resolveEntity(null, systemId);
      }
      if (inputSource == null) {
        inputSource = new InputSource(systemId);
        InputStream is = null;
        int redirects = 0;
        boolean redirect;
        URL url = JAXWSUtils.getFileOrURL(inputSource.getSystemId());
        URLConnection conn = url.openConnection();
        do {
          if (conn instanceof HttpsURLConnection) {
            if (options.disableSSLHostnameVerification) {
              ((HttpsURLConnection) conn).setHostnameVerifier(new HttpClientVerifier());
            }
          }
          redirect = false;
          if (conn instanceof HttpURLConnection) {
            ((HttpURLConnection) conn).setInstanceFollowRedirects(false);
          }

          if (conn instanceof JarURLConnection) {
            if (conn.getUseCaches()) {
              doReset = true;
              conn.setDefaultUseCaches(false);
              c = conn;
            }
          }

          try {
            is = conn.getInputStream();
            // is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn);
          } catch (IOException e) {
            if (conn instanceof HttpURLConnection) {
              HttpURLConnection httpConn = ((HttpURLConnection) conn);
              int code = httpConn.getResponseCode();
              if (code == 401) {
                errorReceiver.error(
                    new SAXParseException(
                        WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED(
                            e.getMessage(), systemId, WsimportOptions.defaultAuthfile),
                        null,
                        e));
                throw new AbortException();
              }
              // FOR other code we will retry with MEX
            }
            throw e;
          }

          // handle 302 or 303, JDK does not seem to handle 302 very well.
          // Need to redesign this a bit as we need to throw better error message for IOException in
          // this case
          if (conn instanceof HttpURLConnection) {
            HttpURLConnection httpConn = ((HttpURLConnection) conn);
            int code = httpConn.getResponseCode();
            if (code == 302 || code == 303) {
              // retry with the value in Location header
              List<String> seeOther = httpConn.getHeaderFields().get("Location");
              if (seeOther != null && seeOther.size() > 0) {
                URL newurl = new URL(url, seeOther.get(0));
                if (!newurl.equals(url)) {
                  errorReceiver.info(
                      new SAXParseException(
                          WscompileMessages.WSIMPORT_HTTP_REDIRECT(code, seeOther.get(0)), null));
                  url = newurl;
                  httpConn.disconnect();
                  if (redirects >= 5) {
                    errorReceiver.error(
                        new SAXParseException(
                            WscompileMessages.WSIMPORT_MAX_REDIRECT_ATTEMPT(), null));
                    throw new AbortException();
                  }
                  conn = url.openConnection();
                  inputSource.setSystemId(url.toExternalForm());
                  redirects++;
                  redirect = true;
                }
              }
            }
          }
        } while (redirect);
        inputSource.setByteStream(is);
      }

      return inputSource;
    }