You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-dev@ws.apache.org by Bruno Harbulot <Br...@manchester.ac.uk> on 2006/04/13 16:37:35 UTC

Re: Query properties via HTTP GET

Sal Campana wrote:
> Bruno Harbulot wrote:
> 
>> Hello,
>>
>>
>> I've been using WSRF::Lite (in perl) for a while, and there's a 
>> feature that I find quite useful for debugging: it's possible to get 
>> all the properties by pointing a web browser (or wget, etc.) to the 
>> EPR address (WSRF::Lite include the resource identifier in the EPR 
>> address).
>>
>>
>> In effect, it gives the same result as the content of the response to 
>> a query like this:
>>
>> <wsrp:QueryResourceProperties 
>> xmlns:wsrp="http://docs.oasis-open.org/wsrf/2004/06/wsrf-WS-ResourceProperties-1.2-draft-01.xsd"> 
>>
>> <wsrp:QueryExpression 
>> Dialect="http://www.w3.org/TR/1999/REC-xpath-19991116">*</wsrp:QueryExpression> 
>>
>> </wsrp:QueryResourceProperties>
>>
>>
>>
>> Is there a way to achieve something similar with Apache WSRF? For 
>> example by querying something like this:
>> http://localhost:8080/wsrf/services/filesystem?ref=/dev/vg00/lvol1
>>
>> How hard would it be to implement? (Additionally, how hard would it be 
>> to adapt Apache WSRF so that it can use EPRs without resource 
>> identifier but with just an address of that form?)
>>
>>
>> Regards,
>>
>>
>> Bruno.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: wsrf-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: wsrf-user-help@ws.apache.org
>>
>>
> Well anything is possible....
> 
> But not all services implement Query, so then it becomes an issue of 
> does the service implement query?  if so do this, else do that....
> 
> If you'd like to take a crack at implementing it, then I'm all for it ;-)
> 

(Changing to wsrf-dev, as it seems more appropriate.)



Hi Sal,


I've just implemented these two features.

First, I've changed AbstractResourceHome.extractResourceIdentifier so 
that it can extract the resource identifier from the parameter in the 
query (the parameter being ResourceIdentifier=TheID).

This seems to work fine (at least with the filesystem example).
For example, it's possible to use this kind of requests:

ant -f soapclient.xml 
-Durl="http://localhost:8080/wsrf/services/filesystem?ResourceIdentifier=/dev/vg00/lvol1" 
-Dxml=requests/QueryResourceProperties_allProps.soap

(In this case, the ResourceIdentifier must be removed from the SOAP 
header in the message, otherwise it generates a fault because there are 
too many identifiers.)

This is obviously still working with HTTP POST and is independent from 
the first feature I was after. I think it's quite useful, nevertheless. 
(I prefer my EPRs in just an address sometimes. It's probably a matter 
of taste).



Secondly, I've implemented the first feature I was looking for (and it 
relies on what I implemented first): an HTTP GET corresponding to 
QueryResourceProperties_allProps.

I've written an AbstractQueryStringHandler for this. Again, it seems to 
work fine, at least from a web browser, which is what I wanted in the 
first place (I indent to use this mostly for debugging, as otherwise 
POST would be fine).

When it works (i.e. service that is in WSRF and ResourceIdentifier that 
corresponds to an existing resource), it gives the SOAP response that 
would have been obtained with a POST and an HTTP 200 response code.
When it doesn't (service that does not implement this operation or wrong 
resource identifier), it gives a SOAP fault and an HTTP 500 response 
code. I think this is consistent.



This works with the example from the tutorial, but I might have made 
some mistakes. Any comments welcome.
Please let me know if you think this is relevant for the Apache WSRF 
project, and if you'd like to include it in the main distribution.


Cheers,

Bruno.




I've attached the file for the new AbstractQueryStringHandler.
(I wasn't sure what @authors to put and in which order to put them... 
I've used pieces of code from Axis as well.)

server-config.wsdd must be modified to include this next to the other 
"qs" parameters:
   <parameter name="qs:ResourceIdentifier" 
value="org.apache.ws.resource.impl.QSResourceQueryHandler"/>
   <parameter name="qs.ResourceIdentifier" 
value="org.apache.ws.resource.impl.QSResourceQueryHandler"/>




Here is the code for AbstractResourceHome.extractResourceIdentifier to 
extract the resource ID from the URL:




    public Object extractResourceIdentifier( ResourceContext context )
    {
       if ( getResourceIdentifierReferenceParameterName(  ) == null )
       {
          return null;
       }

       try
       {
		String resourceIdentifierStr = null ;
		HttpServletRequest servletRequest = (HttpServletRequest) 
context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST) ;
		resourceIdentifierStr = 
servletRequest.getParameter("ResourceIdentifier") ; 	
     	
          SOAPHeader soapHeader          = context.getSOAPMessage( 
).getSOAPHeader(  );
          Iterator   resourceIdElemsIter =
             soapHeader.getChildElements( NameUtils.toName( 
getResourceIdentifierReferenceParameterQName(  ) ) );
          if (resourceIdentifierStr == null) {
	         if ( !resourceIdElemsIter.hasNext(  ) )
	         {
	            throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
	                                      "The expected resource identifier 
reference parameter named "
	                                      + 
getResourceIdentifierReferenceParameterName(  )
	                                      + " was not found in the SOAP 
header." );
	         }

	         SOAPHeaderElement resourceIdElem = (SOAPHeaderElement) 
resourceIdElemsIter.next(  );
	         resourceIdentifierStr = resourceIdElem.getValue() ;
          }
          if ( resourceIdElemsIter.hasNext(  ) )
          {
             throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
                                       "More than one resource 
identifier reference parameter named "
                                       + 
getResourceIdentifierReferenceParameterName(  )
                                       + " was found in the SOAP header. 
Exactly one is expected." );
          }

          return resourceIdentifierStr ;
       }
       catch (ClassCastException e) {
     	  throw new JAXRPCException(e) ;
       }
       catch ( SOAPException soape )
       {
          throw new JAXRPCException( soape );
       }
    }



Re: Query properties via HTTP GET

Posted by Bruno Harbulot <Br...@manchester.ac.uk>.
Bruno Harbulot wrote:
> 
> 
> ...
> 
> 
> This works with the example from the tutorial, but I might have made 
> some mistakes. Any comments welcome.

Sorry, the file QSResourceQueryHandler.java I sent was incorrect. Adding 
a space before 'Dialect' (within the string) at line 59 should make it work.


Bruno.