View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.registry.local;
17  
18  import java.util.TreeSet;
19  
20  import org.apache.juddi.IRegistry;
21  import org.apache.juddi.error.FatalErrorException;
22  import org.apache.juddi.error.RegistryException;
23  import org.apache.juddi.error.UnsupportedException;
24  import org.w3c.dom.Element;
25  import org.w3c.dom.Node;
26  
27  /***
28   * @author Kurt Stam (kurt.stam@redhat.com)
29   */
30  public class InquiryService
31  {
32  //	 collection of valid operations
33  	  private TreeSet operations = null;
34  	  
35    public InquiryService() {
36  		super();
37  		operations = new TreeSet();
38  	  	operations.add("find_business");
39  	  	operations.add("find_service");
40  	  	operations.add("find_binding");
41  	  	operations.add("find_tmodel");
42  	  	operations.add("find_relatedbusinesses");
43  	  	operations.add("get_businessdetail");
44  	  	operations.add("get_businessdetailext");
45  	  	operations.add("get_servicedetail");
46  	  	operations.add("get_bindingdetail");
47  	  	operations.add("get_tmodeldetail");
48  	}
49  
50    //Verify that the appropriate endpoint was targeted for
51    // this service request.  The validateRequest method will
52    // throw an UnsupportedException if anything's amiss.
53    public void validateRequest(String operation,String version,Element uddiReq)
54  		throws RegistryException
55  	{
56      // If the value 
57    	// specified is not "2.0" then throw an exception (this 
58    	// value must be specified for all UDDI requests and 
59    	// only version 2.0 UDDI requests are supported by 
60    	// this endpoint).
61  
62    	if (version == null)
63        throw new FatalErrorException("A UDDI generic attribute " +
64          "value was not found for UDDI request: "+operation+" (The " +
65          "'generic' attribute must be present)");
66      else if (!version.equals(IRegistry.UDDI_V2_GENERIC))
67        throw new UnsupportedException("Only UDDI v2 " +
68          "requests are currently supported. The generic attribute value " +
69          "received was: "+version);
70  
71      if ((operation == null) || (operation.trim().length() == 0))
72        throw new FatalErrorException("The UDDI service operation " +
73          "could not be identified.");
74      else if (!operations.contains(operation.toLowerCase()))
75      	throw new UnsupportedException("The operation "+operation+" is not " +
76      			"supported by the UDDI version 2 Inquiry API.");
77  	}
78    
79    public Node inquire(Element uddiReq) throws Exception{
80        
81        //new RequestHandler on it's own thread
82        RequestHandler requestHandler = new RequestHandler();
83        requestHandler.setUddiReq(uddiReq);
84        String operation = requestHandler.getOperation(uddiReq);
85        String version   = requestHandler.getVersion(uddiReq,operation);
86        validateRequest(operation, version, uddiReq);
87        Thread thread = new Thread(requestHandler, "WorkThread");
88        thread.start();
89        thread.join();
90        if (requestHandler.getException()!=null) {
91            throw new Exception(requestHandler.getException());
92        }
93  	  return requestHandler.getResponse();
94    }
95    
96  }