@Test
  public void testSWA() throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();

    QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();
    ap1.setContent("Attachment content", "text/plain");
    msg.addAttachmentPart(ap1);
    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();

    SOAPConnection con = conFac.createConnection();
    URL endpoint =
        new URL("http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
    assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
    assertEquals(2, response.countAttachments());
  }
예제 #2
0
  public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    servletContext = servletConfig.getServletContext();

    try {
      SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
      con = scf.createConnection();
    } catch (Exception e) {
      logger.log(Level.SEVERE, "Unable to open a SOAPConnection", e);
    }

    InputStream in = servletContext.getResourceAsStream("/WEB-INF/address.properties");

    if (in != null) {
      Properties props = new Properties();

      try {
        props.load(in);

        to = props.getProperty("to");
        data = props.getProperty("data");
      } catch (IOException ex) {
        // Ignore
      }
    }
  }
 protected SOAPConnection createSOAPConnection() {
   try {
     SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
     return scf.createConnection();
   } catch (UnsupportedOperationException e) {
     throw new JRRuntimeException(e);
   } catch (SOAPException e) {
     throw new JRRuntimeException(e);
   }
 }
예제 #4
0
  private void doTestSoapConnection(boolean disableChunking) throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();

    if (disableChunking) {
      // this is the custom header checked by ServiceImpl
      msg.getMimeHeaders().addHeader("Transfer-Encoding-Disabled", "true");
      // this is a hint to SOAPConnection that the chunked encoding is not needed
      msg.getMimeHeaders().addHeader("Transfer-Encoding", "disabled");
    }

    QName sayHi = new QName("http://www.jboss.org/jbossws/saaj", "sayHello");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();

    char[] content = new char[16 * 1024];
    Arrays.fill(content, 'A');

    ap1.setContent(new String(content), "text/plain");
    msg.addAttachmentPart(ap1);

    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();

    SOAPConnection con = conFac.createConnection();

    final String serviceURL = baseURL.toString();

    URL endpoint = new URL(serviceURL);
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://www.jboss.org/jbossws/saaj", "sayHelloResponse");

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

    assertEquals(2, response.countAttachments());

    String[] values = response.getMimeHeaders().getHeader("Transfer-Encoding-Disabled");
    if (disableChunking) {
      // this means that the ServiceImpl executed the code branch verifying
      // that chunking was disabled
      assertNotNull(values);
      assertTrue(values.length == 1);
    } else {
      assertNull(values);
    }
  }
예제 #5
0
  public static void main(String args[]) throws Exception {
    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    // Send SOAP Message to SOAP Server
    String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx";
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

    // print SOAP Response
    System.out.print("Response SOAP Message:");
    soapResponse.writeTo(System.out);

    soapConnection.close();
  }
예제 #6
0
 /*
  * Method to send the passed SOAPMessage to the SOAPEndpoint URL
  * that is passed. The SOAP Message will then be sent across to the remote
  * provider in order to perform federation termination.
  * @param msg the <code>FSFederationTerminationNotification</code>
  *  SOAPMesage to be sent
  * @param soapEndPoint the SOAPEndpoint URL of remote provider
  * @return boolean true if successful else false
  */
 public boolean sendTerminationMessage(SOAPMessage msg, String soapEndPoint) {
   try {
     FSUtils.debug.message("started in func sendTerminationMessage");
     if (soapEndPoint == null) {
       FSUtils.debug.error("createSOAPReceiverURL Error!");
       String[] data = {FSUtils.bundle.getString("failCreateURLEndpoint")};
       LogUtil.error(Level.INFO, LogUtil.FAILED_SOAP_URL_END_POINT_CREATION, data);
       return false;
     }
     // Send the message to the provider using the connection.
     ByteArrayOutputStream output = new ByteArrayOutputStream();
     msg.writeTo(output);
     if (FSUtils.debug.messageEnabled()) {
       String xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
       FSUtils.debug.message("SENDING message: \n " + xmlString);
       FSUtils.debug.message("URLEndpoint :" + soapEndPoint);
     }
     SOAPConnection con = scf.createConnection();
     SOAPMessage reply = con.call(msg, soapEndPoint);
     FSUtils.debug.message("SOAP CALL COMPLETED");
     return true;
   } catch (Exception e) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("In catch of sendTerminationMessage", e);
     }
     return false;
   }
 }
