use of org.apache.cxf.hello_world_jms.HelloWorldService in project cxf by apache.
the class JMSClientServerTest method testContextPropagation.
@Test
public void testContextPropagation() throws Exception {
final String testReturnPropertyName = "Test_Prop";
final String testIgnoredPropertyName = "Test_Prop_No_Return";
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
Map<String, Object> requestContext = ((BindingProvider) greeter).getRequestContext();
JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
requestHeader.setJMSCorrelationID("JMS_SAMPLE_CORRELATION_ID");
requestHeader.setJMSExpiration(3600000L);
requestHeader.putProperty(testReturnPropertyName, "mustReturn");
requestHeader.putProperty(testIgnoredPropertyName, "mustNotReturn");
requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
String greeting = greeter.greetMe("Milestone-");
assertNotNull("no response received from service", greeting);
assertEquals("Hello Milestone-", greeting);
Map<String, Object> responseContext = ((BindingProvider) greeter).getResponseContext();
JMSMessageHeadersType responseHdr = (JMSMessageHeadersType) responseContext.get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
if (responseHdr == null) {
fail("response Header should not be null");
}
assertTrue("CORRELATION ID should match :", "JMS_SAMPLE_CORRELATION_ID".equals(responseHdr.getJMSCorrelationID()));
assertTrue("response Headers must conain the app property set in request context.", responseHdr.getPropertyKeys().size() > 0);
boolean found = responseHdr.getPropertyKeys().contains(testReturnPropertyName);
assertTrue("response Headers must match the app property set in request context.", found);
((Closeable) greeter).close();
}
use of org.apache.cxf.hello_world_jms.HelloWorldService in project cxf by apache.
the class JMSClientServerTest method testBasicConnection.
@Test
public void testBasicConnection() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
String response1 = new String("Hello Milestone-");
String response2 = new String("Bonjour");
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
for (int idx = 0; idx < 5; idx++) {
String greeting = greeter.greetMe("Milestone-" + idx);
assertNotNull("no response received from service", greeting);
String exResponse = response1 + idx;
assertEquals(exResponse, greeting);
String reply = greeter.sayHi();
assertNotNull("no response received from service", reply);
assertEquals(response2, reply);
try {
greeter.testRpcLitFault("BadRecordLitFault");
fail("Should have thrown BadRecoedLitFault");
} catch (BadRecordLitFault ex) {
assertNotNull(ex.getFaultInfo());
}
try {
greeter.testRpcLitFault("NoSuchCodeLitFault");
fail("Should have thrown NoSuchCodeLitFault exception");
} catch (NoSuchCodeLitFault nslf) {
assertNotNull(nslf.getFaultInfo());
assertNotNull(nslf.getFaultInfo().getCode());
}
}
((java.io.Closeable) greeter).close();
}
use of org.apache.cxf.hello_world_jms.HelloWorldService in project cxf by apache.
the class JMSClientServerTest method testAsyncCall.
@Ignore
@Test
public void testAsyncCall() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
final Thread thread = Thread.currentThread();
class TestAsyncHandler implements AsyncHandler<String> {
String expected;
TestAsyncHandler(String x) {
expected = x;
}
public String getExpected() {
return expected;
}
public void handleResponse(Response<String> response) {
try {
Thread thread2 = Thread.currentThread();
assertNotSame(thread, thread2);
assertEquals("Hello " + expected, response.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}
TestAsyncHandler h1 = new TestAsyncHandler("Homer");
TestAsyncHandler h2 = new TestAsyncHandler("Maggie");
TestAsyncHandler h3 = new TestAsyncHandler("Bart");
TestAsyncHandler h4 = new TestAsyncHandler("Lisa");
TestAsyncHandler h5 = new TestAsyncHandler("Marge");
Future<?> f1 = greeter.greetMeAsync("Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
f1.get();
f1 = greeter.greetMeAsync("PauseForTwoSecs Santa's Little Helper", new TestAsyncHandler("Santa's Little Helper"));
long start = System.currentTimeMillis();
f1 = greeter.greetMeAsync("PauseForTwoSecs " + h1.getExpected(), h1);
Future<?> f2 = greeter.greetMeAsync("PauseForTwoSecs " + h2.getExpected(), h2);
Future<?> f3 = greeter.greetMeAsync("PauseForTwoSecs " + h3.getExpected(), h3);
Future<?> f4 = greeter.greetMeAsync("PauseForTwoSecs " + h4.getExpected(), h4);
Future<?> f5 = greeter.greetMeAsync("PauseForTwoSecs " + h5.getExpected(), h5);
long mid = System.currentTimeMillis();
assertEquals("Hello " + h1.getExpected(), f1.get());
assertEquals("Hello " + h2.getExpected(), f2.get());
assertEquals("Hello " + h3.getExpected(), f3.get());
assertEquals("Hello " + h4.getExpected(), f4.get());
assertEquals("Hello " + h5.getExpected(), f5.get());
long end = System.currentTimeMillis();
assertTrue("Time too long: " + (mid - start), (mid - start) < 1000);
assertTrue((end - mid) > 1000);
f1 = null;
f2 = null;
f3 = null;
f4 = null;
f5 = null;
((java.io.Closeable) greeter).close();
greeter = null;
service = null;
System.gc();
}
use of org.apache.cxf.hello_world_jms.HelloWorldService in project cxf by apache.
the class JMSWSSecurityTest method testUnsignedSAML2AudienceRestrictionTokenBadURI.
@Test
public void testUnsignedSAML2AudienceRestrictionTokenBadURI() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
callbackHandler.setSignAssertion(true);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
ConditionsBean conditions = new ConditionsBean();
conditions.setTokenPeriodMinutes(5);
List<String> audiences = new ArrayList<>();
audiences.add("jms:jndi:dynamicQueues/test.jmstransport.text.bad");
AudienceRestrictionBean audienceRestrictionBean = new AudienceRestrictionBean();
audienceRestrictionBean.setAudienceURIs(audiences);
conditions.setAudienceRestrictions(Collections.singletonList(audienceRestrictionBean));
callbackHandler.setConditions(conditions);
Map<String, Object> outProperties = new HashMap<>();
outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties);
Client client = ClientProxy.getClient(greeter);
client.getOutInterceptors().add(outInterceptor);
try {
greeter.sayHi();
fail("Failure expected on a bad audience restriction");
} catch (SOAPFaultException ex) {
// expected
}
((java.io.Closeable) greeter).close();
}
use of org.apache.cxf.hello_world_jms.HelloWorldService in project cxf by apache.
the class JMSWSSecurityTest method testUnsignedSAML2Token.
@Test
public void testUnsignedSAML2Token() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService");
QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort");
URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
HelloWorldService service = new HelloWorldService(wsdl, serviceName);
String response = new String("Bonjour");
HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class);
SamlCallbackHandler callbackHandler = new SamlCallbackHandler();
callbackHandler.setSignAssertion(true);
callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER);
Map<String, Object> outProperties = new HashMap<>();
outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties);
Client client = ClientProxy.getClient(greeter);
client.getOutInterceptors().add(outInterceptor);
String reply = greeter.sayHi();
assertNotNull("no response received from service", reply);
assertEquals(response, reply);
((java.io.Closeable) greeter).close();
}
Aggregations