whitlock    2003/02/21 07:54:42

  Modified:    java/test/docStyle/wsifservice nwBank.wsdl
                        zipCodeResolver.wsdl
               java/src/org/apache/wsif/util/jms JMS2HTTPBridge.java
  Log:
  16693: Fix docstyle/jms tests by supporting WSIFServiceURL in the bridge
  
  Revision  Changes    Path
  1.4       +2 -2      xml-axis-wsif/java/test/docStyle/wsifservice/nwBank.wsdl
  
  Index: nwBank.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/docStyle/wsifservice/nwBank.wsdl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- nwBank.wsdl       7 Dec 2002 12:34:02 -0000       1.3
  +++ nwBank.wsdl       21 Feb 2003 15:54:42 -0000      1.4
  @@ -150,9 +150,9 @@
                      jndiConnectionFactoryName="WSIFSampleQCF"
                      
initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"
                      jndiProviderURL="file:///JNDI-Directory">
  -            <jms:propertyValue name="ServiceURL" type="s:string" 
  +            <jms:propertyValue name="WSIFServiceURL" type="s:string" 
                   value="http://server1.pointwsp.net/ws/finance/currency.asmx"/> 
  -      </jms:address>
  +      </jms:address> 
       </port>
     </service>
   </definitions>
  
  
  
  1.4       +2 -2      
xml-axis-wsif/java/test/docStyle/wsifservice/zipCodeResolver.wsdl
  
  Index: zipCodeResolver.wsdl
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/test/docStyle/wsifservice/zipCodeResolver.wsdl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- zipCodeResolver.wsdl      7 Dec 2002 12:34:02 -0000       1.3
  +++ zipCodeResolver.wsdl      21 Feb 2003 15:54:42 -0000      1.4
  @@ -496,9 +496,9 @@
                      jndiConnectionFactoryName="WSIFSampleQCF"
                      
initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"
                      jndiProviderURL="file:///JNDI-Directory">
  -            <jms:propertyValue name="ServiceURL" type="s:string" 
  +            <jms:propertyValue name="WSIFServiceURL" type="s:string" 
                   
value="http://webservices.eraserver.net/zipcoderesolver/zipcoderesolver.asmx"/> 
  -<!--            <jms:propertyValue name="ServiceURL" type="s:string" 
  +<!--            <jms:propertyValue name="WSIFServiceURL" type="s:string" 
                   value="http://localhost:8080/soap/servlet/rpcrouter"/> --> 
         </jms:address>
       </port>
  
  
  
  1.13      +93 -66    
