Java 类javax.xml.soap.SOAPConnection 实例源码

项目:onvifjava    文件:SoapClient.java   
@SuppressWarnings("unchecked")
@Override
// blocking
public <T> T processRequest(Object request, Class<T> responseClass, String soapUri, boolean needsAuthentification)
        throws Exception {
    SOAPConnection soapConnection = null;
    try {
        soapConnection = soapConnectionFactory.createConnection();
        SOAPMessage soapMessage = processSoapMessage(request, needsAuthentification);
        SOAPMessage soapResponse = soapConnection.call(soapMessage, soapUri);
        // get new each time? - no
        Unmarshaller unmarshaller = getUnmarshaller(responseClass);
        return (T) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
    } finally {
        if (soapConnection != null) {
            soapConnection.close();
        }
    }

}
项目:jaffa-framework    文件:WebServiceInvoker.java   
/**
 *  Marshals the inout arguments into a SOAPMessage
 * and invokes the WebService.
 * @param arguments the arguments for the WebService.
 * @return the reply from the WebService.
 * @throws SOAPException if any SOAP error occurs.
 * @throws SOAPFaultException if any SOAPFault occurs.
 * @throws JAXBException if any XML (un)marshalling error occurs.
 */
public Object invoke(Object... arguments) throws SOAPException, SOAPFaultException, JAXBException {
    SOAPConnection connection = null;

    try {
        // Create a connection
        connection = SOAPConnectionFactory.newInstance().createConnection();

        // Create the SOAPMessage
        SOAPMessage message = createSOAPMessage(arguments);

        // Invoke the WebService
        SOAPMessage response = invoke(connection, message);

        // Unmarshal the response
        return unmarshalResponse(response);
    } finally {
        // Always close the connection
        if (connection != null) {
            connection.close();
        }
    }
}
项目:sam-elle    文件:EditTerminalClient.java   
public void callWebService(String iccid, String businessValue) throws SOAPException, IOException, XWSSecurityException, Exception {
    SOAPMessage request = createTerminalRequest(iccid, businessValue);
    request = secureMessage(request);

    // TODO
    logger.info("Edit Terminal Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Edit Terminal Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
    }
}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
public String callWebService(String msisdn) throws SOAPException, IOException, XWSSecurityException, GetTermalIccidException {
    SOAPMessage request = createTerminalRequest(msisdn);
    request = secureMessage(request);

    // TODO
    logger.info("Get Terminals by msisdn Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Get Terminals by msisdn Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        return writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
        throw new GetTermalIccidException(fault.getFaultCode() + "," + fault.getFaultString());
    }
}
项目:atf-toolbox-java    文件:WebServiceAutomationManager.java   
/**
 * sendSoapMessage Connect to the service, will log the request and response
 *
 * @param webServiceKey
 *            the key to locate which web service to use
 * @param request
 *            - SoapMessage to send to the service
 * @return - SoapMessage response
 * @throws MalformedURLException
 *             - if there was an error creating the endpoint Connection
 * @throws SOAPException
 *             - if there was an error creating the SOAP Connection
 */
