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@jboss.com)
29   */
30  public class PublishService
31  {
32    // collection of valid operations
33    private TreeSet operations = null;
34  
35    public PublishService() {
36  	super();
37  	operations = new TreeSet();
38    	operations.add("get_authtoken");
39    	operations.add("get_registeredinfo");
40    	operations.add("discard_authtoken");
41    	operations.add("save_business");
42    	operations.add("save_service");
43    	operations.add("save_binding");
44    	operations.add("save_tmodel");
45    	operations.add("delete_business");
46    	operations.add("delete_service");
47    	operations.add("delete_binding");
48    	operations.add("delete_tmodel");
49    	operations.add("add_publisherassertions");
50    	operations.add("set_publisherassertions");
51    	operations.add("get_publisherassertions");
52    	operations.add("delete_publisherassertions");
53    	operations.add("get_assertionstatusreport");
54  }
55  
56  
57    public void validateRequest(String operation,String version,Element uddiReq)
58  		throws RegistryException
59  	{
60      // If the value 
61    	// specified is not "2.0" then throw an exception (this 
62    	// value must be specified for all UDDI requests and 
63    	// only version 2.0 UDDI requests are supported by 
64    	// this endpoint).
65  
66    	if (version == null)
67        throw new FatalErrorException("A UDDI generic attribute " +
68          "value was not found for UDDI request: "+operation+" (The " +
69          "'generic' attribute must be present)");
70      else if (!version.equals(IRegistry.UDDI_V2_GENERIC))
71        throw new UnsupportedException("Only UDDI v2 " +
72          "requests are currently supported. The generic attribute value " +
73          "received was: "+version);
74  
75      if ((operation == null) || (operation.trim().length() == 0))
76        throw new FatalErrorException("The UDDI service operation " +
77          "could not be identified.");
78      else if (!operations.contains(operation.toLowerCase()))
79      	throw new UnsupportedException("The operation "+operation+" is not " +
80      			"supported by the UDDI version 2 Publish API.");
81  	}
82    
83    public Node publish(Element uddiReq) throws Exception
84    {
85        //new RequestHandler on it's own thread
86        RequestHandler requestHandler = new RequestHandler();
87        requestHandler.setUddiReq(uddiReq);
88        String operation = requestHandler.getOperation(uddiReq);
89        String version   = requestHandler.getVersion(uddiReq, operation);
90        validateRequest(operation, version, uddiReq);
91        Thread thread = new Thread(requestHandler, "WorkThread");
92        thread.start();
93        thread.join();
94        if (requestHandler.getException()!=null) {
95            throw new Exception(requestHandler.getException());
96        }
97        return requestHandler.getResponse();
98    }
99  }