Skip to content

Instantly share code, notes, and snippets.

@atroche
Created April 14, 2011 11:29
Show Gist options
  • Save atroche/919299 to your computer and use it in GitHub Desktop.
Save atroche/919299 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author dan.ware
*/
public class DMWS_Simple_Servlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// For more info on consuming Web Services;
// http://netbeans.org/kb/docs/websvc/client.html
//
// Docmail Simple API (Test) WSDL
// https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?WSDL
//
// Docmail Test website
// https://www.cfhdocmail.com/test/
//
// This example uses the [SendLetterToAddressCSV_AllFromURLs] operation
try { // Call Web Service Operation
org.tempuri.QuickMail service = new org.tempuri.QuickMail();
org.tempuri.QuickMailSoap port = service.getQuickMailSoap();
// NOTE: The following code was automatically generated by NetBeans
// initialize WS operation arguments here
java.lang.String sUsr = "JavaTest";
java.lang.String sPwd = "javatest";
java.lang.String sMailingName = "JAVA TEST";
java.lang.String sCallingApplicationID = "DMWS_Simple_Servlet";
java.lang.String sTemplateURL = "https://www.cfhdocmail.com/Test_SimpleAPI/apitest.doc";
boolean bColour = false;
boolean bDuplex = false;
org.tempuri.DeliveryType eDeliveryType = org.tempuri.DeliveryType.FIRST_CLASS;
org.tempuri.AddressNameFormat eAddressNameFormat = org.tempuri.AddressNameFormat.TITLE_FIRSTNAME_SURNAME;
java.lang.String sAddressCSVURL = "https://www.cfhdocmail.com/Test_SimpleAPI/apitest1.csv";
java.lang.String sCSVFieldMappingName = "";
boolean bProofApprovalRequired = false;
// process result here
org.tempuri.Result oResult = port.sendLetterToAddressCSVAllFromURLs(sUsr, sPwd, sMailingName, sCallingApplicationID, sTemplateURL, bColour, bDuplex, eDeliveryType, eAddressNameFormat, sAddressCSVURL, sCSVFieldMappingName, bProofApprovalRequired);
// display result information
if (oResult.getErrorText().length() > 0) {
out.println("<p style='color:#f00'><strong>FAILED:</strong><br />"+oResult.getErrorText()+"</p>");
} else {
out.println("<p><strong>Result:</strong><br />");
out.println("Order "+oResult.getOrderNumber()+" created<br />");
out.println("Order value: &pound;"+oResult.getCost()+" - "+oResult.getBalanceMessage());
out.println("</p>");
}
out.println("</body>");
out.println("</html>");
out.close();
} catch (Exception ex) {
System.out.println("Exception: "+ex);
out.println("<p style='color:#f00'><strong>Exception:</strong><br />"+ex+"</p>");
}
out.println("</body>");
out.println("</html>");
out.close();
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment