Creates a managed connection.

@param subject
the subject
@param requestInfo
the request information
@return the managed connection
@throws ResourceException
generic exception
14903
@Override
    final public ManagedConnection createManagedConnection(
                                                           final Subject subject, final ConnectionRequestInfo requestInfo)
                    throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "createManagedConnection", new Object[] {
                                                                              JmsJcaManagedConnection.subjectToString(subject),
                                                                              requestInfo });
        }

        // If we have some request information then see if it already has a core
        // connection associated with it

        JmsJcaConnectionRequestInfo jmsJcaRequestInfo = null;
        SICoreConnection requestCoreConnection = null;
        SICoreConnection coreConnection = null;

        if (requestInfo != null) {

            // Check we have the right type of request information

            if (!(requestInfo instanceof JmsJcaConnectionRequestInfo)) {

                throw new ResourceAdapterInternalException(NLS
                                .getFormattedMessage(("EXCEPTION_RECEIVED_CWSJR1022"),
                                                     new Object[] {
                                                                   "createManagedConnection",
                                                                   JmsJcaConnectionRequestInfo.class
                                                                                   .getName(),
                                                                   requestInfo.getClass().getName() },
                                                     null));

            }

            jmsJcaRequestInfo = (JmsJcaConnectionRequestInfo) requestInfo;
            requestCoreConnection = jmsJcaRequestInfo.getSICoreConnection();

            if (requestCoreConnection != null) {
                // Check that the core connection is still available, ie hasn't been closed. If the
                // core connection is no longer available, null it out and continue without it.

                try {
                    // There is no isAvailable() method on a core connection we use getConnectionListeners()
                    // which is believed to be the cheapest alternative method.
                    requestCoreConnection.getConnectionListeners();

                } catch (final SIException e) {
                    // No FFDC code needed
                    if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
                        SibTr.debug(TRACE, "Connection Request Info core connection no longer available");
                    jmsJcaRequestInfo.setSICoreConnection(null);
                    requestCoreConnection = null;
                } catch (final SIErrorException e) {
                    // No FFDC code needed
                    if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
                        SibTr.debug(TRACE, "Connection Request Info core connection no longer available");
                    jmsJcaRequestInfo.setSICoreConnection(null);
                    requestCoreConnection = null;
                }
            }
        }

        // See if we can get a user name and password from the subject or
        // request information

        final JmsJcaUserDetails userDetails = getUserDetails(subject,
                                                             requestInfo);

        // If we didn't get any request information or we did but it didn't
        // contain a core connection, create a new one

        if (requestCoreConnection == null) {

            // Obtain a core connection factory

            final SICoreConnectionFactory coreConnectionFactory;

            if (!UTEHelperFactory.jmsTestEnvironmentEnabled) {

                try {

                    coreConnectionFactory = SICoreConnectionFactorySelector
                                    .getSICoreConnectionFactory(FactoryType.TRM_CONNECTION);

                } catch (final SIException exception) {

                    FFDCFilter.processException(exception, CLASS_NAME
                                                           + ".createManagedConnection", FFDC_PROBE_5, this);
                    throw new ResourceException(NLS.getFormattedMessage(
                                                                        "EXCEPTION_RECEIVED_CWSJR1021", new Object[] {
                                                                                                                      exception, "getSICoreConnectionFactory" },
                                                                        null), exception);

                }

            } else {

                coreConnectionFactory = UTEHelperFactory.getHelperInstance()
                                .setupJmsTestEnvironment();

            }

            // Check we have obtained a core connection factory successfully

            if (coreConnectionFactory == null) {

                throw new ResourceAdapterInternalException(NLS
                                .getFormattedMessage(
                                                     ("SICORECONNECTION_ERROR_CWSJR1023"),
                                                     new Object[] { "createManagedConnection" },
                                                     null));

            }

            // Create a connection

            try {

                final Map trmProperties = getTrmProperties();

                if (userDetails == null) {

                    requestCoreConnection = coreConnectionFactory
                                    .createConnection(subject, trmProperties);

                } else {

                    requestCoreConnection = coreConnectionFactory
                                    .createConnection(userDetails.getUserName(),
                                                      userDetails.getPassword(), trmProperties);

                }

            } catch (final SIException exception) {

                FFDCFilter.processException(exception, CLASS_NAME
                                                       + ".createManagedConnection", FFDC_PROBE_1, this);
                if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled()) {
                    SibTr.exception(this, TRACE, exception);
                }
                throw new ResourceException(NLS.getFormattedMessage(
                                                                    "EXCEPTION_RECEIVED_CWSJR1028", new Object[] {
                                                                                                                  exception, "createManagedConnection" }, null),
                                exception);

            } catch (final SIErrorException exception) {

                FFDCFilter.processException(exception, CLASS_NAME
                                                       + ".createManagedConnection", FFDC_PROBE_2, this);
                if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled()) {
                    SibTr.exception(this, TRACE, exception);
                }
                throw new ResourceException(NLS.getFormattedMessage(
                                                                    "EXCEPTION_RECEIVED_CWSJR1028", new Object[] {
                                                                                                                  exception, "createManagedConnection" }, null),
                                exception);

            }

            // If we have some request information, set the core connection back
            // into it

            if (jmsJcaRequestInfo != null) {

                jmsJcaRequestInfo.setSICoreConnection(requestCoreConnection);

            }

            // This is a new coreConnection so set this parent coreConnection in 
            // the managedConnection by assigning it to the coreConnection here.
            // The managedconnection will now have full control over the parent
            // coreconnection.
            coreConnection = requestCoreConnection;
        }
        else
        {

            try {
                // We are here as we already have a valid coreconnection in our requestInfo, this
                // means we already have a managedConnection that is looking at the parent, so we
                // need to create a clone of that coreConnection to pass into our new managedConnection.

                // Create a clone to give to the managed connection object which will be stored in the 
                // J2C connection pool.
                coreConnection = requestCoreConnection.cloneConnection();
            } catch (final SIException e) {
                FFDCFilter.processException(e, CLASS_NAME + ".createManagedConnection", FFDC_PROBE_7, this);
                if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled())
                    SibTr.exception(this, TRACE, e);
                throw new ResourceException(NLS.getFormattedMessage("EXCEPTION_RECEIVED_CWSJR1028",
                                                                    new Object[] { e, "createManagedConnection" },
                                                                    null), e);
            } catch (final SIErrorException e) {
                FFDCFilter.processException(e, CLASS_NAME + ".createManagedConnection", FFDC_PROBE_8, this);
                if (TraceComponent.isAnyTracingEnabled() && TRACE.isEventEnabled())
                    SibTr.exception(this, TRACE, e);
                throw new ResourceException(NLS.getFormattedMessage("EXCEPTION_RECEIVED_CWSJR1028",
                                                                    new Object[] { e, "createManagedConnection" },
                                                                    null), e);
            }
        }

        final JmsJcaManagedConnection managedConnection;

        try {

            // Create a managed connection

            if ((getShareDataSourceWithCMP() != null)
                && (getShareDataSourceWithCMP().booleanValue())) {

                // ShareDataSourceWithCMP is set - return a managed connection
                // implementing SynchronizationProvider

                managedConnection = new JmsJcaManagedConnectionSynchronizationProvider(
                                this, coreConnection, userDetails, subject);

            } else {

                // ShareDataSourceWithCMP is not set - return a normal managed
                // connection

                managedConnection = new JmsJcaManagedConnection(this,
                                coreConnection, userDetails, subject);

            }

        } catch (final SIException exception) {

            FFDCFilter.processException(exception, CLASS_NAME
                                                   + ".createManagedConnection", FFDC_PROBE_3, this);
            throw new ResourceException(NLS.getFormattedMessage(
                                                                "EXCEPTION_RECEIVED_CWSJR1026", new Object[] { exception,
                                                                                                              "createManagedConnection" }, null), exception);

        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "createManagedConnection",
                       managedConnection);
        }
        return managedConnection;

    }
837981
@Override
	public synchronized ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
    {
        checkNotClosed();
        throw new FFMQException("Unsupported feature","UNSUPPORTED_FEATURE");
    }
477801
public MailRequest newTextMailRequest(String requestId, String subject, String body) {
        return createMailRequest(requestId, false, subject, body);
    }
1241353
@Override
    public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector, ServerSessionPool sessionPool,
            int maxMessages) throws JMSException {
        throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
    }
157518
private SICoreConnection createConnection(Certificate[] certificate) throws SIAuthenticationException, SIResourceException, SINotAuthorizedException {
        if (TraceComponent.isAnyTracingEnabled()
            && CoreSPIConnFactory.tc.isEntryEnabled()) {
            SibTr.entry(CoreSPIConnFactory.tc, "createConnection", certificate);
        }

        // Check that the Messaging Engine is started
        checkStarted();

        Subject subject = null;

        try {
            subject = _authentication.login(certificate);
        } catch (MessagingAuthenticationException e) {
            throw new SIAuthenticationException(e.getMessage());
        }
        SICoreConnection connection = createConnection(subject, null);
        if (TraceComponent.isAnyTracingEnabled()
            && CoreSPIConnFactory.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnFactory.tc, "createConnection", connection);
        return connection;
    }
949520
public ApiResponse<ApiSuccessResponse> createContactWithHttpInfo(CreateContactData createContactData) throws ApiException {
        com.squareup.okhttp.Call call = createContactValidateBeforeCall(createContactData, null, null);
        Type localVarReturnType = new TypeToken<ApiSuccessResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
1102039
public ConnectionInfo getConnection(String name) {
    final URI uri = uriWithPath("./connections/" + encodePathSegment(name));
    return this.rt.getForObject(uri, ConnectionInfo.class);
  }
16112
def requestConnection(self, wanInterfaceId=1, timeout=1):
        
        namespace = Wan.getServiceType("requestConnection") + str(wanInterfaceId)
        uri = self.getControlURL(namespace)

        self.execute(uri, namespace, "RequestConnection", timeout=timeout)
1239022
public URLConnection getResourceConnection (String name) throws ResourceException {
        name = removeNamePrefix(name).replace('\\', '/');

        //remove the leading / as we are trying with a leading / now
        if (name.startsWith("WEB-INF/groovy/")) {
            name = name.substring(15);//just for uniformity
        } else if (name.startsWith("/")) {
            name = name.substring(1);
        }

        /*
        * Try to locate the resource and return an opened connection to it.
        */
        try {
            URL url = servletContext.getResource('/' + name);
            if (url == null) {
                url = servletContext.getResource("/WEB-INF/groovy/" + name);
            }
            if (url == null) {
                throw new ResourceException("Resource \"" + name + "\" not found!");
            }
            return url.openConnection();
        } catch (IOException e) {
            throw new ResourceException("Problems getting resource named \"" + name + "\"!", e);
        }
    }
1105951
private JMXConnector getMBeanServerConnection(String controllerHost, int controllerPort, HashMap<String, Object> environment) throws MalformedURLException, IOException {
        JMXServiceURL serviceURL = new JMXServiceURL("REST", controllerHost, controllerPort, "/IBMJMXConnectorREST");
        return new ClientProvider().newJMXConnector(serviceURL, environment);
    }
274870
@Override
	public TopicConnection createTopicConnection() throws JMSException
    {
    	String username = getStringProperty(Context.SECURITY_PRINCIPAL,null); 
    	String password = getStringProperty(Context.SECURITY_CREDENTIALS,null);
    	
        return createTopicConnection(username,password);
    }
1225655
@Override
    public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages)
            throws JMSException {
        throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
    }
