Search in sources :

Example 6 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project camel by apache.

the class Client method invoke.

public String invoke() throws Exception {
    // Service Qname as defined in the WSDL.
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
    // Port QName as defined in the WSDL.
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapOverHttpRouter");
    // Create a dynamic Service instance
    Service service = Service.create(serviceName);
    // Add a port to the Service
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    // Create a dispatch instance
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    // Use Dispatch as BindingProvider
    BindingProvider bp = dispatch;
    MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
    // Create SOAPMessage Request
    SOAPMessage request = factory.createMessage();
    // Request Body
    SOAPBody body = request.getSOAPBody();
    // Compose the soap:Body payload
    QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMe", "ns1");
    SOAPBodyElement payload = body.addBodyElement(payloadName);
    SOAPElement message = payload.addChildElement("requestType");
    message.addTextNode("Hello Camel!!");
    System.out.println("Send out the request: Hello Camel!!");
    // Invoke the endpoint synchronously
    // Invoke endpoint operation and read response
    SOAPMessage reply = dispatch.invoke(request);
    // process the reply
    body = reply.getSOAPBody();
    QName responseName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse");
    SOAPElement bodyElement = (SOAPElement) body.getChildElements(responseName).next();
    String responseMessageText = bodyElement.getTextContent();
    System.out.println("Get the response: " + responseMessageText);
    return responseMessageText;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 7 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project camel by apache.

the class CxfMtomRouterPayloadModeTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    if (MtomTestHelper.isAwtHeadless(logger, null)) {
        return;
    }
    Holder<byte[]> photo = new Holder<byte[]>(MtomTestHelper.REQ_PHOTO_DATA);
    Holder<Image> image = new Holder<Image>(getImage("/java.jpg"));
    Hello port = getPort();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) port).getBinding();
    binding.setMTOMEnabled(true);
    port.detail(photo, image);
    MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, photo.value);
    Assert.assertNotNull(image.value);
    if (image.value instanceof BufferedImage) {
        Assert.assertEquals(560, ((BufferedImage) image.value).getWidth());
        Assert.assertEquals(300, ((BufferedImage) image.value).getHeight());
    }
}
Also used : Hello(org.apache.camel.cxf.mtom_feature.Hello) Holder(javax.xml.ws.Holder) SOAPBinding(javax.xml.ws.soap.SOAPBinding) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 8 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project camel by apache.

the class CxfMtomPOJOProducerTest method setUp.

@Before
public void setUp() throws Exception {
    endpoint = Endpoint.publish("http://localhost:" + port + "/CxfMtomPOJOProducerTest/jaxws-mtom/hello", getImpl());
    SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
    binding.setMTOMEnabled(true);
}
Also used : SOAPBinding(javax.xml.ws.soap.SOAPBinding) Before(org.junit.Before)

Example 9 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project nhin-d by DirectProject.

the class DocumentRepositoryUtils method getDocumentRepositoryPortType.

/**
     * Construct a DocumentRepositoryPortType object using the provided
     * endpoint.
     * 
     * @param endpoint
     *            The XDR endpoint.
     * @param wsdlPath
     *            The path to the WSDL.
     * @return a DocumentRepositoryPortType object.
     * @throws Exception
     */
public static DocumentRepositoryPortType getDocumentRepositoryPortType(String endpoint, URL wsdlPath) throws Exception {
    QName qname = new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_Service");
    DocumentRepositoryService service = new DocumentRepositoryService(wsdlPath, qname);
    service.setHandlerResolver(new RepositoryHandlerResolver());
    DocumentRepositoryPortType port = service.getDocumentRepositoryPortSoap12(new MTOMFeature(true, 1));
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    return port;
}
Also used : DocumentRepositoryPortType(ihe.iti.xds_b._2007.DocumentRepositoryPortType) QName(javax.xml.namespace.QName) MTOMFeature(javax.xml.ws.soap.MTOMFeature) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DocumentRepositoryService(ihe.iti.xds_b._2007.DocumentRepositoryService)

Example 10 with SOAPBinding

use of javax.xml.ws.soap.SOAPBinding in project tomee by apache.

the class AttachmentTest method testAttachmentViaWsInterface.

//END SNIPPET: setup    
/**
     * Create a webservice client using wsdl url
     *
     * @throws Exception
     */
//START SNIPPET: webservice
public void testAttachmentViaWsInterface() throws Exception {
    Service service = Service.create(new URL("http://localhost:" + port + "/webservice-attachments/AttachmentImpl?wsdl"), new QName("http://superbiz.org/wsdl", "AttachmentWsService"));
    assertNotNull(service);
    AttachmentWs ws = service.getPort(AttachmentWs.class);
    // retrieve the SOAPBinding
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) ws).getBinding();
    binding.setMTOMEnabled(true);
    String request = "tsztelak@gmail.com";
    // Byte array
    String response = ws.stringFromBytes(request.getBytes());
    assertEquals(request, response);
    // Data Source
    DataSource source = new ByteArrayDataSource(request.getBytes(), "text/plain; charset=UTF-8");
    // not yet supported !
    //        response = ws.stringFromDataSource(source);
    //        assertEquals(request, response);
    // Data Handler
    response = ws.stringFromDataHandler(new DataHandler(source));
    assertEquals(request, response);
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) DataHandler(javax.activation.DataHandler) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) URL(java.net.URL) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Aggregations

SOAPBinding (javax.xml.ws.soap.SOAPBinding)10 QName (javax.xml.namespace.QName)4 BindingProvider (javax.xml.ws.BindingProvider)3 Before (org.junit.Before)3 DocumentRepositoryService (ihe.iti.xds_b._2007.DocumentRepositoryService)2 Image (java.awt.Image)2 URL (java.net.URL)2 Holder (javax.xml.ws.Holder)2 Service (javax.xml.ws.Service)2 MTOMFeature (javax.xml.ws.soap.MTOMFeature)2 Hello (org.apache.camel.cxf.mtom_feature.Hello)2 Test (org.junit.Test)2 DocumentRepositoryPortType (ihe.iti.xds_b._2007.DocumentRepositoryPortType)1 BufferedImage (java.awt.image.BufferedImage)1 Properties (java.util.Properties)1 Level (java.util.logging.Level)1 DataHandler (javax.activation.DataHandler)1 DataSource (javax.activation.DataSource)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1