예제 #7
0
  public SecurityToken logon(
      String anEndpointReference, String aUserName, String aPassword, String anApplicationID)
      throws LogonManagerException, SOAPException, IOException {
    SecurityToken result;
    SOAPMessage message;
    SOAPConnection conn = null;

    try {
      result = null;
      String request =
          REQUEST_FORMAT.format(
              ((Object) (new Object[] {fURL, aUserName, aPassword, anEndpointReference})));
      message =
          MessageFactory.newInstance()
              .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes()));
      conn = SOAPConnectionFactory.newInstance().createConnection();
      SOAPMessage response = conn.call(message, fURL);
      SOAPBody body = response.getSOAPBody();
      if (body.hasFault()) throw new LogonManagerException(body.getFault());
      result = new SecurityToken();
      result.setSOAPBody(body);
      for (Iterator it = body.getChildElements(); it.hasNext(); fill(result, (Node) it.next())) ;
      return result;
    } finally {
      if (conn != null) conn.close();
    }
  }
  /**
   * @param query the input of the user
   * @return SOAP message which is good for cross-platform web service
   */
  public SOAPMessage sendSOAPMessage(String query, URL serverURL) throws SOAPException {

    /** create a SOAP msg from query */
    SOAPMessage wsRequest = MessageFactory.newInstance().createMessage();

    // SOAP params
    SOAPPart part = wsRequest.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    SOAPBody body = envelope.getBody();

    // Name: a local name, a namespace prefix, and a namesapce URI.
    Name name = envelope.createName("query", "yyns", "http://cis555.co.nf/");
    SOAPElement elem = body.addChildElement(name);
    elem.addTextNode(query);
    //		body.addChildElement(envelope.createName("query", "yyns",
    // "http://cis555.co.nf/")).addTextNode(query);  //###
    wsRequest.saveChanges();

    /** send SOAP to P2P ring */
    // get response
    SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage wsResponse = conn.call(wsRequest, serverURL);
    conn.close();
    return wsResponse;
  }
예제 #9
0
 public WsRpcConnection() {
   try {
     connectionFactory = SOAPConnectionFactory.newInstance();
     messageFactory = MessageFactory.newInstance();
   } catch (Exception e) {
     logger.debug(e.getMessage(), e);
   }
 }
예제 #10
0
  public SOAPClient(String url, String soapAction)
      throws UnsupportedOperationException, SOAPException {
    // Create the connection
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    conn = scf.createConnection();

    // Create message
    MessageFactory mf = MessageFactory.newInstance();
    soapRequest = mf.createMessage();
    wsdlURL = url;

    // add SOAP Action
    if (soapAction != null) {
      MimeHeaders hd = soapRequest.getMimeHeaders();
      hd.addHeader("SOAPAction", soapAction);
    }
  }
예제 #11
0
  static {
    try {
      fac = MessageFactory.newInstance();
    } catch (Exception ex) {
      FSUtils.debug.error(FSUtils.bundle.getString("missingSOAPMessageFactory"), ex);
    }

    try {
      scf = SOAPConnectionFactory.newInstance();
    } catch (SOAPException e) {
      FSUtils.debug.error("FSSOAPService", e);
    }
  };
예제 #12
0
파일: SoapUtil.java 프로젝트: ossbase/frgu
  public static SOAPMessage sendSoapMessage(SOAPMessage soap, String url) {
    try {
      // Create SOAP Connection
      SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
      SOAPConnection soapConnection = soapConnectionFactory.createConnection();

      // Send SOAP Message to SOAP Server
      SOAPMessage soapResponse = soapConnection.call(soap, url);

      // Process the SOAP Response
      // printSOAP(soapResponse);

      soapConnection.close();

      return soapResponse;

    } catch (Exception e) {
      System.err.println("Error occurred while sending SOAP Request to Server");
      e.printStackTrace();

      return null;
    }
  }
예제 #13
0
  /*
   * Send a request to a locally running Cougar container via SOAP as per the
   * passed parameters.
   *
   * @param message
   * @param serviceName
   * @param version
   * @param httpBean
   * @return
   */
  public HttpResponseBean makeCougarSOAPCall(
      SOAPMessage message, String serviceName, String version, HttpCallBean httpBean) {
    try {

      // Debugging code
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();
      message.writeTo(outStream);
      SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
      SOAPConnection connection = connectionFactory.createConnection();

      // this can either be a SOAPException or SOAPMessage
      HttpResponseBean responseBean = new HttpResponseBean();
      Object response;

      String host = httpBean.getHost();
      String port = httpBean.getPort();

      String endPoint = "http://" + host + ":" + port + "/" + serviceName + "Service/" + version;

      try {

        response = connection.call(message, endPoint);

      } catch (SOAPException e) {
        response = e;
      } finally {
        connection.close();
      }

      responseBean.setResponseObject(handleResponse(response, responseBean));

      return responseBean;

    } catch (SOAPException | IOException | ParserConfigurationException | TransformerException e) {
      throw new RuntimeException(SOAP_CALL_TEXT + e, e);
    }
  }
