ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Apache-Soap-Dev
Apache-Soap-Dev
Re: Help with SOAP Message Routing !!!
by Michael Fasosin other posts by this author
Apr 28 2003 5:20PM messages near this date
Re: Help with SOAP Message Routing !!! | Re: Help with SOAP Message Routing !!!
Hi Scott,

Thanks for that, I've revised that. I think I added that in desperation this
morning. My problem still remains though.

I have the following question. As I've not seen a single good example
anywhere that does this in the sample code or anywhere else. I will post the
correct code out once this is working as I've seen loads of folks ask the
same question.

If you have a SOAP envelope from a Messaging method() using SOAPContext, do
you or do you not need to unmarshall the envelope and if you do what is the
correct way of doing so.e.g. using a signature :-

fooBar (Envelope requestEnvelope,SOAPContext requestContext,SOAPContext
responseContext) throws some stuff

Secondly,  If you are retrieving elements from the  Nodes as I was doing
using wc3.dom in Xerces, You can send the content of your headerentries and
bodyentries to a Writer class or something but what if you need to move the
attributes somewhere else, that's why I thought maybe it is a marshalling
problem. If so What is the correct way of doing so.

Thanks for looking at this.

Michael
----- Original Message -----
From: "Scott Nichol" <snicholnews@[...].com> 
To: <soap-dev@[...].org> 
Sent: Monday, April 28, 2003 6:02 PM
Subject: Re: Help with SOAP Message Routing !!!