45956
@Override
    public IApiConnector createConnector(ApiRequest req, Api api, RequiredAuthType authType, boolean hasDataPolicy, IConnectorConfig connectorConfig) {
        return (request, resultHandler) -> {
            // Apply options from config as our base case
            ApimanHttpConnectorOptions httpOptions = new ApimanHttpConnectorOptions(config)
                    .setHasDataPolicy(hasDataPolicy)
                    .setRequiredAuthType(authType)
                    .setTlsOptions(tlsOptions)
                    .setUri(parseApiEndpoint(api))
                    .setSsl(api.getEndpoint().toLowerCase().startsWith("https")); //$NON-NLS-1$
            // If API has endpoint properties indicating timeouts, then override config.
            setAttributesFromApiEndpointProperties(api, httpOptions);
            // Get from cache
            HttpClient client = clientFromCache(httpOptions);
            return new HttpConnector(vertx, client, request, api, httpOptions, connectorConfig, resultHandler).connect();
         };
    }
545255
private String resolveSubjectToDatastream(String subject) throws ServerException{
        String pidURI = PID.toURI(m_obj.getPid());
        if (subject.startsWith(pidURI)) {
            if (subject.length() == pidURI.length()) {
                return "RELS-EXT";
            }
            if (subject.charAt(pidURI.length()) == '/') {
                return "RELS-INT";
            }
        }
        throw new GeneralException("Cannot determine which relationship datastream to update for subject " + subject + ".  Relationship subjects must be the URI of the object or the URI of a datastream within the object.");
    }
617115
public ApiResponse<TokenInfoSuccessResponse> tokenInfoWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = tokenInfoValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<TokenInfoSuccessResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
98579
protected Connection createConnection() throws JMSException {
        if (connectionFactory instanceof QueueConnectionFactory) {
            return ((QueueConnectionFactory) connectionFactory).createQueueConnection();
        }
        return connectionFactory.createConnection();
    }
637513
@Override
    final public ManagedConnectionMetaData getMetaData()
                    throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "getMetaData");
        }

        if (_metaData == null) {
            _metaData = new JmsJcaManagedConnectionMetaData();
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "getMetaData", _metaData);
        }
        return _metaData;

    }