예제 #14
0
  @Override
  public RpcResult invoke(RpcInvokeAction rpcInvokeAction) {
    SimpleRpcResult result = new SimpleRpcResult();
    try {
      SOAPConnection connection = connectionFactory.createConnection();
      soapToRpcResult(
          connection.call(
              actionToSoap(rpcInvokeAction), getServiceURL(rpcInvokeAction.getRpcPath())),
          rpcInvokeAction,
          result);
      connection.close();
    } catch (Exception e) {
      throw (new WsRpcConnectionRuntimeException(e));
    }

    return result;
  }
예제 #15
0
  /**
   * executeCall method intakes SOAP Message, establishes connection to PhaseIV Web Service to
   * invoke processRequest method and returns response SOAMPmessage.
   *
   * @param request Input SOAPMessage with xmlRequest
   * @return SOAPMessage with xmlResponse.
   * @throws Exception
   */
  private SOAPMessage executeCall(SOAPMessage request, String clientURL) throws Exception {

    SOAPMessage respMsg = null;
    SOAPConnection conn = null;

    try {
      conn = SOAPConnectionFactory.newInstance().createConnection();
      logger.debug("clientURL:" + clientURL);
      respMsg = conn.call(request, clientURL);
      logger.debug("executeCall .... completed" + respMsg);
    } catch (Exception exp) {
      logger.error("executeCall -->error while invoking PhaseIV web service:" + exp.getMessage());
      throw exp;
    } finally {
      if (conn != null) conn.close();
    }

    return respMsg;
  }
예제 #16
0
  /*
   * Sends a synchronous SOAPMessage to remote provider.
   * @param response the http response object
   * @param msg the <code>SOAPMessage</code> to be sent
   * @param partnerDecriptor the remote provider meta descriptor
   * @param needAuthn determines forced authn
   * @return <code>SOAPMessage</code> corresponding to liberty
   *  request/response message
   * @exception IOException, SOAPException if error occurrs
   */
  public SOAPMessage doSyncCall(
      HttpServletResponse response,
      SOAPMessage msg,
      ProviderDescriptorType partnerDecriptor,
      boolean needAuthn)
      throws IOException, SOAPException {
    FSUtils.debug.message("FSSOAPService.doSyncCall: Called");

    String soapURL = createSOAPReceiverUrl(response, partnerDecriptor, false);
    if (soapURL == null) {
      FSUtils.debug.error("FSSOAPService.doSyncCall: " + "createSOAPReceiverURL Error!");
      String[] data = {FSUtils.bundle.getString("failCreateURLEndpoint")};
      LogUtil.error(Level.INFO, LogUtil.FAILED_SOAP_URL_END_POINT_CREATION, data);
      return null;
    }
    // Send the message to the provider using the connection.
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    msg.writeTo(output);
    String xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
    if (FSUtils.debug.messageEnabled()) {
      FSUtils.debug.message("FSSOAPService.doSyncCall: SENDING message\n" + xmlString);
    }
    SOAPConnection con = scf.createConnection();
    SOAPMessage reply = con.call(msg, soapURL);
    if (reply == null) {
      response.sendError(
          response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("noReplyfromSOAPReceiver"));
      return null;
    }

    // check the SOAP message for any SOAP related errors
    // before passing control to SAML processor
    output = new ByteArrayOutputStream();
    reply.writeTo(output);
    xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
    if (FSUtils.debug.messageEnabled()) {
      FSUtils.debug.message("FSSOAPService.doSyncCall: REPLIED message:\n" + xmlString);
    }
    return reply;
  }
