Search in sources :

Example 6 with Consumer

use of com.swiftmq.amqp.v100.client.Consumer in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POAttachDurableConsumer po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    DeliveryMemory deliveryMemory = po.getDeliveryMemory();
    if (deliveryMemory.getLinkName() != null)
        deliveryMemory.setLinkName(po.getLinkName());
    DurableConsumer consumer = new DurableConsumer(mySession, po.getSource(), po.getLinkName(), po.getLinkCredit(), po.getQoS(), deliveryMemory);
    int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
    consumer.setHandle(handle);
    po.setLink(consumer);
    waitingPO.put(po.getLinkName(), po);
    try {
        AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
        attachFrame.setName(new AMQPString(po.getLinkName()));
        attachFrame.setHandle(new Handle(handle));
        attachFrame.setRole(Role.RECEIVER);
        if (consumer.getQoS() == QoS.AT_MOST_ONCE)
            attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
        Source source = new Source();
        String s = po.getSource();
        if (s != null)
            source.setAddress(new AddressString(s));
        else
            source.setDynamic(AMQPBoolean.TRUE);
        // This identifies a durable
        source.setDurable(TerminusDurability.CONFIGURATION);
        source.setExpiryPolicy(po.getExpiryPolicy());
        source.setTimeout(new Seconds(0));
        Map m = null;
        if (po.isNoLocal()) {
            m = new HashMap();
            m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
        }
        if (po.getSelector() != null) {
            if (m == null)
                m = new HashMap();
            m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
        }
        if (m != null)
            source.setFilter(new FilterSet(m));
        attachFrame.setSource(source);
        Target target = new Target();
        target.setAddress(new AddressString(uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++)));
        target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        target.setTimeout(new Seconds(0));
        attachFrame.setTarget(target);
        attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
        outboundHandler.send(attachFrame);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) NoLocalFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.NoLocalFilter) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) SelectorFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.SelectorFilter)

Example 7 with Consumer

use of com.swiftmq.amqp.v100.client.Consumer in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POFillCache po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    Consumer c = po.getConsumer();
    FlowFrame flowFrame = new FlowFrame(mySession.getChannel());
    flowFrame.setHandle(new Handle(c.getHandle()));
    flowFrame.setAvailable(new AMQPUnsignedInt(0));
    flowFrame.setDrain(AMQPBoolean.FALSE);
    flowFrame.setNextIncomingId(new TransferNumber(nextIncomingId));
    flowFrame.setNextOutgoingId(new TransferNumber(nextOutgoingId));
    flowFrame.setLinkCredit(new AMQPUnsignedInt(po.getLinkCredit()));
    flowFrame.setIncomingWindow(new AMQPUnsignedInt(incomingWindow));
    flowFrame.setOutgoingWindow(new AMQPUnsignedInt(outgoingWindow));
    if (po.getLastDeliveryId() != -1)
        flowFrame.setDeliveryCount(new SequenceNo(po.getLastDeliveryId()));
    TxnIdIF txnIdIF = po.getTxnIdIF();
    if (txnIdIF != null) {
        Map map = new HashMap();
        map.put(new AMQPSymbol("txn-id"), txnIdIF);
        try {
            flowFrame.setProperties(new Fields(map));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    outboundHandler.send(flowFrame);
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException)

Example 8 with Consumer

use of com.swiftmq.amqp.v100.client.Consumer in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POAttachConsumer po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    String name = null;
    DeliveryMemory deliveryMemory = po.getDeliveryMemory();
    if (deliveryMemory.getLinkName() != null)
        name = deliveryMemory.getLinkName();
    else {
        name = uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++);
        deliveryMemory.setLinkName(name);
    }
    Consumer consumer = null;
    if (po.getLinkCredit() == -1)
        consumer = new Consumer(mySession, po.getSource(), name, po.getQoS(), deliveryMemory);
    else
        consumer = new Consumer(mySession, po.getSource(), name, po.getLinkCredit(), po.getQoS(), deliveryMemory);
    int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
    consumer.setHandle(handle);
    po.setLink(consumer);
    waitingPO.put(name, po);
    try {
        AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
        attachFrame.setName(new AMQPString(name));
        attachFrame.setHandle(new Handle(handle));
        attachFrame.setRole(Role.RECEIVER);
        if (consumer.getQoS() == QoS.AT_MOST_ONCE)
            attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
        Source source = new Source();
        String s = po.getSource();
        if (s != null)
            source.setAddress(new AddressString(s));
        else
            source.setDynamic(AMQPBoolean.TRUE);
        source.setDurable(TerminusDurability.NONE);
        source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        source.setTimeout(new Seconds(0));
        Map m = null;
        if (po.isNoLocal()) {
            m = new HashMap();
            m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
        }
        if (po.getSelector() != null) {
            if (m == null)
                m = new HashMap();
            m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
        }
        if (m != null)
            source.setFilter(new FilterSet(m));
        attachFrame.setSource(source);
        Target target = new Target();
        target.setAddress(new AddressString(name));
        target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        target.setTimeout(new Seconds(0));
        attachFrame.setTarget(target);
        attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
        outboundHandler.send(attachFrame);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) NoLocalFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.NoLocalFilter) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) SelectorFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.SelectorFilter)

Example 9 with Consumer

use of com.swiftmq.amqp.v100.client.Consumer in project swiftmq-client by iitsoftware.

the class DurableConsumer method unsubscribe.

/**
 * Unsubscribes the durable consumer and destroys the durable link.
 *
 * @throws AMQPException
 */
public void unsubscribe() throws AMQPException {
    if (!closed)
        close();
    Semaphore sem = new Semaphore();
    POAttachDurableConsumer po = new POAttachDurableConsumer(sem, name, source, linkCredit, qoS, false, null, TerminusExpiryPolicy.LINK_DETACH, deliveryMemory);
    mySession.getSessionDispatcher().dispatch(po);
    sem.waitHere();
    if (!po.isSuccess())
        throw new AMQPException(po.getException());
    DurableConsumer c = (DurableConsumer) po.getLink();
    c.close();
}
Also used : POAttachDurableConsumer(com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer) Semaphore(com.swiftmq.tools.concurrent.Semaphore) POAttachDurableConsumer(com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)

Example 10 with Consumer

use of com.swiftmq.amqp.v100.client.Consumer in project camel by apache.

the class OAuthToken method getOrRefreshAccessToken.

private synchronized void getOrRefreshAccessToken() {
    if (token == null) {
        LOGGER.debug("Generate OAuth token");
        token = OAuthClientUtils.getAccessToken(WebClient.create(configuration.getOauthTokenUrl()), new Consumer(configuration.getOauthClientId(), configuration.getOauthClientSecret()), new ResourceOwnerGrant(configuration.getUserName(), configuration.getPassword()), true);
        LOGGER.debug("OAuth token expires in {}s", token.getExpiresIn());
        // Set expiration time related info in milliseconds
        token.setIssuedAt(System.currentTimeMillis());
        token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
        authString = token.toString();
        if (token.getExpiresIn() > 0) {
            expireAt = token.getIssuedAt() + token.getExpiresIn();
        }
    } else if (expireAt > 0 && System.currentTimeMillis() >= expireAt) {
        LOGGER.debug("OAuth token is expired, refresh it");
        token = OAuthClientUtils.refreshAccessToken(WebClient.create(configuration.getOauthTokenUrl()), new Consumer(configuration.getOauthClientId(), configuration.getOauthClientSecret()), token, null, false);
        LOGGER.debug("Refreshed OAuth token expires in {}s", token.getExpiresIn());
        // Set expiration time related info in milliseconds
        token.setIssuedAt(System.currentTimeMillis());
        token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
        authString = token.toString();
        if (token.getExpiresIn() > 0) {
            expireAt = token.getIssuedAt() + token.getExpiresIn();
        }
    }
}
Also used : Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) ResourceOwnerGrant(org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerGrant)

Aggregations

Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)19 WebClient (org.apache.cxf.jaxrs.client.WebClient)17 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)12 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)9 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)9 Test (org.junit.Test)9 AMQPContext (com.swiftmq.amqp.AMQPContext)7 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)7 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)6 JwsJwtCompactConsumer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer)6 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)4 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 RefreshTokenGrant (org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrant)3 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)2 BearerAccessToken (com.nimbusds.oauth2.sdk.token.BearerAccessToken)2 TypelessAccessToken (com.nimbusds.oauth2.sdk.token.TypelessAccessToken)2 Connection (com.swiftmq.amqp.v100.client.Connection)2 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2