Get a handle to a service

@param url
@param tc
@param unshared
whether an exclusive connection should be used
@return a DCERPC handle for the given url
@throws MalformedURLException
@throws DcerpcException
501372
public static DcerpcHandle getHandle ( String url, CIFSContext tc, boolean unshared ) throws MalformedURLException, DcerpcException {
        if ( url.startsWith("ncacn_np:") ) {
            return new DcerpcPipeHandle(url, tc, unshared);
        }
        throw new DcerpcException("DCERPC transport not supported: " + url);
    }
1261819
public static Connection getConnection(final String jdbcURL) throws SQLException {
        try {
            return getRealConnection(jdbcURL);
        } catch (final SQLException sqlException) {
            try {
                return (Connection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws Exception {
                        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
                        if (cl != null && cl != DriverManagerAccessor.class.getClassLoader()) {
                            final Class<?> definedClass = DriverManagerAccessorSupport.define(cl);
                            final Method method = definedClass.getDeclaredMethod("getRealConnection", String.class);
                            method.setAccessible(true);
                            return (Connection) method.invoke(null, jdbcURL);

                        } else {
                            throw sqlException;
                        }
                    }
                });
            } catch (PrivilegedActionException e) {
                throw sqlException;
            }
        }
    }
609278
protected void onUnhandledException(WebURL webUrl, Throwable e) {
        if (myController.getConfig().isHaltOnError() && !(e instanceof IOException)) {
            throw new RuntimeException("unhandled exception", e);
        } else {
            String urlStr = (webUrl == null ? "NULL" : webUrl.getURL());
            logger.warn("Unhandled exception while fetching {}: {}", urlStr, e.getMessage());
            logger.info("Stacktrace: ", e);
            // Do nothing by default (except basic logging)
            // Sub-classed can override this to add their custom functionality
        }
    }
265425
@SuppressWarnings("unused")
    public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
        try {
            return (URLConnection) _openConnectionProxy.invoke(getInstance(), new Object[] { url, proxy });
        } catch (Exception e) {
            FFDCFilter.processException(e, getClass().getName(), "openConnection", new Object[] { url, proxy });
            return null;
        }
    }
318721
public void send(TCResponseRequest event) throws TCAPSendException {

        if (this.previewMode)
            return;

        if (!this.isStructured()) {
            throw new TCAPSendException("Unstructured dialogs do not use Response");
        }

        try {
            dialogLock.lock();
            TCResponseMessageImpl tcbm = null;

            if (state == TRPseudoState.InitialReceived) {
                // TC-END request primitive issued in response to a TC-BEGIN
                // indication primitive
                this.idleTimerActionTaken = true;
                stopIdleTimer();
                tcbm = (TCResponseMessageImpl) TcapFactory.createTCResponseMessage();
                tcbm.setDestinationTransactionId(this.remoteTransactionId);
                // local address may change, lets check it;
                if (event.getOriginatingAddress() != null && !event.getOriginatingAddress().equals(this.localAddress)) {
                    this.localAddress = event.getOriginatingAddress();
                }

                if (event.getApplicationContextName() != null || event.getConfidentiality() != null
                        || event.getSecurityContext() != null || event.getUserInformation() != null) {
                    // set dialog portion
                    DialogPortion dp = TcapFactory.createDialogPortion();
                    dp.setProtocolVersion(TcapFactory.createProtocolVersionFull());
                    dp.setApplicationContext(event.getApplicationContextName());
                    dp.setUserInformation(event.getUserInformation());
                    dp.setSecurityContext(event.getSecurityContext());
                    dp.setConfidentiality(event.getConfidentiality());

                    tcbm.setDialogPortion(dp);
                }
                if (this.scheduledComponentList.size() > 0) {
                    Component[] componentsToSend = new Component[this.scheduledComponentList.size()];
                    this.prepareComponents(componentsToSend);
                    tcbm.setComponent(componentsToSend);
                }

            } else if (state == TRPseudoState.Active) {
                restartIdleTimer();
                tcbm = (TCResponseMessageImpl) TcapFactory.createTCResponseMessage();

                tcbm.setDestinationTransactionId(this.remoteTransactionId);
                if (this.scheduledComponentList.size() > 0) {
                    Component[] componentsToSend = new Component[this.scheduledComponentList.size()];
                    this.prepareComponents(componentsToSend);
                    tcbm.setComponent(componentsToSend);
                }

            } else {
                throw new TCAPSendException(String.format("State is not %s or %s: it is %s", TRPseudoState.Active,
                        TRPseudoState.InitialReceived, this.state));
            }

            AsnOutputStream aos = new AsnOutputStream();
            try {
                tcbm.encode(aos);
                if (this.provider.getStack().getStatisticsEnabled()) {
                    this.provider.getStack().getCounterProviderImpl().updateTcResponseSentCount(this);
                }
                this.provider.send(aos.toByteArray(), event.getReturnMessageOnError(), this.remoteAddress, this.localAddress,
                        this.seqControl, this.getNetworkId(), this.localSsn);

                this.scheduledComponentList.clear();
            } catch (Exception e) {
                // FIXME: remove freshly added invokes to free invoke ID??
                if (logger.isEnabledFor(Level.ERROR)) {
                    logger.error("Failed to send message: ", e);
                }
                throw new TCAPSendException("Failed to send TC-Response message: " + e.getMessage(), e);
            } finally {
                // FIXME: is this proper place - should we not release in case
                // of error ?
                release();
            }
        } finally {
            dialogLock.unlock();
        }
    }