xml-axis-wsif/java/src/org/apache/wsif/util/jms/JMS2HTTPBridge.java
  
  Index: JMS2HTTPBridge.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/util/jms/JMS2HTTPBridge.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JMS2HTTPBridge.java       19 Feb 2003 16:08:33 -0000      1.12
  +++ JMS2HTTPBridge.java       21 Feb 2003 15:54:42 -0000      1.13
  @@ -100,7 +100,7 @@
    * @author Mark Whitlock <[EMAIL PROTECTED]>
    */
   public class JMS2HTTPBridge {
  -    private URL httpURL = null;
  +    private String httpURL = null;
       private JMS2HTTPBridgeDestination destination = null;
   
       private static final ArrayList outGoingHeaders =
  @@ -143,7 +143,7 @@
           String jndiUrl,
           String queueConnectionFactory,
           String readQueue,
  -        String httpUrlString,
  +        String httpURL,
           String startType,
           int syncTimeout,
           boolean verbose)
  @@ -154,7 +154,7 @@
               jndiUrl,
               queueConnectionFactory,
               readQueue,
  -            httpUrlString,
  +            httpURL,
               startType,
               new Integer(syncTimeout),
               new Boolean(verbose));
  @@ -176,7 +176,7 @@
                       + readQueue
                       + "\n"
                       + "HTTP URL = "
  -                    + httpUrlString
  +                    + httpURL
                       + "\n"
                       + "Start Type = "
                       + startType
  @@ -202,7 +202,7 @@
                   startType,
                   verbose);
   
  -        httpURL = new URL(httpUrlString);
  +        this.httpURL = httpURL;
           this.syncTimeout = syncTimeout;
           this.verbose = verbose;
           Trc.exit();
  @@ -220,7 +220,7 @@
                   + "-s <sampleName> "
                   + "-qcf <queueConnectionFactory> "
                   + "-q <readQueue> "
  -                + "-http <httpUrl> "
  +                + "-http <httpURL> "
                   + "-t <syncTimeout> "
                   + "-v";
   
  @@ -231,7 +231,7 @@
           String sampleName = null;
           String queueConnectionFactory = "WSIFSampleQCF";
           String readQueue = null;
  -        String httpUrlString = "http://localhost:8080/soap/servlet/rpcrouter";;
  +        String httpURL = "http://localhost:8080/soap/servlet/rpcrouter";;
           // Sync timeout of 10000 milliseconds is the default.
           int syncTimeout = 10000;
           boolean verbose = false;
  @@ -261,7 +261,7 @@
                   readQueue = args[idx];
               } else if (args[idx].equals("-http")) {
                   idx++;
  -                httpUrlString = args[idx];
  +                httpURL = args[idx];
               } else if (args[idx].equals("-t")) {
                   idx++;
                   syncTimeout = new Integer(args[idx]).intValue();
  @@ -279,7 +279,7 @@
               || jndiUrl == null
               || queueConnectionFactory == null
               || readQueue == null
  -            || httpUrlString == null)
  +            || httpURL == null)
               throw new Exception("Missing parameter\n" + usage);
   
           JMS2HTTPBridge j2h =
  @@ -288,7 +288,7 @@
                   jndiUrl,
                   queueConnectionFactory,
                   readQueue,
  -                httpUrlString,
  +                httpURL,
                   startType,
                   syncTimeout,
                   verbose);
  @@ -319,13 +319,16 @@
                           System.out.println(
                               "JMS2HTTPBridge Message contained '" + body + "'");
   
  +                    String url = getServiceURL(msg);
  +                    URL tmpUrl = new URL(url);
  +                    String host = tmpUrl.getHost();
  +                    int port = tmpUrl.getPort();
  +
                       statusCode = null;
                       statusMessage = null;
                       BooleanHolder useFullURL = new BooleanHolder(false);
                       StringBuffer otherHeaders = new StringBuffer();
  -                    String host = httpURL.getHost();
  -                    int port = httpURL.getPort();
  -
  +                    
                       // The SocketFactoryFactory.getFactory method has changed 
                       // signature between Axis 1.0 and Axis 1.1 so avoid its use
                       // by using DefaultSocketFactory instead. This prevents the
  @@ -345,6 +348,7 @@
                                   (String) msg.getStringProperty(
                                       "WSIFContentType");
                           } catch (JMSException je) {
  +                             // Safe to ignore this exception as ct has a good 
default
                               Trc.ignoredException(je);
                           }
                       }
  @@ -355,6 +359,7 @@
                               action =
                                   (String) msg.getStringProperty("SOAPAction");
                           } catch (JMSException je) {
  +                             // Safe to ignore this exception as action has a good 
default
                               Trc.ignoredException(je);
                           }
                       }
  @@ -363,7 +368,7 @@
                           writeToSocket(
                               sock,
                               body,
  -                            httpURL,
  +                            url,
                               otherHeaders,
                               host,
                               port,
  @@ -383,7 +388,37 @@
               }
           } catch (Exception e) {
               Trc.exception(e);
  -            System.err.println("JMS2HTTPBridge caught " + e);
  +            e.printStackTrace();
  +
  +            String errText =
  +                "<?xml version='1.0' encoding='UTF-8'?>\n"
  +                    + "<SOAP-ENV:Envelope "
  +                    + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
"
  +                    + "xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\"; "
  +                    + "xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\";>\n"
  +                    + "<SOAP-ENV:Body>\n"
  +                    + "<SOAP-ENV:Fault>\n"
  +                    + "<faultcode>SOAP-ENV:Server</faultcode>\n"
  +                    + "<faultstring>"
  +                    + "JMS2HTTPBridge caught "
  +                    + e
  +                    + "</faultstring>\n"
  +                    + 
"<faultactor>org.apache.wsif.util.jms.JMS2HTTPBridge</faultactor>\n"
  +                    + "</SOAP-ENV:Fault>\n\n"
  +                    + "</SOAP-ENV:Body>\n"
  +                    + "</SOAP-ENV:Envelope>";
  +
  +            try {
  +                destination.setReplyToQueue((Queue) original.getJMSReplyTo());
  +                destination.send(errText, original.getJMSMessageID());
  +            } catch (Exception e2) {
  +                // Deep trouble
  +                Trc.exception(e2);
  +                System.err.println(
  +                    "JMS2HTTPBridge unable to send exception information "
  +                        + "back to the WSIF client. Exception "
  +                        + e2);
  +            }
           }
   
           Trc.exit();
  @@ -408,7 +443,7 @@
       private InputStream writeToSocket(
           Socket sock,
           String body,
  -        URL tmpURL,
  +        String url,
           StringBuffer otherHeaders,
           String host,
           int port,
  @@ -422,7 +457,7 @@
               this,
               sock,
               body,
  -            tmpURL,
  +            url,
               otherHeaders,
               host,
               new Integer(port),
  @@ -449,19 +484,6 @@
               action = "";
           }
   
  -        // if UserID is not part of the context, but is in the URL, use
  -        // the one in the URL.
  -        if ((userID == null) && (tmpURL.getUserInfo() != null)) {
  -            String info = tmpURL.getUserInfo();
  -            int sep = info.indexOf(':');
  -
  -            if ((sep >= 0) && (sep + 1 < info.length())) {
  -                userID = info.substring(0, sep);
  -                passwd = info.substring(sep + 1);
  -            } else {
  -                userID = info;
  -            }
  -        }
           if (userID != null) {
               StringBuffer tmpBuf = new StringBuffer();
   
  @@ -498,15 +520,8 @@
           StringBuffer header = new StringBuffer();
   
           // byte[] request = reqEnv.getBytes();
  -        header.append(HTTPConstants.HEADER_POST).append(" ");
  -        if (useFullURL.value) {
  -            header.append(tmpURL.toExternalForm());
  -        } else {
  -            header.append(
  -                (((tmpURL.getFile() == null) || tmpURL.getFile().equals(""))
  -                    ? "/"
  -                    : tmpURL.getFile()));
  -        }
  +        header.append(HTTPConstants.HEADER_POST).append(" ").append(
  +            new URL(url).getFile());
   
           //        Message reqMessage = msgContext.getRequestMessage();
   
  @@ -1018,17 +1033,23 @@
           throws Exception {
           Trc.entry(this, inp, contentType, contentLocation);
   
  +        // Zero means unknown length. Will just read from inp once.
           int cl = 0;
  -        try {
  -            cl = new Integer(contentLength).intValue();
  -        } catch (Exception e) {
  -            Trc.ignoredException(e);
  -        }
  -        
  -        byte[] buff = new byte[cl];
  +        if (contentLength != null)
  +            try {
  +                cl = new Integer(contentLength).intValue();
  +            } catch (Exception e) {
  +                Trc.ignoredException(e);
  +            }
  +
  +        byte[] buff = null;
  +        if (cl != 0)
  +            buff = new byte[cl];
  +
           int bytesRead = 0;
           int cnt = 0;
  -        while (bytesRead < cl) {
  +        // do {} while() ensures we read once if contentLength is unknown
  +        do {
               int avail = inp.available();
               while ((avail == 0)
                   && ((syncTimeout == 0) || (cnt * 100 < syncTimeout))) {
  @@ -1040,12 +1061,13 @@
                   avail = inp.available();
               }
   
  -            if (cnt * 100 >= syncTimeout) {
  -                System.err.println(
  +            if (syncTimeout != 0 && cnt * 100 >= syncTimeout) {
  +                String errText =
                       "JMS2HTTPBridge timeout before reading complete "
                           + "message from socket. Bytes read="
  -                        + bytesRead);
  -                break;
  +                        + bytesRead;
  +                System.err.println(errText);
  +                throw new WSIFException(errText);
               }
   
               if (veryVerbose)
  @@ -1055,17 +1077,14 @@
                           + " bytesRead="
                           + bytesRead);
   
  -//            byte[] tmp = new byte[avail];
  -//            inp.read(tmp);
  -//            for (int i=0; i<avail; i++) {
  -//                   buff[bytesRead+i] = tmp[i];
  -//            }
  -            
  +            if (cl == 0)
  +                buff = new byte[avail];
               inp.read(buff, bytesRead, avail);
               bytesRead += avail;
           }
  +        while (bytesRead < cl);
           String sBuff = new String(buff);
  -        
  +
           if (verbose)
               System.out.println(
                   "JMS2HTTPBridge sendJmsReply len="
  @@ -1089,7 +1108,8 @@
                   if (props.containsKey(prop))
                       kept.put(prop, props.get(prop));
               } catch (Exception e) {
  -                System.err.println("JMS2HTTPBridge properties caught " + e);
  +             Trc.ignoredException(e);
  +                e.printStackTrace();
               }
           }
   
  @@ -1149,23 +1169,30 @@
                   }
               } catch (JMSException e) {
                   Trc.ignoredException(e);
  +                e.printStackTrace();
               }
           }
           Trc.exit();
       }
   
  -    private URL getServiceURL(Message m) {
  +    private String getServiceURL(Message m) {
           Trc.entry(this, m);
  -        URL serviceURL = null;
  +        String url = null;
           try {
  -            String s = m.getStringProperty("ServiceURL");
  -            serviceURL = new URL(s);
  +            if (m.propertyExists("WSIFServiceURL")) {
  +                url = m.getStringProperty("WSIFServiceURL");
  +                if (verbose)
  +                    System.out.println("JMS2HTTPBridge WSIFServiceURL=" + url);
  +            }
           } catch (Exception e) {
               Trc.ignoredException(e);
  -            serviceURL = httpURL;
  +            // Quietly ignore this as we default to httpURL
           }
  -        Trc.exit(serviceURL);
  -        return serviceURL;
  +
  +        if (url == null)
  +            url = httpURL;
  +        Trc.exit(url);
  +        return url;
       }
   
   }
  
  
  


Reply via email to