From: <st...@us...> - 2006-12-15 14:38:54
|
Revision: 3719 http://svn.sourceforge.net/smartfrog/?rev=3719&view=rev Author: steve_l Date: 2006-12-15 06:38:53 -0800 (Fri, 15 Dec 2006) Log Message: ----------- handle client only deployments; new interop test Modified Paths: -------------- trunk/projects/alpine/prototype/M32/ivy.xml trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/core/MessageContext.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Session.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Transmission.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/http/HttpTransmitter.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ParserHelper.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ResourceLoader.java Added Paths: ----------- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/FileTransmission.java trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/ResourceTransmission.java Modified: trunk/projects/alpine/prototype/M32/ivy.xml =================================================================== --- trunk/projects/alpine/prototype/M32/ivy.xml 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/ivy.xml 2006-12-15 14:38:53 UTC (rev 3719) @@ -17,11 +17,7 @@ description="artifacts needed to build the application"/> <conf name="compile" visibility="private" description="artifacts needed to compile the application"/> - <conf name="unittest" extends="compile" - description="the classpath needed to run unittests"/> - <conf name="systemtest" extends="unittest,optional" - description="the classpath needed to run systemtests"/> - <conf name="test" extends="systemtest" + <conf name="test" extends="compile,master,optional" description="the classpath needed to run tests"/> <conf name="master" description="contains the artifact but no dependencies"/> <conf name="redist" description="redistributals excluding smartfrog artifacts"/> @@ -29,6 +25,8 @@ extends="redist"/> <conf name="optional" description="optional extras"/> <conf name="all" description="everything" extends="default,optional"/> + <conf name="daemon" visibility="private" extends="master,runtime" + description="the classpath needed to run smartfrog daemons"/> </configurations> <publications> @@ -42,21 +40,25 @@ rev="latest.integration" conf="build->default"/> <dependency org="org.smartfrog" - name="smartfrog" + name="smartfrog" changing="true" rev="latest.integration" - conf="compile->master;runtime->default"/> + conf="compile->master;runtime->default"/> + <dependency org="org.smartfrog" + name="sf-www" + changing="true" + rev="latest.integration" + conf="compile,runtime->default;redist->master"/> <dependency org="xom" name="xom" rev="${xom.version}" conf="compile->master;redist->master"/> - <!-- here jaxen is included, but none of its dependencies--> <dependency org="org.smartfrog" name="sf-jetty" changing="true" rev="latest.integration" - conf="systemtest->default"/> + conf="test,runtime->default;redist->master"/> <dependency org="javax.servlet" name="servlet-api" rev="${servletapi.version}" @@ -86,5 +88,20 @@ name="xalan" rev="${xalan.version}" conf="optional->default"/> + + <!--test--> + + <dependency org="junit" + name="junit" + rev="${junit.version}" + conf="test->default"/> + + <dependency org="httpunit" + name="httpunit" + rev="${httpunit.version}" + conf="test->default"> + <exclude org="rhino"/> + <exclude org="xerces"/> + </dependency> </dependencies> </ivy-module> \ No newline at end of file Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/core/MessageContext.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/core/MessageContext.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/core/MessageContext.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -131,6 +131,11 @@ this.processed = processed; } + + public ResourceLoader getLoader() { + return loader; + } + /** * Create a new request and return it, as well as saving * it in the <code>request</code> attribute. Added: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/FileTransmission.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/FileTransmission.java (rev 0) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/FileTransmission.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -0,0 +1,74 @@ +/** (C) Copyright 2006 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.projects.alpine.transport; + +import org.smartfrog.projects.alpine.core.MessageContext; +import org.smartfrog.projects.alpine.transport.http.HttpTransmitter; + +import java.io.File; + +/** + * Transmit an XML file to a destination, using the soap version and URL of the current + * message context. + * The file is not deleted afterwards. + * created 11-Dec-2006 14:18:41 + */ + +public class FileTransmission extends Transmission { + + private File file; + + + public FileTransmission(MessageContext context) { + super(context); + } + + /** + * Transmit a file + * @param context message context + * @param file file to send + */ + public FileTransmission(MessageContext context, File file) { + super(context); + this.file = file; + } + + + public File getFile() { + return file; + } + + public void setFile(File file) { + this.file = file; + } + + /** + * triggers the actuall transmission + * + * @return computed result + * @throws Exception if unable to compute a result + * @throws org.smartfrog.projects.alpine.faults.AlpineRuntimeException in case of trouble. + */ + public Object call() throws Exception { + HttpTransmitter transmitter = new HttpTransmitter(this); + transmitter.transmitPayload(file); + return null; + } +} Added: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/ResourceTransmission.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/ResourceTransmission.java (rev 0) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/ResourceTransmission.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -0,0 +1,61 @@ +/** (C) Copyright 2006 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.projects.alpine.transport; + +import org.smartfrog.projects.alpine.core.MessageContext; + +import java.io.*; + +/** + * created 11-Dec-2006 14:28:41 + */ + +public class ResourceTransmission extends FileTransmission { + + private String resource; + + public ResourceTransmission(MessageContext context, String resource) throws IOException { + super(context); + this.resource=resource; + + InputStream ins= context.getLoader().loadResource(resource); + File outputFile = null; + OutputStream outToFile = null; + outputFile = File.createTempFile("alpine", ".xml"); + outToFile=new FileOutputStream(outputFile); + int b; + while((b=ins.read())>=0) { + outToFile.write(b); + } + outToFile.flush(); + outToFile.close(); + ins.close(); + setFile(outputFile); + } + + + /** + * Returns a string representation of the object. + * @return a string representation of the object. + */ + public String toString() { + return "Transmitting resource "+resource+ " as "+getFile().getPath(); + } +} Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Session.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Session.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Session.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -148,8 +148,19 @@ */ public Transmission createTransmission(AlpineEPR destination, String action) { + MessageContext messageContext = createMessageContextWithRequest(destination, action); + Transmission tx = new Transmission(messageContext); + return tx; + } + + /** + * Create a mesae context with a request pointing at the far end + * @param destination url + * @param action soap Action + * @return the message context wit the the stub request put together + */ + public MessageContext createMessageContextWithRequest(AlpineEPR destination, String action) { MessageContext messageContext = createNewMessageContext(); - Transmission tx = new Transmission(messageContext); MessageDocument request = messageContext.createRequest(); AddressDetails addressing = new AddressDetails(address); addressing.setTo(destination); @@ -158,10 +169,10 @@ messageIDSource.addNewID(addressing); } request.setAddressDetails(addressing); - return tx; + return messageContext; } - protected MessageContext createNewMessageContext() { + public MessageContext createNewMessageContext() { return new MessageContext(role, validating); } Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Transmission.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Transmission.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/Transmission.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -136,6 +136,7 @@ * @throws AlpineRuntimeException which contains anything else translated or nested * @throws org.smartfrog.projects.alpine.faults.TimeoutException * if there is a timeout + * @return the response */ public MessageDocument blockForResult(long timeout) { try { @@ -176,7 +177,7 @@ /** * Add the request and response messages to the fault as XML fragments. Good for diagnostics. * - * @param fault + * @param fault the fault that is being raised */ public void addMessagesToFault(AlpineRuntimeException fault) { if (getRequest() != null) { Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/http/HttpTransmitter.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/http/HttpTransmitter.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/transport/http/HttpTransmitter.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -107,136 +107,172 @@ } } + + /** + * Save a request to a file. This file should be deleted afterwards + * + * @return the file containing the request + * @throws IOException if the temp file could not be saved + */ + protected File saveRequestToFile() throws IOException { + File outputFile = null; + OutputStream outToFile = null; + try { + outputFile = File.createTempFile("alpine", ".xml"); + outToFile = new BufferedOutputStream(new FileOutputStream(outputFile)); + Serializer serializer = new Serializer(outToFile); + serializer.write(request); + serializer.flush(); + outToFile.flush(); + outToFile.close(); + } catch(IOException ioe) { + //clean up and rethrow on failure + if (outToFile != null) { + try { + outToFile.close(); + } catch (IOException e) { + //swallow + } + } + //delete the file + outputFile.delete(); + //rethrow + throw ioe; + } + return outputFile; + } + + /** + * Save the current request to a file and then transmit it. + * @throws org.smartfrog.projects.alpine.faults.AlpineRuntimeException in case of trouble. + */ public void transmit() { + File outputFile = null; + try { + outputFile = saveRequestToFile(); + } catch (IOException ioe) { + //error before we even connect to the server + throw new HttpTransportFault(ERROR_DURING_PREPARATION, ioe); + } + try { + transmitPayload(outputFile); + } finally { + if (outputFile != null) { + outputFile.delete(); + } + } + } + + /** + * Transmit a file containing an XML message. + * the file is not deleted afterwards, so the transport can be used to push up existing messages + * @param outputFile file to upload. + * @throws org.smartfrog.projects.alpine.faults.AlpineRuntimeException in case of trouble. + */ + public void transmitPayload(File outputFile) { String destination = wsa.getDestination(); log.debug("Posting to " + destination); PostMethod method = new ProgressingPostMethod(destination); //REVISIT. Its not clear that this method should stay around. //method.setFollowRedirects(true); - method.addRequestHeader("SOAPAction",""); - method.addRequestHeader("User-Agent",HttpConstants.ALPINE_VERSION); + method.addRequestHeader("SOAPAction", ""); + method.addRequestHeader("User-Agent", HttpConstants.ALPINE_VERSION); //fill in the details //1. get the message into a byte array //2. add it //3. TODO: add files? - File outputFile = null; - OutputStream outToFile = null; RequestEntity re = null; + String contentType = HttpConstants.CONTENT_TYPE_TEXT_XML; + String ctxContentType = (String) tx.getContext().get(ContextConstants.ATTR_SOAP_CONTENT_TYPE); + if (ctxContentType != null) { + contentType = ctxContentType; + } + re = new ProgressiveFileUploadRequestEntity(tx, request, outputFile, + contentType, + tx.getUploadFeedback(), BLOCKSIZE); + method.setRequestEntity(re); + InputStream responseStream = null; try { - try { - try { - outputFile = File.createTempFile("alpine", ".post"); - outToFile = new BufferedOutputStream(new FileOutputStream(outputFile)); - Serializer serializer = new Serializer(outToFile); - serializer.write(request); - serializer.flush(); - outToFile.flush(); - String contentType = HttpConstants.CONTENT_TYPE_TEXT_XML; - String ctxContentType = (String) tx.getContext().get(ContextConstants.ATTR_SOAP_CONTENT_TYPE); - if(ctxContentType!=null) { - contentType=ctxContentType; - } - re = new ProgressiveFileUploadRequestEntity(tx, request, outputFile, - contentType, - tx.getUploadFeedback(), BLOCKSIZE); - method.setRequestEntity(re); - } finally { - if (outToFile != null) { - outToFile.close(); - } - } - } catch (IOException ioe) { - //error before we even connect to the server - throw new HttpTransportFault(ERROR_DURING_PREPARATION, ioe); + int statusCode = httpclient.executeMethod(method); + final boolean requestFailed = statusCode != HttpStatus.SC_OK; + boolean responseIsXml; + //get the content type and drop anything following a semicolon + //this can be null on an empty response + contentType = getResponseContentType(method); + if(contentType!=null) { + contentType = HttpBinder.extractBaseContentType(contentType); + responseIsXml = HttpBinder.isValidSoapContentType(contentType); + } else { + responseIsXml=false; + } + if (requestFailed && + (!responseIsXml || statusCode != HttpStatus.SC_INTERNAL_SERVER_ERROR)) { + //TODO: treat 500+text/xml response specially, as it is probably a SOAPFault + log.error("Method failed: " + method.getStatusLine()); + throw new HttpTransportFault(destination, method); } - InputStream responseStream = null; - try { - int statusCode = httpclient.executeMethod(method); - final boolean requestFailed = statusCode != HttpStatus.SC_OK; - boolean responseIsXml; - //get the content type and drop anything following a semicolon - //this can be null on an empty response - String contentType = getResponseContentType(method); - if(contentType!=null) { - contentType = HttpBinder.extractBaseContentType(contentType); - responseIsXml = HttpBinder.isValidSoapContentType(contentType); - } else { - responseIsXml=false; - } - if (requestFailed && - (!responseIsXml || statusCode != HttpStatus.SC_INTERNAL_SERVER_ERROR)) { - //TODO: treat 500+text/xml response specially, as it is probably a SOAPFault - log.error("Method failed: " + method.getStatusLine()); - throw new HttpTransportFault(destination, method); - } - - //response is 200, but is it HTML? - if (!responseIsXml) { - HttpTransportFault fault = new HttpTransportFault(destination, method, - "Wrong content type: expected " - + HttpConstants.CONTENT_TYPE_TEXT_XML - + " or " - + HttpConstants.CONTENT_TYPE_SOAP_XML - + " but got [" - + contentType - + ']'); - throw fault; - } - //extract the response - responseStream = new CachingInputStream(method.getResponseBodyAsStream(),"utf8"); - //parse it - SoapMessageParser parser = tx.getContext().createParser(); - MessageDocument response; - if (!requestFailed) { + //response is 200, but is it HTML? + if (!responseIsXml) { + HttpTransportFault fault = new HttpTransportFault(destination, method, + "Wrong content type: expected " + + HttpConstants.CONTENT_TYPE_TEXT_XML + + " or " + + HttpConstants.CONTENT_TYPE_SOAP_XML + + " but got [" + + contentType + + ']'); + throw fault; + } + //extract the response + responseStream = new CachingInputStream(method.getResponseBodyAsStream(),"utf8"); + //parse it + SoapMessageParser parser = tx.getContext().createParser(); + MessageDocument response; + if (!requestFailed) { + response = parser.parseStream(responseStream); + //set our response + tx.getContext().setResponse(response); + } else { + // if is a fault, turn it into an exception. + try { response = parser.parseStream(responseStream); //set our response tx.getContext().setResponse(response); - } else { - // if is a fault, turn it into an exception. - try { - response = parser.parseStream(responseStream); - //set our response - tx.getContext().setResponse(response); - } catch (Exception e) { - //this is here to catch XML Responses that cannot be - //parsed, and to avoid the underlying problem 'remote server error' - //from being lost. - String text=responseStream.toString(); - SoapException ex = new SoapException( - "The remote endpoint returned an error,\n" - + "but the response could not be parsed\n" - + "and turned into a SOAPFault.\n" - +"XML:"+ text+ - "\nParse Error:"+e.toString(), - e, null); - ex.addAddressDetails(request); - throw ex; - } - SoapException ex = new SoapException(response); + } catch (Exception e) { + //this is here to catch XML Responses that cannot be + //parsed, and to avoid the underlying problem 'remote server error' + //from being lost. + String text=responseStream.toString(); + SoapException ex = new SoapException( + "The remote endpoint returned an error,\n" + + "but the response could not be parsed\n" + + "and turned into a SOAPFault.\n" + +"XML:"+ text+ + "\nParse Error:"+e.toString(), + e, null); + ex.addAddressDetails(request); throw ex; } - } catch (IOException ioe) { - throw new HttpTransportFault(destination, ioe); - } catch (SAXException e) { - throw new HttpTransportFault(destination, e); - } catch (ParsingException e) { - throw new HttpTransportFault(destination, e); - } finally { - if (responseStream != null) { - try { - responseStream.close(); - } catch (IOException e) { - //ignore this. - } - } - method.releaseConnection(); + SoapException ex = new SoapException(response); + throw ex; } + } catch (IOException ioe) { + throw new HttpTransportFault(destination, ioe); + } catch (SAXException e) { + throw new HttpTransportFault(destination, e); + } catch (ParsingException e) { + throw new HttpTransportFault(destination, e); } finally { - if (outputFile != null) { - outputFile.delete(); + if (responseStream != null) { + try { + responseStream.close(); + } catch (IOException e) { + //ignore this. + } } + method.releaseConnection(); } } Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ParserHelper.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ParserHelper.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ParserHelper.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -54,7 +54,7 @@ * @param disableDoctypes flag to disable doctypes * @param secureLoading flag for secure loading (disables entity expansion) * @return an appropriately configured XML reader - * @throws org.xml.sax.SAXException + * @throws org.xml.sax.SAXException if something went very wrong */ public static XMLReader createXmlParser(boolean validate, boolean disableDoctypes, @@ -93,9 +93,9 @@ } /** - * turn XSD support on + * turn XSD support on (xerces-specific) * - * @param xerces + * @param xerces the parser */ public static void enableXmlSchema(XMLReader xerces) { setFeature(xerces, @@ -113,7 +113,7 @@ * @throws org.xml.sax.SAXException if neither implementation coudl be loaded */ public static XMLReader createBaseXercesInstance() throws SAXException { - XMLReader xerces = null; + XMLReader xerces; try { xerces = XMLReaderFactory.createXMLReader(PARSER_XERCES); } catch (SAXException e) { @@ -135,9 +135,9 @@ boolean flag) { try { parser.setFeature(name, flag); - } catch (SAXNotRecognizedException e) { + } catch (SAXNotRecognizedException ignored) { log.debug("SAXNotRecognizedException setting " + name); - } catch (SAXNotSupportedException e) { + } catch (SAXNotSupportedException ignored) { log.debug("SAXNotSupportedException setting " + name); } } @@ -145,8 +145,8 @@ /** * use the JAXP APIs to locate and bind to a parser * - * @return - * @throws javax.xml.parsers.ParserConfigurationException + * @return a new instance (somehow) + * @throws javax.xml.parsers.ParserConfigurationException if it refuses to be * */ public static DOMImplementation loadDomImplementation() Modified: trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ResourceLoader.java =================================================================== --- trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ResourceLoader.java 2006-12-15 14:34:14 UTC (rev 3718) +++ trunk/projects/alpine/prototype/M32/src/java/org/smartfrog/projects/alpine/xmlutils/ResourceLoader.java 2006-12-15 14:38:53 UTC (rev 3719) @@ -77,8 +77,8 @@ /** * load a resource. * - * @param resourceName - * @return + * @param resourceName the name of the resource + * @return the resource as an input stream * @throws java.io.IOException if a resource is missing */ public InputStream loadResource(String resourceName) throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |