use of javax.xml.ws.Holder in project cxf by apache.
the class HeaderClientServerTest method testReturnHeader.
@Test
public void testReturnHeader() throws Exception {
URL wsdl = getClass().getResource("/wsdl/soapheader.wsdl");
assertNotNull(wsdl);
SOAPHeaderService service = new SOAPHeaderService(wsdl, serviceName);
assertNotNull(service);
TestHeader proxy = service.getPort(portName, TestHeader.class);
try {
Holder<TestHeader5ResponseBody> out = new Holder<TestHeader5ResponseBody>();
Holder<TestHeader5> outHeader = new Holder<TestHeader5>();
TestHeader5 in = new TestHeader5();
String val = new String(TestHeader5.class.getSimpleName());
for (int idx = 0; idx < 2; idx++) {
val += idx;
in.setRequestType(val);
proxy.testHeader5(out, outHeader, in);
assertEquals(1000, out.value.getResponseType());
assertEquals(val, outHeader.value.getRequestType());
}
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
}
use of javax.xml.ws.Holder in project cxf by apache.
the class JAXRS20ClientServerBookTest method testPostCollectionGenericEntityGenericCallback.
@Test
public void testPostCollectionGenericEntityGenericCallback() throws Exception {
String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections3";
WebClient wc = WebClient.create(endpointAddress);
wc.accept("application/xml").type("application/xml");
GenericEntity<List<Book>> collectionEntity = createGenericEntity();
final Holder<Book> holder = new Holder<Book>();
InvocationCallback<Book> callback = new GenericInvocationCallback<Book>(holder) {
};
Future<Book> future = wc.post(collectionEntity, callback);
Book book = future.get();
assertEquals(200, wc.getResponse().getStatus());
assertSame(book, holder.value);
assertNotSame(collectionEntity.getEntity().get(0), book);
assertEquals(collectionEntity.getEntity().get(0).getName(), book.getName());
}
use of javax.xml.ws.Holder in project cxf by apache.
the class JAXRS20ClientServerBookTest method doTestGetBookAsync.
private void doTestGetBookAsync(String address, boolean asyncInvoker) throws InterruptedException, ExecutionException {
WebClient wc = createWebClient(address);
final Holder<Book> holder = new Holder<Book>();
InvocationCallback<Book> callback = createCallback(holder);
Future<Book> future = asyncInvoker ? wc.async().get(callback) : wc.get(callback);
Book book = future.get();
assertSame(book, holder.value);
assertEquals(124L, book.getId());
validateResponse(wc);
}
use of javax.xml.ws.Holder in project cxf by apache.
the class JAXRSAsyncClientTest method testGetBookAsync404Callback.
@Test
public void testGetBookAsync404Callback() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/bookheaders/404";
WebClient wc = createWebClient(address);
final Holder<Object> holder = new Holder<Object>();
InvocationCallback<Object> callback = createCallback(holder);
try {
wc.async().get(callback).get();
fail("Exception expected");
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof NotFoundException);
assertTrue(ex.getCause() == holder.value);
}
wc.close();
}
use of javax.xml.ws.Holder in project cxf by apache.
the class Client method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Please specify the WSDL file.");
System.exit(1);
}
URL wsdlURL;
File wsdlFile = new File(args[0]);
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
System.out.println(wsdlURL);
TestMtomService tms = new TestMtomService(wsdlURL, SERVICE_NAME);
TestMtomPortType port = (TestMtomPortType) tms.getPort(PORT_NAME, TestMtomPortType.class);
Binding binding = ((BindingProvider) port).getBinding();
((SOAPBinding) binding).setMTOMEnabled(true);
URL fileURL = Client.class.getResource("/me.bmp");
File aFile = new File(new URI(fileURL.toString()));
long fileSize = aFile.length();
System.out.println("Filesize of me.bmp image is: " + fileSize);
System.out.println("\nStarting MTOM Test using basic byte array:");
Holder<String> name = new Holder<String>("Sam");
Holder<byte[]> param = new Holder<byte[]>();
param.value = new byte[(int) fileSize];
InputStream in = fileURL.openStream();
int len = in.read(param.value);
while (len < fileSize) {
len += in.read(param.value, len, (int) (fileSize - len));
}
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testByteArray(name, param);
System.out.println("--Received byte[] back from server, returned size is " + param.value.length);
System.out.println("--Returned string value is " + name.value);
Image image = ImageIO.read(new ByteArrayInputStream(param.value));
System.out.println("--Loaded image from byte[] successfully, hashCode=" + image.hashCode());
System.out.println("Successfully ran MTOM/byte array demo");
System.out.println("\nStarting MTOM test with DataHandler:");
name.value = "Bob";
Holder<DataHandler> handler = new Holder<DataHandler>();
handler.value = new DataHandler(fileURL);
System.out.println("--Sending the me.bmp image to server");
System.out.println("--Sending a name value of " + name.value);
port.testDataHandler(name, handler);
InputStream mtomIn = handler.value.getInputStream();
fileSize = 0;
for (int i = mtomIn.read(); i != -1; i = mtomIn.read()) {
fileSize++;
}
System.out.println("--Received DataHandler back from server, " + "returned size is " + fileSize);
System.out.println("--Returned string value is " + name.value);
System.out.println("Successfully ran MTOM/DataHandler demo");
System.exit(0);
}
Aggregations