-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ddossot
committed
Sep 10, 2010
1 parent
c4ccf4a
commit 7c8fddc
Showing
13 changed files
with
251 additions
and
214 deletions.
There are no files selected for viewing
57 changes: 36 additions & 21 deletions
57
.../component-interceptor/src/main/java/com/clood/interceptor/BrokerNotReadyInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,67 @@ | ||
|
||
package com.clood.interceptor; | ||
|
||
import org.mule.api.MuleContext; | ||
import org.mule.api.MuleEvent; | ||
import org.mule.api.MuleException; | ||
import org.mule.api.MuleMessage; | ||
import org.mule.api.context.MuleContextAware; | ||
import org.mule.api.context.notification.MuleContextNotificationListener; | ||
import org.mule.api.context.notification.ServerNotification; | ||
import org.mule.api.interceptor.Interceptor; | ||
import org.mule.api.interceptor.Invocation; | ||
import org.mule.api.processor.MessageProcessor; | ||
import org.mule.context.notification.MuleContextNotification; | ||
import org.mule.context.notification.NotificationException; | ||
|
||
/** | ||
* @author David Dossot (david@dossot.net) | ||
*/ | ||
// <start id="BrokerNotReadyInterceptor"/> | ||
public final class BrokerNotReadyInterceptor implements MuleContextAware, | ||
MuleContextNotificationListener, Interceptor { | ||
|
||
public final class BrokerNotReadyInterceptor | ||
implements MuleContextAware, MuleContextNotificationListener<MuleContextNotification>, Interceptor | ||
{ | ||
private volatile boolean brokerReady = false; | ||
private MessageProcessor next; | ||
|
||
public void setMuleContext(final MuleContext context) { | ||
try { | ||
public void setMuleContext(final MuleContext context) | ||
{ | ||
try | ||
{ | ||
context.registerListener(this); | ||
} catch (final NotificationException ne) { | ||
} | ||
catch (final NotificationException ne) | ||
{ | ||
throw new RuntimeException(ne); | ||
} | ||
} | ||
|
||
public void onNotification(final ServerNotification notification) { | ||
final int action = notification.getAction(); | ||
|
||
if (action == MuleContextNotification.CONTEXT_STARTED) { | ||
public void setListener(MessageProcessor listener) | ||
{ | ||
next = listener; | ||
} | ||
|
||
public void onNotification(final MuleContextNotification notification) | ||
{ | ||
final int action = notification.getAction(); | ||
|
||
if (action == MuleContextNotification.CONTEXT_STARTED) | ||
{ | ||
brokerReady = true; | ||
} | ||
else if (action == MuleContextNotification.CONTEXT_STOPPED) { | ||
else if (action == MuleContextNotification.CONTEXT_STOPPED) | ||
{ | ||
brokerReady = false; | ||
} | ||
} | ||
|
||
public MuleMessage intercept(final Invocation invocation) | ||
throws MuleException { | ||
|
||
if (!brokerReady) { | ||
throw new IllegalStateException("Invocation of service " + invocation.getService().getName() + " impossible at this time!"); | ||
public MuleEvent process(MuleEvent event) throws MuleException | ||
{ | ||
if (!brokerReady) | ||
{ | ||
throw new IllegalStateException("Invocation of service " + event.getFlowConstruct().getName() | ||
+ " impossible at this time!"); | ||
} | ||
|
||
return invocation.invoke(); | ||
return next.process(event); | ||
} | ||
|
||
} | ||
// <end id="BrokerNotReadyInterceptor"/> | ||
// <end id="BrokerNotReadyInterceptor"/> |
36 changes: 23 additions & 13 deletions
36
...13/component-interceptor/src/main/java/com/clood/interceptor/PayloadCacheInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 11 additions & 9 deletions
20
chapter13/mule-client/src/test/java/com/muleinaction/muleclient/RawHttpMuleClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
|
||
package com.muleinaction.muleclient; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.mule.MuleServer; | ||
import org.mule.api.MuleMessage; | ||
import org.mule.module.client.MuleClient; | ||
|
||
/** | ||
* @author David Dossot (david@dossot.net) | ||
*/ | ||
public class RawHttpMuleClientTest { | ||
public class RawHttpMuleClientTest | ||
{ | ||
// TODO reactivate when cookie issues will be fixed in Mule 3 | ||
@Ignore | ||
@Test | ||
public void tapHttpTransport() throws Exception { | ||
public void tapHttpTransport() throws Exception | ||
{ | ||
// <start id="MuleClient-RawHttp-Transport"/> | ||
final MuleClient muleClient = new MuleClient(true); | ||
|
||
final MuleMessage response = muleClient | ||
.send( | ||
"http://www.google.com/finance/historical?q=NASDAQ:GOOG&histperiod=weekly&output=csv", | ||
null, null); | ||
final MuleMessage response = muleClient.send( | ||
"http://www.google.com/finance/historical?q=NASDAQ:GOOG&histperiod=weekly&output=csv", null, null); | ||
|
||
final String payload = response.getPayloadAsString(); | ||
|
||
muleClient.dispose(); | ||
// <end id="MuleClient-RawHttp-Transport"/> | ||
|
||
assertNotNull(response); | ||
assertNotNull(payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.