Based on some help from Erik Abele on infrastructure I was able to
sort this one out. Erik put together a test case in C to validate
that the Apache server was doing its thing with respect to content
negotiation - which left me with the problem of resolving the issues
with the Java approach.
Detailed below are the issues and solutions.
Stephen McConnell wrote:
Have started some experimentation with content negotiation and I think I need a mime type addition to server running www.apache.org.
I have setup the following test content:
http://www.apache.org/~mcconnell/
This contains a single jar file and a test file containing metadata about the jar file.
example.jar example.jar.meta
I've also put together a little test case that creates a url to the artifact http://www.apache.org/~mcconnell/example and then sets the "accept" request parameter to "text/x-meta". Presumably the mime type used here ("text/x-meta") needs to be declared on the Apache server with a mapping to the ".meta" extension.
Does anyone know if this is something I can configure
in the enclosing directory - or do I need post a request to
infrastructure?
You can declare MIME type additions by putting in place a .htaccess file somewhere in the filesystem. For the above example I declared a "text/x-meta" MIME type using a .htaccess file containing the following:
AddType text/x-meta .meta
Here is a fragment of the relevant java source:
URL url = new URL( "http://www.apache.org/~mcconnell/test/example" );
URLConnection connection = url.openConnection();
connection.setRequestProperty( "accept", "text/x-meta" );
The above line contains a bug.
To operate corectly the request property key should be "Accept" (note that the value is case sensitive).
getLogger().info( "input" ); InputStream input = (InputStream) connection.getContent(); Properties properties = new Properties(); properties.load( input );
Without the mime mapping the above code will result in the stuffing
of the jar file into the properties file which is not exactly
what we want.
Using the following URL:
http://www.apache.org/~mcconnell/test/example
I can pull down the meta info using the attached testcase resulting in:
[INFO ] (playground.demo): name: avalon-activation-impl [INFO ] (playground.demo): group: avalon-activation [INFO ] (playground.demo): version: 1.2.2-dev [INFO ] (playground.demo): signature: 20031111.020554
Example source is attached.
Cheers, Steve.
--
Stephen J. McConnell mailto:[EMAIL PROTECTED]
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.playground;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
import java.util.Properties;
import java.util.Enumeration;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Executable;
import org.apache.avalon.framework.activity.Initializable;
/**
* A test component that is initializable, executable and disposable
* and implements the Hello service.
*
* @avalon.component version="1.0" name="hello" lifestyle="singleton"
*/
public class TestComponent extends AbstractLogEnabled
implements Executable
{
private boolean m_started = false;
public void execute() throws Exception
{
URL url = new URL( "http://www.apache.org/~mcconnell/test/example" );
URLConnection connection = url.openConnection();
connection.setRequestProperty( "Accept", "text/x-meta" );
try
{
InputStream input = (InputStream) connection.getContent();
Properties properties = new Properties();
properties.load( input );
if( properties.getProperty( "avalon.artifact.name" ) != null )
{
final String name = properties.getProperty( "avalon.artifact.name" );
final String group = properties.getProperty( "avalon.artifact.group" );
final String version = properties.getProperty( "avalon.artifact.version" );
final String signature = properties.getProperty( "avalon.artifact.signature" );
getLogger().info( "name: " + name );
getLogger().info( "group: " + group );
getLogger().info( "version: " + version );
getLogger().info( "signature: " + signature );
}
else
{
getLogger().info( "failed" );
}
}
catch( Throwable e )
{
getLogger().info( "error: " + e );
}
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