public SOAPMessage sendSoapMessage(String webServiceKey, SOAPMessage request) throws MalformedURLException, SOAPException {
    SOAPMessage response = null;

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    try {

        WebService service = getWebService(webServiceKey);

        logSOAPMessage(request, "SOAP Request");

        URL endpoint = new URL(service.getEndPoint());

        response = connection.call(request, endpoint);

        logSOAPMessage(response, "SOAP Response");
    } catch (Exception e) {
        throw e;
    } finally {
        connection.close();
    }

    return response;
}
项目:bisis-v4    文件:SOAPUtilClient.java   
public SOAPMessage sendReceive(SOAPMessage msg, String URLAddress)
    throws SOAPException, MalformedURLException{


    setProxyFromINI(true);
    URL endPoint = new URL(URLAddress);
    SOAPMessage reply=null; 
    // TODO: set proxy ako treba
    SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();

    SOAPConnection con = factory.createConnection();
    if(con==null){
        if(MessagingEnvironment.DEBUG==1)
            System.out.println("SOAPConnection failure!");
    }else{

        reply = con.call(msg, endPoint);
        con.close();
        if(MessagingEnvironment.DEBUG==1)
            System.out.println("\nSending to: "+URLAddress+" success");
    }
    setProxyFromINI(false);
    return reply;
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
public Collection<ValidationErrorMessage> registerPatients(String username, String passwordHash, String url, Collection<Subject> subjects)
        throws Exception {
    log.info("Register patients initialized by: " + username + " on: " + url);
    Collection<ValidationErrorMessage> ret = new ArrayList<>();
    for (Subject subject : subjects) {
        SOAPMessage soapMessage = requestFactory.createCreateSubject(username, passwordHash, subject);
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();
        SOAPMessage soapResponse = soapConnection.call(soapMessage, url + "/ws/studySubject/v1");
        String error = parseRegisterSubjectsResponse(soapResponse);
        if (error != null) {
            String detailedErrorMessage = "Registering subject " + subject.getSsid() + " against instance " + url + " failed, OC error: " + error;
            log.error(detailedErrorMessage);
            ret.add(new ValidationErrorMessage(detailedErrorMessage));
        }
    }
    log.info("Registered subjects against instance " + url + " completed, number of subjects:" +
                subjects.size());
    return ret;

}
项目:sam-elle    文件:EditTerminalClient.java   
public void callWebService(String iccid, String businessValue) throws SOAPException, IOException, XWSSecurityException, Exception {
    SOAPMessage request = createTerminalRequest(iccid, businessValue);
    request = secureMessage(request);

    // TODO
    logger.info("Edit Terminal Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Edit Terminal Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
    }
}
项目:sam-elle    文件:GetTerminalsByMsisdnClient.java   
public String callWebService(String msisdn) throws SOAPException, IOException, XWSSecurityException, GetTermalIccidException {
    SOAPMessage request = createTerminalRequest(msisdn);
    request = secureMessage(request);

    // TODO
    logger.info("Get Terminals by msisdn Request: ");
    request.writeTo(System.out);
    System.out.println("");

    SOAPConnection connection = connectionFactory.createConnection();
    SOAPMessage response = connection.call(request, url);
    // TODO
    logger.info("Get Terminals by msisdn Response: ");
    response.writeTo(System.out);
    System.out.println("");

    if (!response.getSOAPBody().hasFault()) {
        return writeTerminalResponse(response);
    } else {
        SOAPFault fault = response.getSOAPBody().getFault();
        logger.error("Received SOAP Fault");
        logger.error("SOAP Fault Code :" + fault.getFaultCode());
        logger.error("SOAP Fault String :" + fault.getFaultString());
        throw new GetTermalIccidException(fault.getFaultCode() + "," + fault.getFaultString());
    }
}
项目:jbossws-cxf    文件:JBWS3084CxfTestCase.java   
@Test
@RunAsClient
public void testSoapConnectionGet() throws Exception
{
   final String serviceURL = baseURL + "/greetMe";
   SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();

   SOAPConnection con = conFac.createConnection();
   URL endpoint = new URL(serviceURL);
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPMessage msg = msgFactory.createMessage();
   msg.getSOAPBody().addBodyElement(new QName("http://www.jboss.org/jbossws/saaj", "greetMe"));
   SOAPMessage response = con.call(msg, endpoint);
   QName greetMeResp = new QName("http://www.jboss.org/jbossws/saaj", "greetMeResponse");

   Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(greetMeResp);
   SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
   assertNotNull(soapElement);

   assertEquals(1, response.countAttachments());
}
项目:jbossws-cxf    文件:JBWS1815TestCase.java   
@Test
@RunAsClient
public void testProviderMessage() throws Exception
{
   SOAPMessage reqMsg = getRequestMessage();
   URL epURL = new URL(baseURL + "/jaxws-jbws1815/ProviderImpl");
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
   Detail detail = resEnv.getBody().getFault().getDetail();
   assertNotNull(detail);
   SOAPElement exception = (SOAPElement)detail.getDetailEntries().next();
   assertNotNull(exception);
   assertEquals("MyWSException", exception.getElementQName().getLocalPart());
   assertEquals("http://www.my-company.it/ws/my-test", exception.getElementQName().getNamespaceURI());
   SOAPElement message = (SOAPElement)exception.getChildElements().next();
   assertNotNull(message);
   assertEquals("message", message.getNodeName());
   assertEquals("This is a faked error", message.getValue());
}
项目:jbossws-cxf    文件:JBWS3945TestCase.java   
@Test
@RunAsClient
public void testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ() throws Exception
{
   try
   {
      //<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:throwSoapFaultException xmlns:ns2="http://server.exception.samples.jaxws.ws.test.jboss.org/"/></soap:Body></soap:Envelope>

      SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();

      SOAPConnection con = conFac.createConnection();
      MessageFactory msgFactory = MessageFactory.newInstance();
      SOAPMessage msg = msgFactory.createMessage();
      msg.getSOAPBody().addBodyElement(new QName(targetNS, "throwSoapFaultException"));
      SOAPMessage response = con.call(msg, new URL(targetEndpoint + "Servlet"));
      Element el = (Element)response.getSOAPBody().getChildElements().next();
      assertEquals("Fault", el.getLocalName());
   }
   catch (Exception e)
   {
      fail(e);
   }
}
项目:jbossws-cxf    文件:ProviderMessageTestCase.java   
@Test
@RunAsClient
public void testProviderMessage() throws Exception
{
   SOAPMessage reqMsg = getRequestMessage();
   SOAPEnvelope reqEnv = reqMsg.getSOAPPart().getEnvelope();

   URL epURL = baseURL;
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();

   SOAPHeader soapHeader = resEnv.getHeader();
   if (soapHeader != null)
      soapHeader.detachNode();

   assertEquals(reqEnv, resEnv);
}
项目:jbossws-cxf    文件:ProviderMessageTestCase.java   
@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception
{
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));

   URL epURL = baseURL;
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   if (resMsg != null)
   {
      SOAPPart soapPart = resMsg.getSOAPPart();
      //verify there's either nothing in the reply or at least the response body is empty
      if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null)
      {
         SOAPBody soapBody = soapPart.getEnvelope().getBody();
         assertFalse(soapBody.getChildElements().hasNext());
      }
   }
}
项目:jbossws-cxf    文件:WebMethodTestCase.java   
@Test
@RunAsClient
public void testLegalMessageAccess() throws Exception
{
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();

   String reqEnv =
      "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
      " <env:Header/>" +
      " <env:Body>" +
      "  <ns1:echoString xmlns:ns1='" + targetNS + "'>" +
      "   <arg0>Hello</arg0>" +
      "  </ns1:echoString>" +
      " </env:Body>" +
      "</env:Envelope>";
   SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));

   URL epURL = new URL(baseURL + "/TestService");
   SOAPMessage resMsg = con.call(reqMsg, epURL);

   QName qname = new QName(targetNS, "echoStringResponse");
   SOAPElement soapElement = (SOAPElement)resMsg.getSOAPBody().getChildElements(qname).next();
   soapElement = (SOAPElement)soapElement.getChildElements(new QName("return")).next();
   assertEquals("Hello", soapElement.getValue());
}
项目:jbossws-cxf    文件:WebMethodTestCase.java   
@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception
{
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();

   String reqEnv =
      "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
      " <env:Header/>" +
      " <env:Body>" +
      "  <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" +
      "   <String_1>Hello</String_1>" +
      "  </ns1:noWebMethod>" +
      " </env:Body>" +
      "</env:Envelope>";
   SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));

   URL epURL = new URL(baseURL + "/TestService");
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   SOAPFault soapFault = resMsg.getSOAPBody().getFault();
   assertNotNull("Expected SOAPFault", soapFault);

   String faultString = soapFault.getFaultString();
   assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
