source: MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/DCRProxyAction.java @ 519

Last change on this file since 519 was 519, checked in by vronk, 14 years ago

activated DCRProxy

File size: 1.6 KB
Line 
1package eu.clarin.cmdi.mdservice.action;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.net.URL;
6import java.net.URLConnection;
7
8/**
9 * Acts as a Struts 2 controller
10 * serves the requests regarding DataCategories
11 * it passes them further (Proxy) to the Data Category Registry.
12 *   
13 * @author vronk
14 *
15 */
16
17public class DCRProxyAction extends GenericProxyAction {
18
19        private static final long serialVersionUID = 1L;
20       
21        private String proxy_key = "dcregistry";
22       
23        @Override
24        public String getProxyKey() {
25                return proxy_key;
26        }
27       
28         
29        public String getFullFormat() {
30                        return "dc2" + getFormat();             
31        }
32       
33       
34        /**
35         * uses base_url and (optionally) id to form a url
36         * no id => ?list all datacategories?
37         * @return the URL to data category xml format
38         * @throws Exception
39         */
40        public URL getTargetRequest() throws IOException {
41
42                URL targetURL = null;
43                if (getQ()==null || getQ().equals("")) {
44                //      Admin.notifyUser("ERROR DCRProxy.targetURL: missing param Q!");
45                        targetURL =new URL( getBaseURL(), getActionkey());
46                } else {
47                        targetURL =new URL( getBaseURL(), getActionkey() + "/" + getQ());
48                }
49                Admin.notifyUser("DCRProxy.targetURL:" + targetURL);
50
51            return targetURL;
52        }
53       
54        public InputStream getSourceStream() throws IOException {
55       
56                /* need to set Request-Property: Accept to xml
57                 * for to get dcif/xml from DCR-server by means of content negotiation */
58                URLConnection urlConnection = getTargetRequest().openConnection();
59        urlConnection.setRequestProperty("Accept", "application/dcif+xml");
60   
61        return urlConnection.getInputStream();
62   
63        }       
64}
Note: See TracBrowser for help on using the repository browser.