예제 #17
0
 /*
  * Sends the passed SOAPMessage to the SOAPEndpoint URL
  * that is passed.
  * @param msg the <code>SOAPMessage</code> to be sent
  * @param soapEndPoint the SOAPEndpoint URL of remote provider
  * @return SOAPMessage response message from remote provider
  * @exception IOException, SOAPException if error occurrs
  */
 public SOAPMessage sendMessage(SOAPMessage msg, String soapEndPoint)
     throws IOException, SOAPException {
   try {
     FSUtils.debug.message("just started in func sendMessage");
     if (soapEndPoint == null) {
       FSUtils.debug.error("createSOAPReceiverURL Error!");
       String[] data = {soapEndPoint};
       LogUtil.error(Level.INFO, LogUtil.FAILED_SOAP_URL_END_POINT_CREATION, data);
       return null;
     }
     // Send the message to the provider using the connection.
     ByteArrayOutputStream output = new ByteArrayOutputStream();
     msg.writeTo(output);
     String xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message(
           "SENDING message: \n " + xmlString + "\nURLEndpoint :" + soapEndPoint + "\nSOAP CALL");
     }
     SOAPConnection con = scf.createConnection();
     SOAPMessage reply = con.call(msg, soapEndPoint);
     FSUtils.debug.message("SOAP CALL COMPLETED");
     if (reply == null) {
       return null;
     }
     // check the SOAP message for any SOAP related errors
     // before passing control to SAML processor
     output = new ByteArrayOutputStream();
     reply.writeTo(output);
     xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("REPLIED message: \n " + xmlString);
     }
     return reply;
   } catch (Exception e) {
     FSUtils.debug.error("In catch of sendMessage", e);
     return null;
   }
 }
예제 #18
0
  public boolean patientAndProviderEmailSend(
      String fromUser,
      String fromUserProvider,
      String toUser,
      String toUserProvider,
      String subject,
      String message) {
    String ret = "";
    // System.out.println("ticket: "+ticket);
    try {
      SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
      SOAPConnection conn = scf.createConnection();

      // Create message
      MessageFactory mf = MessageFactory.newInstance();
      SOAPMessage msg = mf.createMessage();

      // Object for message parts
      SOAPPart sp = msg.getSOAPPart();

      SOAPEnvelope env = sp.getEnvelope();
      env.addNamespaceDeclaration("soap", "http://schemas.xmlsoap.org/soap/envelop/");
      env.addNamespaceDeclaration("urn", "urn:gov:hhs:fha:nhinc:common:task");

      SOAPHeader header = env.getHeader();

      SOAPBody body = env.getBody();

      // Populate body
      SOAPElement be = body.addChildElement("SendMailTaskRequest", "urn");
      be.addChildElement("taskID", "urn").addTextNode(EMAIL_TASK_ID);
      be.addChildElement("fromUser", "urn").addTextNode(fromUser);
      be.addChildElement("fromUserProvider", "urn").addTextNode(fromUserProvider);
      be.addChildElement("toUser", "urn").addTextNode(toUser);
      be.addChildElement("toUserProvider", "urn").addTextNode(toUserProvider);
      be.addChildElement("subject", "urn").addTextNode(subject);
      be.addChildElement("message", "urn").addTextNode(message);
      //            be.addChildElement("ticket", "urn").addTextNode(ticket);
      //            be.addChildElement("action", "urn").addTextNode(action);
      //            be.addChildElement("message", "urn").addTextNode(message);
      //            be.addChildElement("patientID", "urn").addTextNode(patientId);

      // Save message
      msg.saveChanges();

      // View input
      // System.out.println("\n Soap request:\n");
      // msg.writeTo(System.out);

      // Send
      // String urlval = "http://208.75.163.61:8080/TaskManager/TaskManagerService";
      String urlval = getProperty("EmailSendEndpoint");
      SOAPMessage reply = conn.call(msg, urlval);

      // Create transformer
      TransformerFactory tff = TransformerFactory.newInstance();
      Transformer tf = tff.newTransformer();

      // Get reply content
      Source source = reply.getSOAPPart().getContent();
      Writer outWriter = new StringWriter();

      // Set output transformation
      // StreamResult result = new StreamResult(System.out);
      StreamResult result = new StreamResult(outWriter);

      // transfrom to get the xml
      tf.transform(source, result);

      // close connection
      conn.close();

      String xmlSource = outWriter.toString();
      ret = xmlSource;
      // System.out.println("mail test: "+ret);
    } catch (Exception e) {
      e.printStackTrace();
    }
    // assertTrue(ret.indexOf("<detail>Success</detail>")>0);
    if (ret.indexOf("<detail>Success</detail>") > 0) return true;
    return false;
  }