项目:jbossws-cxf    文件:MultipartContentTypeTestCase.java   
@Test
@RunAsClient
public void testSendMultipartSoapMessage() throws Exception {
   final MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
   final SOAPMessage msg = msgFactory.createMessage();
   final SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(
      new QName("urn:ledegen:soap-attachment:1.0", "echoImage"));
   bodyElement.addTextNode("cid:" + IN_IMG_NAME);

   final AttachmentPart ap = msg.createAttachmentPart();
   ap.setDataHandler(getResource("saaj/jbws3857/" + IN_IMG_NAME));
   ap.setContentId(IN_IMG_NAME);
   msg.addAttachmentPart(ap);

   final SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
   final SOAPConnection connection = conFactory.createConnection();
   final SOAPMessage response = connection.call(msg, new URL("http://" + baseURL.getHost()+ ":" + baseURL.getPort() + "/" + PROJECT_NAME + "/testServlet"));

   final String contentTypeWeHaveSent = getBodyElementTextValue(response);
   assertContentTypeStarts("multipart/related", contentTypeWeHaveSent);
}
项目:eHMP    文件:MviSoapConnection.java   
public PRPAIN201310UV02 send1309Message(PRPAIN201309UV02 message) {
    LOG.debug("Starting send1309Message");
    SOAPMessage request = makeSOAPMessage(message);
    LOG.debug("SOAP body built");
    try {
        LOG.debug("Making connection to MVI");
        SOAPConnection connection = factory.createConnection(); 

           LOG.debug("Invoking MVI call to " + getMviUri());
        SOAPMessage response = connection.call(request, getMviUri());
        NodeList children = response.getSOAPBody().getChildNodes();
        Node responseBody = null;
        for(int i = 0; i < children.getLength(); i++) {
            Node currentNode = children.item(i);
            if("PRPA_IN201310UV02".equals(currentNode.getLocalName())) {
                responseBody = currentNode;
                break;
            }
        }
        return makePOJOFromBody(responseBody, PRPAIN201310UV02.class);
    } catch (UnsupportedOperationException | SOAPException e) {
        LOG.error("Unable to successfully communicate with MVI",e);
    }

    return null;
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testSendReceiveMessageWithEmptyNSPrefix() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage request = mf.createMessage();

    SOAPPart sPart = request.getSOAPPart();
    SOAPEnvelope env = sPart.getEnvelope();
    SOAPBody body = env.getBody();

    //Namespace prefix is empty
    body.addBodyElement(new QName("http://fakeNamespace2.org","echo"))
                                .addTextNode("This is some text");

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    assertFalse(response.getAttachments().hasNext());
    assertEquals(0, response.countAttachments());

    String requestStr = printSOAPMessage(request);
    String responseStr = printSOAPMessage(response);
    assertTrue(responseStr.indexOf("echo") > -1);
    sCon.close();
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testSendReceiveSimpleSOAPMessage() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage request = mf.createMessage();

    createSimpleSOAPPart(request);

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    assertFalse(response.getAttachments().hasNext());
    assertEquals(0, response.countAttachments());

    String requestStr = printSOAPMessage(request);
    String responseStr = printSOAPMessage(response);
    assertTrue(responseStr.indexOf("echo") != -1);
    sCon.close();
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testSendReceive_ISO88591_EncodedSOAPMessage() throws Exception {
    MimeHeaders mimeHeaders = new MimeHeaders();
    mimeHeaders.addHeader("Content-Type", "text/xml; charset=iso-8859-1");

    InputStream inputStream = TestUtils.getTestFile("soap-part-iso-8859-1.xml");
    SOAPMessage requestMessage = MessageFactory.newInstance().createMessage(mimeHeaders, inputStream);


    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(requestMessage, getAddress());
    assertFalse(response.getAttachments().hasNext());
    assertEquals(0, response.countAttachments());

    printSOAPMessage(requestMessage);
    String responseStr = printSOAPMessage(response);
    assertEquals("This is some text.Here are some special chars : \u00F6\u00C6\u00DA\u00AE\u00A4",
                 response.getSOAPBody().getElementsByTagName("something").item(0).getTextContent());
    assertTrue(responseStr.indexOf("echo") != -1);
    sCon.close();
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testCallWithSOAPAction() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage request = mf.createMessage();

    String soapAction = "urn:test:echo";

    request.getSOAPPart().getEnvelope().getBody().addBodyElement(new QName("urn:test", "echo"));
    request.getMimeHeaders().addHeader("SOAPAction", soapAction);

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    sCon.call(request, getAddress());
    sCon.close();

    assertEquals(soapAction, lastSoapAction);
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testCallMTOM() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();

    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", TestUtils.MTOM_TEST_MESSAGE_CONTENT_TYPE);
    InputStream in = TestUtils.getTestFile(TestUtils.MTOM_TEST_MESSAGE_FILE);
    SOAPMessage request = mf.createMessage(headers, in);
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();

    // Remove the headers since they have mustunderstand=1 
    envelope.getHeader().removeContents();
    // Change the name of the body content so that the request is routed to the echo service
    ((SOAPElement)envelope.getBody().getChildElements().next()).setElementQName(new QName("echo"));

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    sCon.close();

    SOAPPart soapPart = response.getSOAPPart();
    SOAPElement textElement =
            (SOAPElement)soapPart.getEnvelope().getElementsByTagName("text").item(0);
    AttachmentPart ap = response.getAttachment((SOAPElement)textElement.getChildNodes().item(0));
    assertNotNull(ap);
}
项目:bandwidth-on-demand    文件:KisOnlineClient.java   
@Override
public List<Organization> findOrganizations() {
  try {
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    try {
      SOAPMessage request = createGetKlantenRequest(username, password);
      SOAPMessage response = soapConnection.call(request, createEndPointWithTimeout(endPoint, timeout));

      return parseKlanten(response.getSOAPBody());
    } finally {
      soapConnection.close();
    }
  } catch (MalformedURLException | UnsupportedOperationException | SOAPException | XPathExpressionException e) {
    throw new RuntimeException(e);
  }
}
项目:parabuild-ci    文件:TestMsg.java   
public void testEnvelope(String[] args) throws Exception {
    String xmlString =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
        "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
        "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
        " <soapenv:Header>\n" +
        "  <shw:Hello xmlns:shw=\"http://localhost:8080/axis/services/MessageService\">\n" +
        "    <shw:Myname>Tony</shw:Myname>\n" +
        "  </shw:Hello>\n" +
        " </soapenv:Header>\n" +
        " <soapenv:Body>\n" +
        "  <shw:process xmlns:shw=\"http://message.samples\">\n" +
        "    <shw:City>GENT</shw:City>\n" +
        "  </shw:process>\n" +
        " </soapenv:Body>\n" +
        "</soapenv:Envelope>";

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage smsg =
            mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
    SOAPPart sp = smsg.getSOAPPart();
    SOAPEnvelope se = (SOAPEnvelope)sp.getEnvelope();

    SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = conn.call(smsg, "http://localhost:8080/axis/services/MessageService2");
}
项目:parabuild-ci    文件:UddiPing.java   
public static void searchUDDI(String name, String url) throws Exception {
    // Create the connection and the message factory.
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = scf.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance();

    // Create a message
    SOAPMessage msg = msgFactory.createMessage();

    // Create an envelope in the message
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

    // Get hold of the the body
    SOAPBody body = envelope.getBody();

    javax.xml.soap.SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("find_business", "",
            "urn:uddi-org:api"));

    bodyElement.addAttribute(envelope.createName("generic"), "1.0")
            .addAttribute(envelope.createName("maxRows"), "100")
            .addChildElement("name")
            .addTextNode(name);

    URLEndpoint endpoint = new URLEndpoint(url);
    msg.saveChanges();

    SOAPMessage reply = connection.call(msg, endpoint);
    //System.out.println("Received reply from: " + endpoint);
    //reply.writeTo(System.out);
    connection.close();
}
项目:parabuild-ci    文件:DelayedStockQuote.java   
public String getStockQuote(String tickerSymbol) throws Exception {
    SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection con = scFactory.createConnection();

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();

    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();

    header.detachNode();

    Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
    SOAPBodyElement gltp = body.addBodyElement(bodyName);

    Name name = envelope.createName("symbol");
    SOAPElement symbol = gltp.addChildElement(name);
    symbol.addTextNode(tickerSymbol);

    URLEndpoint endpoint = new URLEndpoint("http://64.124.140.30/soap");
    SOAPMessage response = con.call(message, endpoint);
    con.close();

    SOAPPart sp = response.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();
    Iterator it = sb.getChildElements();
    while (it.hasNext()) {
        SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();
        Iterator it2 = bodyElement.getChildElements();
        while (it2.hasNext()) {
            SOAPElement element2 = (SOAPElement) it2.next();
            return element2.getValue();
        }
    }
    return null;
}
项目:parabuild-ci    文件:EchoAttachment.java   
/**
 * This method sends a file as an attachment then 
 *  receives it as a return.  The returned file is
 *  compared to the source. Uses SAAJ API.
 *  @param The filename that is the source to send.
 *  @return True if sent and compared.
 */