>  Here's some code that is probably not what you meant to do:
> 
>                 // Loop through each ordered RoomDoc from the SOAP
>  request
>                 logger.debug("<Checking the ReferenceDocuments Tag>");
>                 SOAPContext MimeSOAPContext = new SOAPContext();
> 
>  The new SOAPContext() creates an empty context, not a copy of the
>  request.  Don't you want to be examining the requestContext?
> 
> 
>  On 28 Apr 2003 at 8:17, Michael Fasosin wrote:
> 
>  > Hi All,
>  >
>  >
>  > I have a problem using SOAP2.3.1  Message Routing
>  >
>  > The Application I'm developing is essentially a SOAPService that will
receive invoice/purchase order notifications with attachments etc. I've used
>  > the Apache Message Router to receive the message using the <method>
<reqContext, reContext .....>  signature.
>  >
>  > When I receive the message and I want to process it as indicated
(essentially put the items in a vector) in the method below source. Nothing
seems to happen. I don't know if I need to create a Document from the
envelope or not. I've not found any reasonalble example that gives me an
indication
>  as to what to do. I'll appreciate if you can spare a moment to look at the
method below. The code executes all the logic but doesn't seem to populate
my vector. The Writer however has data and writes to the log file.
>  >
>  > I'm using SOAP2.3 Libraries on Tomcat 4.0.1 javax.* transformer DOM
libraries in the Apache Xerces 2.3 Libraries.
>  >
>  > I've pasted the relevant section of the code below.  I have a feeling it
might have something to do with unmarshalling a document from the
requestEnvelope not sure if I really need to do that for this so I'm asking
for opinion from you folks.
>  >
>  > Thanks for your help
>  >
>  > Mike
>  >
>  >
>  >
>  >  public class InvoiceIntegrationService
>  >      extends HttpServlet
>  >      implements HttpMappingConstants {
>  >
>  > ........................................................
>  >
>  >    /**
>  >     *
>  >     * <br>
>  >     * This is the main method() that will be called when we get an
incoming Request. This service will call
>  >         * others Services to do the rest of the work related to creating
the  Room
>  >     * do the main work which is receiving the SOAP/XML Request from a
Client and processing it.
>  >     * <br>
>  >     * Example:<br>
>  >     * <br>
>  >     *  http://fragma.com/soapserver/servlet/messagerouter<br>
>  >     * <br>
>  >     *
>  >     */
>  >    public void ReceiveEnvelopeWithAttachments(Envelope requestEnvelope,
>  >                                                  SOAPContext
requestContext,
>  >                                                  SOAPContext
responseContext) throws
>  >        IOException,
>  >        ServletException, SOAPException {
>  >      //Clear up anything we have from previous calls in Globals.
>  >      long startTime = new Date().getTime();
>  >
>  >      initElementsMappings();
>  >      HttpServletRequest request = (HttpServletRequest)
>  >          requestContext.getProperty(Constants.BAG_HTTPSERVLETREQUEST);
>  >      // Get the BASIC Authorization header from the Request
>  >      String authenticate = request.getHeader("Authorization");
>  >      // First Thing We'll do is Attempt to Authenticate The User.
>  >      logger.debug("Attempting to Authenticate The User" + authenticate);
>  >      if (!allowUser(authenticate)) {
>  >        // Not allowed, so report he's unauthorized
>  >        logger.debug("User Not Authorized");
>  >      }
>  >      else {
>  >        // We will place the rest of our code in here.
>  >        logger.debug("User Authorized");
>  >        try {
>  >          initElementsMappings();
>  >
>  >          logger.debug("<Received a Create Invoice Room Request>");
>  >          // We need to trasverse the Header to see what is in there.
>  >          // Traverse the HTTP headers and show them on the screen
>  >          logger.debug(
>  >              "<We Need to Traverse the HTTP Headers and Show Them on the
Screen> ");
>  >          Header header = requestEnvelope.getHeader();
>  >          Vector headerEntries = header.getHeaderEntries();
>  >
>  >          for (Enumeration enum = headerEntries.elements();
enum.hasMoreElements(); ) {
>  >            Element el = (Element) enum.nextElement();
>  >            DOM2Writer.serializeAsXML( (Node) el, QMSWriter);
>  >          }
>  >          Body body = requestEnvelope.getBody();
>  >          Vector bodyEntries = body.getBodyEntries();
>  >          //We'll get the Top Level Body Entry Tag.
>  >
>  >          logger.debug("<----------------------->");
>  >          for (Enumeration e = bodyEntries.elements();
e.hasMoreElements(); ) {
>  >            Element el = (Element) e.nextElement();
>  >            DOM2Writer.serializeAsXML( (Node) el, QMSWriter);
>  >
>  >            Element ReferenceDocuments = (Element)
el.getElementsByTagName(
>  >                "ReferenceDocuments").item(0);
>  >            if (ReferenceDocuments != null) {
>  >              try {
>  >                // Loop through each ordered RoomDoc from the SOAP
request
>  >                logger.debug("<Checking the ReferenceDocuments Tag>");
>  >                SOAPContext MimeSOAPContext = new SOAPContext();
>  >                // get the number of attachment count
>  >                int attachmentCount = MimeSOAPContext.getCount();
>  >                MimeBodyPart attachment;
>  >                // Get root part
>  >                MimeBodyPart rootPart = MimeSOAPContext.getRootPart();
>  >                // For every Attachment Received Get the BodyPart
>  >                for (int i = 0; i < MimeSOAPContext.getCount(); i++) {
>  >                  attachment = (MimeBodyPart)
requestContext.getBodyPart(i);
>  >                  logger.debug(attachment);
>  >                  if (! (attachment.equals(rootPart))) {
>  >                    String qmsMimeType = attachment.getContentType();
>  >                    // Add the Documents Received into our CSPACE Vector
Ready for use
>  >                    String fileName =
ReferenceDocuments.getAttribute("fileName");
>  >                    String documentName =
ReferenceDocuments.getAttribute(
>  >                        "documentName");
>  >                    cid =
ReferenceDocuments.getAttribute("href").substring(4); // We want to get rid
of the cid:.
>  >                    QMSWriter.write("Content-ID = "+cid+"\n");
>  >                    Object content = attachment.getContent();
>  >                    QMSWriter.write("The attachment
is...\n"+attachment.getContent()+"\n");
>  >                    String classType = content.getClass().getName();
>  >                    if (attachment.isMimeType("text/*")) {
>  >                      logger.debug("<The mime data is in text format>");
>  >                    }
>  >                    else {
>  >                      logger.debug("<The mime data is in binary
format> ");
>  >                    }
>  >                    qmsItemsVect.addElement("fileName");
>  >                    qmsItemsVect.addElement("documentName");
>  >                    qmsItemsVect.addElement("qmsBodyPart");
>  >                    qmsItemsVect.addElement("qmsMimeType");
>  >                  }
>  >
>  >                }
>  >
>  >              }
>  >              catch (Exception DocItem) {
>  >                throw new SOAPException(HttpMappingConstants.
>  >                                        INVOICEROOMCREATIONFAILDOCATTACH,
>  >                                        "Parsing Error Encountered",
DocItem);
>  >              }
>  >            }
>  >            //Move the Room Items into something we can use.
>  >            // Ok Folks so We got this Item, We need to check that We
have something in here.
>  >            Element InvoiceRoom = (Element) el.getElementsByTagName(
>  >                "InvoiceRoom").item(0);
>  >
>  >            if (InvoiceRoom != null) {
>  >
>  >              try {
>  >                // Loop through each ordered InvoiceRoom from the SOAP
request
>  >                logger.debug("<Checking the InvoiceRoom Tag>");
>  >                String invoiceNumber = InvoiceRoom.getAttribute(
>  >                    "invoiceNumber");
>  >                String invoiceDate = InvoiceRoom.getAttribute(
>  >                    "invoiceDate");
>  >                String invoiceValue = InvoiceRoom.getAttribute(
>  >                    "invoiceValue");
>  >                String invoiceCurrency = InvoiceRoom.getAttribute(
>  >                    "invoiceCurrency");
>  >                String poNumber = InvoiceRoom.getAttribute("poNumber");
>  >                String queryCreationDateTime = InvoiceRoom.getAttribute(
>  >                    "queryCreationDateTime");
>  >                String invoiceCustomer = InvoiceRoom.getAttribute(
>  >                    "invoiceCustomer");
>  >                //    InvoiceFolder =
InvoiceFolder.concat(HttpMappingConstants.INVOICEFOLDER);
>  >                //  InvoiceFolder =
InvoiceFolder.concat(invoiceCustomer);
>  >                //   discussionAddress =
discussionAddress.concat(invoiceCustomer);
>  >                //  discussionAddress =
discussionAddress.concat(invoiceNumber);
>  >                logger.debug("Showing The Content of InvoiceFolder" +
>  >                             InvoiceRoom.getAttribute("invoiceNumber"));
>  >                logger.debug("Showing The Content of Discussion" +
>  >                             InvoiceCustomer);
>  >                String tpID = InvoiceRoom.getAttribute("tpID");
>  >                String supplier = InvoiceRoom.getAttribute("supplier");
>  >
>  >                // Add the Items Received into our Vector Ready for use
>  >                qmsItemsVect.addElement("invoiceNumber");
>  >                qmsItemsVect.addElement("invoiceDate");
>  >                qmsItemsVect.addElement("invoiceValue");
>  >                qmsItemsVect.addElement("invoiceCurrency");
>  >                qmsItemsVect.addElement("poNumber");
>  >                qmsItemsVect.addElement("queryCreationDateTime");
>  >                qmsItemsVect.addElement("InvoiceCustomer");
>  >                qmsItemsVect.addElement("tpID");
>  >                qmsItemsVect.addElement("supplier");
>  >                //  qmsItemsVect.addElement("InvoiceFolder");
>  >                //  qmsItemsVect.addElement("discussionAddress");
>  >              }
>  >              catch (Exception RoomItem) {
>  >                throw new SOAPException(HttpMappingConstants.
>  >                                        INVOICEROOMCREATIONFAILINVNUM,
>  >                                        "Parsing Error Encountered",
>  >                                        RoomItem);
>  >              }
>  >            }
>  >            //Move the WebURLs Items into something we can use.
>  >            Element WebURL = (Element) el.getElementsByTagName(
>  >                "WebURL").item(0);
>  >            if (WebURL != null) {
>  >              try {
>  >                logger.debug("<Checking the WebURL Tag>");
>  >               // Loop through each ordered WebURL from the SOAP request
>  >                String urlName = WebURL.getAttribute("urlName");
>  >                String urlLink = WebURL.getAttribute("URL");
>  >                // Add the WebURLs Received into our Vector Ready for use
>  >                qmsItemsVect.addElement("urlName");
>  >                qmsItemsVect.addElement("urlLink");
>  >              }
>  >              catch (Exception WebItem) {
>  >                throw new SOAPException(HttpMappingConstants.
>  >                                        INVOICEROOMCREATIONFAILED,
>  >                                        "Web URL Not Specified",
WebItem);
>  >              }
>  >            }
>  >          }
>  >
>  >          logger.debug(QMSWriter.toString());
>  >
>  >          long stopTime = new Date().getTime() - startTime;
>  >          logger.debug("Time for Processing SOAP Request Operation: " +
stopTime);
>  >
>  >          try {
>  >            // Send the envelope back to the client
>  >            env.marshall(QMSWriter, null);
>  >            responseContext.setRootPart(QMSWriter.toString(),
>  >                                        "text/xml");
>  >          }
>  >          catch (Exception e) {
>  >            throw new SOAPException(Constants.FAULT_CODE_SERVER,
>  >                "Error Writing Response Message Back To Server", e);
>  >          }
>  >
>  >        }
>  >        catch (Exception e) {
>  >          throw new SOAPException(BexHttpMappingConstants.
>  >                                  INVOICEROOMCREATIONFAILED,
>  >                                  "Error Attempting to Create Invoice
Room", e);
>  >        }
>  >      }
>  >
>  >    }
> 
> 
>  Scott Nichol
> 
>  Do not reply directly to this e-mail address,
>  as it is filtered to only receive e-mail from
>  specific mailing lists.
> 
> 
Thread:
Michael Fasosin
Scott Nichol
Michael Fasosin
Scott Nichol
Scott Nichol

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved