Create a new transaction resource and add it to the registry

@param externalPath the external path
@return 201 with the transaction id and expiration date
@throws URISyntaxException if URI syntax exception occurred
977503
@POST
    public Response createTransaction(@PathParam("path") final String externalPath) throws URISyntaxException {

        if (batchService.exists(session.getId(), getUserPrincipal())) {
            LOGGER.debug("renewing transaction {}", session.getId());
            batchService.refresh(session.getId(), getUserPrincipal());
            final Response.ResponseBuilder res = noContent();
            session.getFedoraSession().getExpires().ifPresent(expires -> {
                res.expires(from(expires));
            });
            return res.build();
        }

        if (externalPath != null && !externalPath.isEmpty()) {
            return status(BAD_REQUEST).build();
        }

        batchService.begin(session.getFedoraSession(), getUserPrincipal());
        session.makeBatchSession();
        LOGGER.info("Created transaction '{}'", session.getId());

        final Response.ResponseBuilder res = created(
                new URI(translator().toDomain("/tx:" + session.getId()).toString()));
        session.getFedoraSession().getExpires().ifPresent(expires -> {
            res.expires(from(expires));
        });
        return res.build();
    }
663558
@Override
    public boolean importTransaction(String globalId, int expires) throws SystemException {

        //The first thing we need to do is distinguish between local and remote invocations. If the UOW currently associated
        //with the thread is a global txn then we know the invocation must be local. The other case is where the remote servers
        //web container has begun a local txn in the absence of the global context. We do know that there was a global txn on 
        //invocation else there wouldn't even be a cc available.
        final UOWCoordinator uowCoord = _uowc.getUOWCoord();
        _threadUOWCoord.set(uowCoord);

        if (uowCoord != null && uowCoord.isGlobal()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "The Web Service request is a local invocation");

            ((DistributableTransaction) uowCoord).resumeAssociation();
            return false;
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "The Web Service request is a remote invocation");

        try {
            TMHelper.checkTMState();
        } catch (NotSupportedException e) {
            final SystemException se = new SystemException();
            se.initCause(e);
            throw se;
        }

        //The web container will start a local tran as there will not be a global context
        //on thread. We need to suspend this before attaching the global tran
        final LocalTransactionCoordinator ltc = LocalTranCurrentSet.instance().suspend();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "Suspended LTC", ltc);

        boolean createdNewTransaction = false;

        DistributableTransaction tx = getTransactionForID(globalId);

        if (tx == null) {
            tx = new EmbeddableTransactionImpl(expires, globalId);
            createdNewTransaction = true;

            new TransactionWrapper((EmbeddableTransactionImpl) tx);
        }

        _threadImportedTran.set(tx);

        // Add association to police single thread per tran
        tx.addAssociation();

        // Resume transaction on this thread
        try {
            _tm.resume((Transaction) tx);
        } catch (Exception e) {
            SystemException se = new SystemException();
            se.initCause(e);
            throw se;
        }

        return createdNewTransaction;
    }
205809
private URI toUri(final String path) {
        try {
            return new URI(null, null, path, null);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
1043628
public URL signUrlWithSigner(String bucketName, String blobName, String keyPath)
      throws IOException {
    // [START signUrlWithSigner]
    URL signedUrl =
        storage.signUrl(
            BlobInfo.newBuilder(bucketName, blobName).build(),
            14,
            TimeUnit.DAYS,
            SignUrlOption.signWith(
                ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))));
    // [END signUrlWithSigner]
    return signedUrl;
  }
819779
@Override
    public boolean addSync() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.entry(this, tc, "addSync");
        }

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();

        if (uowCoord == null) {
            // No transaction context.  Should never happen.
            // removed null check on mcWrapper since it is redundant from the above code (mcWrapper.getUOWCoordinator())
            String pmiName = mcWrapper.gConfigProps.cfName;

            Object[] parms = new Object[] { "addSync", pmiName };
            Tr.error(tc, "NO_VALID_TRANSACTION_CONTEXT_J2CA0040", parms); 
            throw new ResourceException("INTERNAL ERROR: No valid transaction context present");

        }

        try {

            //  No need to register for synchronization for unshared/LTC/res-control=Application.
            //  Instead of cleanup being done via after completion it will either happen at close or
            //  commit/rollback which ever happens last.  This will allow the connection to be returned
            //  to the pool prior to the end of the LTC scope allowing better utilization of the connection.
            boolean shareable = mcWrapper.getConnectionManager().shareable();
            if (!shareable && !J2CUtilityClass.isContainerAtBoundary(mcWrapper.pm.connectorSvc.transactionManager)) {
                //Register an instance of a no-transaction wrapper
                // so the TM will create an RRS NativeLocalTranasction.  The wrapper
                // provides "empty" TransactioWrapper and Synchronization behaviors,
                // but indicates to the TM that the LTC requires RRS support.  
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(new RRSNoTransactionWrapper());

                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
                    Tr.exit(this, tc, "addSync", "returning without registering.");
                }
                return false;
            } else { // Register a synchronization with the Transaction Manager
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(this);
                mcWrapper.markRRSLocalTransactionWrapperInUse();
                registeredForSync = true;
            }
        } catch (ResourceException e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ejs.j2c.RRSLocalTransactionWrapper.addSync", "594", this);
            Object[] parms = new Object[] { "addSync", e, "Exception" };
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", parms);
            throw e;
        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ejs.j2c.RRSLocalTransactionWrapper.addSync", "605", this);
            Object[] parms = new Object[] { "addSync", e, "Exception" };
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", parms);
            ResourceException re = new ResourceException("addSync: caught Exception");
            re.initCause(e);
            throw re;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.exit(this, tc, "addSync", registeredForSync);
        }

        return registeredForSync;

    }
828644
public WritableByteChannel create(URI path) throws IOException {
    logger.atFine().log("create(%s)", path);
    return create(path, CreateFileOptions.DEFAULT);
  }
1148080
public static URI urlToUri( URL url ) throws URISyntaxException {

		URI uri;
		try {
			// Possible failing step.
			uri = url.toURI();

		} catch( Exception e ) {
			// URL did not comply with RFC 2396 => illegal non-escaped characters.
			try {
				uri = new URI(
						url.getProtocol(),
						url.getUserInfo(),
						url.getHost(),
						url.getPort(),
						url.getPath(),
						url.getQuery(),
						url.getRef());

			} catch( Exception e1 ) {
				throw new URISyntaxException( String.valueOf( url ), "Broken URL." );
			}
		}

		uri = uri.normalize();
		return uri;
	}
376250
public HttpCopy createCopyMethod(final String sourcePath, final String destinationPath) {
        return new HttpCopy(repositoryURL + sourcePath, repositoryURL + destinationPath);
    }
1079646
public static LocalFileResource newResource(String normalizedPath, String repositoryPath) {
        return new LocalFileResource(normalizedPath, repositoryPath, null);
    }
293736
public URL signUrlWithSigner(String keyPath) throws IOException {
    // [START signUrlWithSigner]
    URL signedUrl =
        blob.signUrl(
            14,
            TimeUnit.DAYS,
            SignUrlOption.signWith(
                ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))));
    // [END signUrlWithSigner]
    return signedUrl;
  }
325530
public void setExternalGraphicPath( String externalGraphicPath ) throws MalformedURLException {
        if (externalGraphicPath == null) {
            PointSymbolizerWrapper pointSymbolizerWrapper = adapt(PointSymbolizerWrapper.class);
            if (pointSymbolizerWrapper != null) {
                Graphic graphic = pointSymbolizerWrapper.getGraphic();
                graphic.graphicalSymbols().clear();
                externalGraphic = null;
            }
        } else {
            PointSymbolizerWrapper pointSymbolizerWrapper = adapt(PointSymbolizerWrapper.class);
            if (pointSymbolizerWrapper != null) {
                Graphic graphic = pointSymbolizerWrapper.getGraphic();
                graphic.graphicalSymbols().clear();
                String urlStr = externalGraphicPath;
                if (!externalGraphicPath.startsWith("http:") && !externalGraphicPath.startsWith("file:")) { //$NON-NLS-1$ //$NON-NLS-2$
                    urlStr = "file:" + externalGraphicPath; //$NON-NLS-1$
                } else if (externalGraphicPath.startsWith("./")) {
                    urlStr = "file:" + externalGraphicPath; //$NON-NLS-1$
                }
                externalGraphic = sb.createExternalGraphic(new URL(urlStr), getFormat(externalGraphicPath));
                graphic.graphicalSymbols().add(externalGraphic);
            }
            setExternalGraphicPath(externalGraphicPath, externalGraphic);
        }
    }
763190
public <R> R withCommitTransaction(TransFunc<R> transFunc) throws IOException {
    return withTransaction(transFunc, true);
  }
959530
public static String externalUrl(SlingHttpServletRequest request, String path) {
        return LinkUtil.getAbsoluteUrl(request, LinkUtil.getUrl(request, path));
    }
1242642
private TransactionalDataSource getTransactionalDataSource(
            ODataRequestContext odataRequestContext, Type type) throws ODataException {
        DataSource dataSource = dataSourceFactory.getDataSource(odataRequestContext, type.getFullyQualifiedName());
        String dataSourceKey = dataSource.getClass().toString();
        if (dataSourceMap.containsKey(dataSourceKey)) {
            return dataSourceMap.get(dataSourceKey);
        } else {
            TransactionalDataSource transactionalDataSource = dataSource.startTransaction();

            dataSourceMap.put(dataSourceKey, transactionalDataSource);
            return transactionalDataSource;
        }
    }
103166
public static String modifyURIPath(String uri, String newPath) {
        try {
            URI uriObj = new URI(uri);
            return uriToString(URLUtils.modifyURIPath(uriObj, newPath));
        }
        catch (URISyntaxException e) {
            try {
                return (new NetworkInterfaceURI(uri)).modifyURIPath(newPath);
            }
            catch (IllegalArgumentException ne) {
                throw new IllegalArgumentException(ne.getMessage(), ne);
            }
        }
    }
235798
@Override
    public String path() {
        try {
            return new URI(request.uri()).getRawPath();
        } catch (URISyntaxException e) { //NOSONAR
            // Should never be the case.
            return uri();
        }
    }
1170554
public static String buildURIAsString(String scheme, String userInfo,
            String host, int port, String path, String query, String fragment) throws URISyntaxException {
        URI helperURI;
        try {
            helperURI = new URI(scheme, userInfo, host, port, path, query, fragment);
        } catch (URISyntaxException e) {
            return NetworkInterfaceURI.buildURIToString(scheme, userInfo, host, port, path, query, fragment);
        }
        return helperURI.toString();
    }