public boolean echoUsingSAAJ(String filename) throws Exception {
    String endPointURLString =  "http://localhost:" +opts.getPort() + "/axis/services/urn:EchoAttachmentsService";

    SOAPConnectionFactory soapConnectionFactory =
            javax.xml.soap.SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection =
            soapConnectionFactory.createConnection();

    MessageFactory messageFactory =
            MessageFactory.newInstance();
    SOAPMessage soapMessage =
            messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope requestEnvelope =
            soapPart.getEnvelope();
    SOAPBody body = requestEnvelope.getBody();
    SOAPBodyElement operation = body.addBodyElement
            (requestEnvelope.createName("echo"));

    Vector dataHandlersToAdd = new Vector();
    dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
            File(filename))));

    if (dataHandlersToAdd != null) {
        ListIterator dataHandlerIterator =
                dataHandlersToAdd.listIterator();

        while (dataHandlerIterator.hasNext()) {
            DataHandler dataHandler = (DataHandler)
                    dataHandlerIterator.next();
            javax.xml.soap.SOAPElement element =
                    operation.addChildElement(requestEnvelope.createName("source"));
            javax.xml.soap.AttachmentPart attachment =
                    soapMessage.createAttachmentPart(dataHandler);
            soapMessage.addAttachmentPart(attachment);
            element.addAttribute(requestEnvelope.createName
                                 ("href"), "cid:" + attachment.getContentId());
        }
    }
    javax.xml.soap.SOAPMessage returnedSOAPMessage =
            soapConnection.call(soapMessage, endPointURLString);
    Iterator iterator = returnedSOAPMessage.getAttachments();
    if (!iterator.hasNext()) {
        //The wrong type of object that what was expected.
        System.out.println("Received problem response from server");
        throw new AxisFault("", "Received problem response from server", null, null);

    }
    //Still here, so far so good.
    //Now lets brute force compare the source attachment
    // to the one we received.
    DataHandler rdh = (DataHandler) ((AttachmentPart)iterator.next()).getDataHandler();

    //From here we'll just treat the data resource as file.
    String receivedfileName = rdh.getName();//Get the filename. 

    if (receivedfileName == null) {
        System.err.println("Could not get the file name.");
        throw new AxisFault("", "Could not get the file name.", null, null);
    }


    System.out.println("Going to compare the files..");
    boolean retv = compareFiles(filename, receivedfileName);

    java.io.File receivedFile = new java.io.File(receivedfileName);

    receivedFile.delete();

    return retv;
}
项目:jaffa-framework    文件:WebServiceInvoker.java   
/**
 * Invokes the WebService, passing it the input message.
 * @param connection the connection to use for invoking the WebService.
 * @param message the input to the WebService.
 * @return the response from the WebService.
 * @throws SOAPException if any SOAP error occurs.
 */