1219523
public JsonRequestHandler getRequestHandler(RequestType pType) {
        JsonRequestHandler handler = requestHandlerMap.get(pType);
        if (handler == null) {
            throw new UnsupportedOperationException("Unsupported operation '" + pType + "'");
        }
        return handler;
    }
1328616
private void parseSpecs(URL url) throws MalformedURLException
    {
        String spec = url.getFile();

        int separator = spec.indexOf('!');
        /*
         * REMIND: we don't handle nested JAR URLs
         */
        if (separator == -1) {
            throw new MalformedURLException("no ! found in url spec:" + spec);
        }

        // Get the protocol
        String protocol = spec.substring(0, spec.indexOf(":"));

        // This is the important part: we use a URL Stream Handler Factory to find the URL Stream handler to use for
        // the nested protocol.
        this.jarFileURL =
            new URL(null, spec.substring(0, separator++), this.handlerFactory.createURLStreamHandler(protocol));
        this.entryName = null;

        /* if ! is the last letter of the innerURL, entryName is null */
        if (++separator != spec.length()) {
            this.entryName = spec.substring(separator, spec.length());
            try {
                // Note: we decode using UTF8 since it's the W3C recommendation.
                // See http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
                this.entryName = URLDecoder.decode(this.entryName, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // Not supporting UTF-8 as a valid encoding for some reasons. We consider XWiki cannot work
                // without that encoding.
                throw new RuntimeException("Failed to URL decode [" + this.entryName + "] using UTF-8.", e);
            }
        }
    }
366945
public static Filter handleURL(ParsedURL url) {
    if(LOG.isDebuggingFiner()) {
      LOG.debugFiner("handleURL " + url.toString());
    }
    if(!isCompatibleURLStatic(url)) {
      return null;
    }
    int id;
    try {
      id = ParseUtil.parseIntBase10(url.getPath());
    }
    catch(NumberFormatException e) {
      return null;
    }
    SoftReference<RenderedImage> ref = images.get(id);
    if(ref != null) {
      RenderedImage ri = ref.get();
      if(ri == null) {
        LOG.warning("Referenced image has expired from the cache!");
      }
      else {
        return new RedRable(GraphicsUtil.wrap(ri));
      }
    }
    // Image not found in registry.
    return null;
  }
624951
private static HttpURLConnection openURLConnection(URL url) throws IOException {
		// This method should be moved to a utility class in BioJava 5.0

		final int timeout = 5000;
		final String useragent = "BioJava";

		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestProperty("User-Agent", useragent);
		conn.setInstanceFollowRedirects(true);
		conn.setConnectTimeout(timeout);
		conn.setReadTimeout(timeout);

		int status = conn.getResponseCode();
		while (status == HttpURLConnection.HTTP_MOVED_TEMP
				|| status == HttpURLConnection.HTTP_MOVED_PERM
				|| status == HttpURLConnection.HTTP_SEE_OTHER) {
			// Redirect!
			String newUrl = conn.getHeaderField("Location");

			if(newUrl.equals(url.toString())) {
				throw new IOException("Cyclic redirect detected at "+newUrl);
			}

			// Preserve cookies
			String cookies = conn.getHeaderField("Set-Cookie");

			// open the new connection again
			url = new URL(newUrl);
			conn.disconnect();
			conn = (HttpURLConnection) url.openConnection();
			if(cookies != null) {
				conn.setRequestProperty("Cookie", cookies);
			}
			conn.addRequestProperty("User-Agent", useragent);
			conn.setInstanceFollowRedirects(true);
			conn.setConnectTimeout(timeout);
			conn.setReadTimeout(timeout);
			conn.connect();

			status = conn.getResponseCode();

			logger.info("Redirecting from {} to {}", url, newUrl);
		}
		conn.connect();

		return conn;
	}
127753
public <T> ISyncHandler<? super T, ? extends ISyncableData> getHandler(T caller)
	{
		@SuppressWarnings("unchecked")
		ISyncHandler<? super T, ? extends ISyncableData> handler = (ISyncHandler<? super T, ? extends ISyncableData>) handlers.get(caller.getClass());
		if (handler == null)
		{
			MalisisCore.log.error("No ISyncHandler registered for type '{}'", caller.getClass());
			return null;
		}

		return handler;
	}
12680
public static Cursor fromUrlSafe(String urlSafe) {
    try {
      return Cursor.copyFrom(BaseEncoding.base64Url().decode(urlSafe));
    } catch (IllegalArgumentException e) {
      throw new IllegalStateException("Unexpected decoding exception", e);
    }
  }
949776
private static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncUnaryRequestCall(
      UnaryRequestMethod<ReqT, RespT> method) {
    return new UnaryServerCallHandler<>(method);
  }
627371
public RequestBuilder get(final String url) {

    checkNotNull(url, "url may not be null");
    final AsyncHttpClient.BoundRequestBuilder ningRequestBuilder = asyncHttpClient.prepareGet(url);
    return createNewRequestBuilder(url, ningRequestBuilder);
  }
1039549
@Pure
	@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
	public static URL getParentURL(URL url) throws MalformedURLException {
		if (url == null) {
			return url;
		}
		String path = url.getPath();
		final String prefix;
		final String parentStr;

		switch (URISchemeType.getSchemeType(url)) {
		case JAR:
			final int index = path.indexOf(JAR_URL_FILE_ROOT);
			assert index > 0;
			prefix = path.substring(0, index + 1);
			path = path.substring(index + 1);
			parentStr = URL_PATH_SEPARATOR;
			break;
		case FILE:
			prefix = null;
			parentStr = ".." + URL_PATH_SEPARATOR; //$NON-NLS-1$
			break;
			//$CASES-OMITTED$
		default:
			prefix = null;
			parentStr = URL_PATH_SEPARATOR;
		}

		if (path == null || "".equals(path)) { //$NON-NLS-1$
			path = parentStr;
		}
		int index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
		if (index == -1) {
			path = parentStr;
		} else if (index == path.length() - 1) {
			index = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR, index - 1);
			if (index == -1) {
				path = parentStr;
			} else {
				path = path.substring(0, index + 1);
			}
		} else {
			path = path.substring(0, index + 1);
		}

		if (prefix != null) {
			path = prefix + path;
		}

		return new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
	}
1084492
private static String getJmxResult(MBeanServerConnection connetion, String url) throws Exception {
        ObjectName name = new ObjectName(DruidStatService.MBEAN_NAME);

        return (String) conn.invoke(name, "service", new String[]{url},
                new String[]{String.class.getName()});
    }
817692
public URL getURL(final String pUrl) {

        try {
            return new URL(pUrl);
        } catch (final MalformedURLException e) {
            throw new ConversionException("Cannot parse URL from string " + pUrl, e);
        }
    }
679824
public static PageFlowRequestWrapper unwrap( ServletRequest servletRequest )
    {
        servletRequest = InternalUtils.unwrapMultipart( servletRequest );
        
        while ( ! ( servletRequest instanceof PageFlowRequestWrapper ) )
        {
            if ( ! ( servletRequest instanceof ServletRequestWrapper ) ) return null;
            servletRequest = ( ( ServletRequestWrapper ) servletRequest ).getRequest();
        }
        
        return ( PageFlowRequestWrapper ) servletRequest;
    }