protected SOAPMessage invoke(SOAPConnection connection, SOAPMessage message) throws SOAPException {
    StringBuilder url = new StringBuilder(getTargetHostPlusApplication());
    if (url.charAt(url.length() - 1) != '/') {
        url.append('/');
    }
    url.append(((WebService) getWebServiceClass().getAnnotation(WebService.class)).serviceName());
    if (log.isDebugEnabled()) {
        log.debug("Invoking WebService at '" + url + "', passing " + message);
    }
    return connection.call(message, url.toString());
}
项目:OSCAR-ConCert    文件:FrmStudyXMLClientSend.java   
private void sendJaxmMsg (String aMsg, String u)  {
    try {
        System.setProperty("javax.net.ssl.trustStore", u);

        SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = scf.createConnection();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();

        SOAPPart sp = message.getSOAPPart();
        SOAPEnvelope envelope = sp.getEnvelope();

        SOAPHeader header = envelope.getHeader();
        SOAPBody body = envelope.getBody();

        SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("OSCAR", "DT", "http://www.oscarhome.org/"));
        headerElement.addTextNode("header");

        SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("Service"));
        bodyElement.addTextNode("compete");

        AttachmentPart ap1 = message.createAttachmentPart();
        ap1.setContent(aMsg, "text/plain");

        message.addAttachmentPart(ap1);

        URLEndpoint endPoint = new URLEndpoint (URLService);  //"https://67.69.12.115:8443/OscarComm/DummyReceiver");
        SOAPMessage reply = connection.call(message, endPoint);

        connection.close();
    } catch (Exception e)   {
        MiscUtils.getLogger().error("Error", e);
    }
}
项目:soap-wrapper-lambda    文件:WrapperApiEndpointIntegrationTest.java   
private SOAPMessage executeApiCallWith(SOAPMessage soapMessage) throws SOAPException {
    SOAPConnection connection = null;
    try {
        connection = soapConnectionFactory.createConnection();
        return connection.call(soapMessage, WRAPPER_API_ENDPOINT);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:hermes    文件:AS2Sender.java   
/**
 * Send the web service request to Hermes2 requesting for sending  
 * a <code>AS2 message</code> loopback with a set of <code>payloads</code>.
 * 
 * @param payloads
 *          The payload set acting as the attachment in <code>AS2 Message</code>. 
 * @return 
 *          A String representing the ID of the message you request to send.            
 * @throws Exception            
 * 
 * @see hk.hku.cecid.corvus.test.Payload
 */
public String send(Payload [] payloads) throws Exception {
    // Make a SOAP Connection and SOAP Message.
    SOAPConnection soapConn = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage request = MessageFactory.newInstance().createMessage();

    // Populate the SOAP Body by filling the required parameters.
    /* This is the sample WSDL request for the sending AS2 message WS request.
     *  
     * <as2_from> as2from </as2_from>
     * <as2_to> as2to </as2_to>
     * <type> type </type>  
     */
    SOAPBody soapBody = request.getSOAPBody();
    soapBody.addChildElement(createElement("as2_from", nsPrefix, nsURI, this.as2From));
    soapBody.addChildElement(createElement("as2_to"  , nsPrefix, nsURI, this.as2To));
    soapBody.addChildElement(createElement("type"    , nsPrefix, nsURI, this.type));        

    // Add the payloads
    for (int i=0; i < payloads.length; i++) {
        AttachmentPart attachmentPart = request.createAttachmentPart();
        FileDataSource fileDS = new FileDataSource(new File(payloads[i].getFilePath()));
        attachmentPart.setDataHandler(new DataHandler(fileDS));
        attachmentPart.setContentType(payloads[i].getContentType());
        request.addAttachmentPart(attachmentPart);
    }

    // Send the request to Hermes and return the message Id to "sender" web services.       
    SOAPMessage response = soapConn.call(request, senderWSURL);
    SOAPBody responseBody = response.getSOAPBody();     

    if (!responseBody.hasFault()){
        SOAPElement messageIdElement = getFirstChild(responseBody, "message_id", nsURI);
        return messageIdElement == null ? null : messageIdElement.getValue();
    } else {
        throw new SOAPException(responseBody.getFault().getFaultString());
    }       
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
public List<Study> listStudies(String username, String passwordHash, String url) throws Exception { //TODO: handle exceptions
    log.info("List studies initiated by: " + username + " on: " + url);
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage message = requestFactory.createListStudiesRequest(username, passwordHash);
    SOAPMessage soapResponse = soapConnection.call(message, url + "/ws/study/v1");  // Add SOAP endopint to OCWS URL.
    List<Study> studies = ListStudiesResponseHandler.parseListStudiesResponse(soapResponse);
    soapConnection.close();
    return studies;
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
private MetaData getMetadataSoapCall(String username, String passwordHash, String url, Study study) throws Exception {
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage message = requestFactory.createGetStudyMetadataRequest(username, passwordHash, study);
    SOAPMessage soapResponse = soapConnection.call(message, url + "/ws/study/v1");  // Add SOAP endopint to OCWS URL.
    MetaData metaData = GetStudyMetadataResponseHandler.parseGetStudyMetadataResponse(soapResponse);
    soapConnection.close();
    return metaData;
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
/**
 * @param username     the user-account name
 * @param passwordHash the SHA1 hash of the user's password
 * @param url          the URL of the OpenClinica-ws instance
 * @param odm          the ODM string to upload
 * @return a non <code>null</code> error code.message if an error occurred. Some are reported by the OpenClinica-WS
 * instance at url. Returns <code>null</code> if everything went OK.
 * @throws Exception in case of a technical error
 */
private String uploadODMString(String username, String passwordHash, String url, String odm) throws Exception {


    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage soapMessage = requestFactory.createDataUploadRequest(username, passwordHash, odm);
    System.out.println("-->" + SoapUtils.soapMessageToString(soapMessage));
    SOAPMessage soapResponse = soapConnection.call(soapMessage, url + "/ws/data/v1");  // Add SOAP endopint to OCWS URL.
    String responseError = SOAPResponseHandler.parseOpenClinicaResponse(soapResponse, "//importDataResponse");
    if (responseError != null) {
        log.error("ImportData request failed: " + responseError);
    }
    return responseError;
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
public List<StudySubjectWithEventsType> getStudySubjectsType(String username, String passwordHash, String url, String studyIdentifier, String siteIdentifier) throws Exception {
    log.info("Get listAllByStudy by: " + username + " on: " + url + " study: " + siteIdentifier + " site: " + siteIdentifier);
    if (studyIdentifier == null || username == null || passwordHash == null || url == null) {
        return null;
    }
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage soapMessage = requestFactory.createListAllByStudy(username, passwordHash, studyIdentifier, siteIdentifier);
    SOAPMessage soapResponse = soapConnection.call(soapMessage, url + "/ws/studySubject/v1");  // Add SOAP endopint to OCWS URL.
    List<StudySubjectWithEventsType> subjectsTypeList =
            ListAllByStudyResponseHandler.retrieveStudySubjectsType(soapResponse);

    soapConnection.close();
    return subjectsTypeList;
}
项目:Open-Clinica-Data-Uploader    文件:OpenClinicaService.java   
public boolean isAuthenticated(String username, String /* hexdigest of sha1 password */ passwordHash, String url) throws Exception {
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage message = requestFactory.createListStudiesRequest(username, passwordHash);
    SOAPMessage soapResponse = soapConnection.call(message, url + "/ws/study/v1");  // Add SOAP endopint to OCWS URL.
    Document responseXml = SoapUtils.toDocument(soapResponse);
    soapConnection.close();
    return StringUtils.isEmpty(OCResponseHandler.isAuthFailure(responseXml));
}