SF.net SVN: geonetwork:[4518] sandbox/3.0.x/geonetwork-web-ebrim/src/main/ java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java

1 message Options
Embed this post
Permalink
josegar74-2

SF.net SVN: geonetwork:[4518] sandbox/3.0.x/geonetwork-web-ebrim/src/main/ java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java

Reply Threaded More More options
Print post
Permalink
Revision: 4518
          http://geonetwork.svn.sourceforge.net/geonetwork/?rev=4518&view=rev
Author:   josegar74
Date:     2009-07-03 16:33:14 +0000 (Fri, 03 Jul 2009)

Log Message:
-----------
GetRepositoryItem return ows:Exception and changes to handleDescribeRecord

Modified Paths:
--------------
    sandbox/3.0.x/geonetwork-web-ebrim/src/main/java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java

Modified: sandbox/3.0.x/geonetwork-web-ebrim/src/main/java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java
===================================================================
--- sandbox/3.0.x/geonetwork-web-ebrim/src/main/java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java 2009-07-03 15:20:18 UTC (rev 4517)
+++ sandbox/3.0.x/geonetwork-web-ebrim/src/main/java/org/geonetwork/webservices/ebrim/csw202/CswEbrimGETService.java 2009-07-03 16:33:14 UTC (rev 4518)
@@ -48,98 +48,95 @@
 import org.springframework.web.context.WebApplicationContext;
 import org.springframework.web.context.support.WebApplicationContextUtils;
 
-/**
- *
+/**                      
  * @author heikki doeleman
- *
  */
 public class CswEbrimGETService extends HttpServlet {
 
- private static Logger log = Logger.getLogger(CswEbrimGETService.class);
-                                  
-
- /**
- *
- */
- private static final long serialVersionUID = -7530539986421781568L;
- public static final String REQUEST = "request";
- public static final String GETCAPABILITIES = "GetCapabilities";
-// public static final String SERVICE = "CSW-ebRIM";
- public static final String VERSION = "1.0.0";
- public static final String SECTIONS = "sections";
- public static final String SERVICE = "service";
- public static final String GETRECORDS = "GetRecords";
- public static final String GETRECORDBYID = "GetRecordById";
- public static final String GETREPOSITORYITEM = "GetRepositoryItem";
- public static final String RESULT_TYPE = "resultType";
- public static final String REQUEST_ID = "requestId";
- public static final String OUTPUT_FORMAT = "outputFormat";
- public static final String OUTPUT_SCHEMA = "outputSchema";
- public static final String START_POSITION = "startPosition";
- public static final String MAX_RECORDS = "maxRecords";
- public static final String DESCRIBERECORD = "DescribeRecord";
- public static final String TYPE_NAME_GET_RECORDS = "typeNames";
- public static final String TYPE_NAME_DESCRIBE_RECORD = "TypeName";
- public static final String NAMESPACE = "NAMESPACE";
- public static final String ELEMENT_SET_NAME = "ElementSetName";
- public static final String ELEMENT_NAME = "ElementName";
- public static final String CONSTRAINT_LANGUAGE = "CONSTRAINTLANGUAGE";
- public static final String CONSTRAINT = "Constraint";
- public static final String CQL_TEXT = "CQL_TEXT";
- public static final String FILTER = "FILTER";
- public static final String SORT_BY = "SortBy";
- public static final String ID = "Id";
-
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    private static Logger log = Logger.getLogger(CswEbrimGETService.class);
 
- String requestedOperation = RequestUtil.getParameter(request, REQUEST);
 
- if (requestedOperation.equalsIgnoreCase(GETCAPABILITIES)) {
- handleGetCapabilities(request, response);
- }
- if (requestedOperation.equalsIgnoreCase(GETRECORDS)) {
- handleGetRecords(request, response);
- }
- if (requestedOperation.equalsIgnoreCase(DESCRIBERECORD)) {
- handleDescribeRecord(request, response);
- }
- if (requestedOperation.equalsIgnoreCase(GETRECORDBYID)) {
- handleGetRecordById(request, response);
- }
- if (requestedOperation.equalsIgnoreCase(GETREPOSITORYITEM)) {
- handleGetRepositoryItem(request, response);
- }
- // unknown operation
- else {
- response.setStatus(404);
- }
- }
-
- private void handleGetRepositoryItem(HttpServletRequest request, HttpServletResponse response) throws ServletException {
- String id = RequestUtil.getParameter(request, ID);
- ServletContext servletContext = this.getServletConfig().getServletContext();
- WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
- try {
- GetRepositoryItemResponse getRepositoryItemResponse = csw202Service.getRepositoryItem(id);
- if(StringUtil.isEmpty(getRepositoryItemResponse.getResponse())) {
- log.debug("Did not find repository item for id: " + id);
- response.setStatus(404);
- }
- else {
- // set up JiBX marshalling context
- IBindingFactory bfact = BindingDirectory.getFactory(GetRepositoryItemResponse.class);
- IMarshallingContext marshallingContext = bfact.createMarshallingContext();
- // marshal to servlet response outputstream
- response.setContentType("text/xml");
- marshallingContext.setIndent(3);
+    /**
+     *
+     */
+    private static final long serialVersionUID = -7530539986421781568L;
+    public static final String REQUEST = "request";
+    public static final String GETCAPABILITIES = "GetCapabilities";
+    // public static final String SERVICE = "CSW-ebRIM";
+    public static final String VERSION = "1.0.0";
+    public static final String SECTIONS = "sections";
+    public static final String SERVICE = "service";
+    public static final String GETRECORDS = "GetRecords";
+    public static final String GETRECORDBYID = "GetRecordById";
+    public static final String GETREPOSITORYITEM = "GetRepositoryItem";
+    public static final String RESULT_TYPE = "resultType";
+    public static final String REQUEST_ID = "requestId";
+    public static final String OUTPUT_FORMAT = "outputFormat";
+    public static final String OUTPUT_SCHEMA = "outputSchema";
+    public static final String START_POSITION = "startPosition";
+    public static final String MAX_RECORDS = "maxRecords";
+    public static final String DESCRIBERECORD = "DescribeRecord";
+    public static final String TYPE_NAME_GET_RECORDS = "typeNames";
+    public static final String TYPE_NAME_DESCRIBE_RECORD = "TypeName";
+    public static final String NAMESPACE = "NAMESPACE";
+    public static final String ELEMENT_SET_NAME = "ElementSetName";
+    public static final String ELEMENT_NAME = "ElementName";
+    public static final String CONSTRAINT_LANGUAGE = "CONSTRAINTLANGUAGE";
+    public static final String CONSTRAINT = "Constraint";
+    public static final String CQL_TEXT = "CQL_TEXT";
+    public static final String FILTER = "FILTER";
+    public static final String SORT_BY = "SortBy";
+    public static final String ID = "Id";
 
+    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+
+        String requestedOperation = RequestUtil.getParameter(request, REQUEST);
+
+        if (requestedOperation.equalsIgnoreCase(GETCAPABILITIES)) {
+            handleGetCapabilities(request, response);
+        }
+        if (requestedOperation.equalsIgnoreCase(GETRECORDS)) {
+            handleGetRecords(request, response);
+        }
+        if (requestedOperation.equalsIgnoreCase(DESCRIBERECORD)) {
+            handleDescribeRecord(request, response);
+        }
+        if (requestedOperation.equalsIgnoreCase(GETRECORDBYID)) {
+            handleGetRecordById(request, response);
+        }
+        if (requestedOperation.equalsIgnoreCase(GETREPOSITORYITEM)) {
+            handleGetRepositoryItem(request, response);
+        }
+        // unknown operation
+        else {
+            response.setStatus(404);
+        }
+    }
+
+    private void handleGetRepositoryItem(HttpServletRequest request, HttpServletResponse response) throws ServletException {
+        String id = RequestUtil.getParameter(request, ID);
+        ServletContext servletContext = this.getServletConfig().getServletContext();
+        WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+        CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
+        try {
+            GetRepositoryItemResponse getRepositoryItemResponse = csw202Service.getRepositoryItem(id);
+            if (StringUtil.isEmpty(getRepositoryItemResponse.getResponse())) {
+                log.debug("Did not find repository item for id: " + id);
+                response.setStatus(404);
+            } else {
+                // set up JiBX marshalling context
+                IBindingFactory bfact = BindingDirectory.getFactory(GetRepositoryItemResponse.class);
+                IMarshallingContext marshallingContext = bfact.createMarshallingContext();
+                // marshal to servlet response outputstream
+                response.setContentType("text/xml");
+                marshallingContext.setIndent(3);
+
                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                 Writer out = new BufferedWriter(new OutputStreamWriter(outputStream));
                 marshallingContext.setOutput(out);
 
- marshallingContext.marshalDocument(getRepositoryItemResponse, "UTF-8", null);
-    // Process marshalling to remove GetRepositoryItemResponse and return only content
+                marshallingContext.marshalDocument(getRepositoryItemResponse, "UTF-8", null);
+                // Process marshalling to remove GetRepositoryItemResponse and return only content
                 String result = outputStream.toString();
                 result = result.replaceAll("<tns:GetRepositoryItemResponse [^>]*>", "");
                 result = result.replaceAll("</tns:GetRepositoryItemResponse>", "");
@@ -147,128 +144,132 @@
                 PrintWriter writer = response.getWriter();
                 writer.write(result);
             }
- }
- catch (CSW202ServiceException x) {
- throw new ServletException(x);
- }
- catch (JiBXException x) {
- throw new ServletException(x);
- }
- catch (IOException x) {
- throw new ServletException(x);
- }
- }
+        }
+        catch (CSW202ServiceException e) {
+            try {
+                outputError(e.getFaultMessage(), response);
+            } catch (Exception x) {
+                throw new ServletException(e);
+            }
+        }
+        catch (JiBXException e) {
+            throw new ServletException(e);
+        }
+        catch (IOException e) {
+            throw new ServletException(e);
+        }
+    }
 
- private void handleGetCapabilities(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- GetCapabilities getCapabilities = new GetCapabilities();
- //
- // service
- //
- // OGC 07-110r2: The value of the service parameter shall be the service type code
- // "CSW-ebRIM".
- String service = RequestUtil.getParameter(request, SERVICE);
-
- getCapabilities.setService(service);
- //
- // version
- //
- // OGC 07-110r2: The value of the version parameter shall be "1.0.0".
- AcceptVersions acceptVersions = new AcceptVersions();
- List<String> acceptVersionsList = new ArrayList<String>();
- acceptVersionsList.add(VERSION);
- acceptVersions.setVersion(acceptVersionsList);
- getCapabilities.setAcceptVersions(acceptVersions);
- //
- // sections
- //
- // OGC 07-110r2: The sections parameter may be used to request a subset of the complete
- // capabilities
- // document; the value is a comma-separated list of section names. The set of recognized
- // section
- // names shall be as specified in Table 7 of OGC 05-008 and Table 58 of OGC 07-006r1,
- // with the exception of "Contents".
- // Table 7 of OGC 05-008:
- // ServiceIdentification
- // ServiceProvider
- // OperationsMetadata
- // Contents
- // Table 58 of OGC 07-006r1:
- // Filter_Capabilities
- Sections sections = new Sections();
- String sectionsParameter = RequestUtil.getParameter(request, SECTIONS);
- if (StringUtil.isNotEmpty(sectionsParameter)) {
- String[] sectionsArray = sectionsParameter.split(",");
- if (sectionsArray != null && sectionsArray.length > 1) {
- List<String> sectionsList = Arrays.asList(sectionsArray);
- sections.setSection(sectionsList);
- getCapabilities.setSections(sections);
- }
- }
- //
- // updatesequence
- //
- // not supported, server must return latest version
- // getCapabilities.setUpdateSequence(updateSequence);
- //
- // acceptformats
- //
- // not supported, always use text/xml
- //
- AcceptFormats acceptFormats = new AcceptFormats();
- List<MimeType> outputFormat = new ArrayList<MimeType>();
- MimeType textXML = new MimeType();
- textXML.setValue("text/xml");
- outputFormat.add(textXML);
- acceptFormats.setOutputFormat(outputFormat);
- getCapabilities.setAcceptFormats(acceptFormats);
+    private void handleGetCapabilities(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        GetCapabilities getCapabilities = new GetCapabilities();
+        //
+        // service
+        //
+        // OGC 07-110r2: The value of the service parameter shall be the service type code
+        // "CSW-ebRIM".
+        String service = RequestUtil.getParameter(request, SERVICE);
 
- ServletContext servletContext = this.getServletConfig().getServletContext();
- WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
+        getCapabilities.setService(service);
+        //
+        // version
+        //
+        // OGC 07-110r2: The value of the version parameter shall be "1.0.0".
+        AcceptVersions acceptVersions = new AcceptVersions();
+        List<String> acceptVersionsList = new ArrayList<String>();
+        acceptVersionsList.add(VERSION);
+        acceptVersions.setVersion(acceptVersionsList);
+        getCapabilities.setAcceptVersions(acceptVersions);
+        //
+        // sections
+        //
+        // OGC 07-110r2: The sections parameter may be used to request a subset of the complete
+        // capabilities
+        // document; the value is a comma-separated list of section names. The set of recognized
+        // section
+        // names shall be as specified in Table 7 of OGC 05-008 and Table 58 of OGC 07-006r1,
+        // with the exception of "Contents".
+        // Table 7 of OGC 05-008:
+        // ServiceIdentification
+        // ServiceProvider
+        // OperationsMetadata
+        // Contents
+        // Table 58 of OGC 07-006r1:
+        // Filter_Capabilities
+        Sections sections = new Sections();
+        String sectionsParameter = RequestUtil.getParameter(request, SECTIONS);
+        if (StringUtil.isNotEmpty(sectionsParameter)) {
+            String[] sectionsArray = sectionsParameter.split(",");
+            if (sectionsArray != null && sectionsArray.length > 1) {
+                List<String> sectionsList = Arrays.asList(sectionsArray);
+                sections.setSection(sectionsList);
+                getCapabilities.setSections(sections);
+            }
+        }
+        //
+        // updatesequence
+        //
+        // not supported, server must return latest version
+        // getCapabilities.setUpdateSequence(updateSequence);
+        //
+        // acceptformats
+        //
+        // not supported, always use text/xml
+        //
+        AcceptFormats acceptFormats = new AcceptFormats();
+        List<MimeType> outputFormat = new ArrayList<MimeType>();
+        MimeType textXML = new MimeType();
+        textXML.setValue("text/xml");
+        outputFormat.add(textXML);
+        acceptFormats.setOutputFormat(outputFormat);
+        getCapabilities.setAcceptFormats(acceptFormats);
 
- try {
- Capabilities capabilities = csw202Service.getCapabilities(getCapabilities);
- // set up JiBX marshalling context
- IBindingFactory bfact = BindingDirectory.getFactory(Capabilities.class);
- IMarshallingContext marshallingContext = bfact.createMarshallingContext();
- // marshal to servlet response outputstream
- response.setContentType("text/xml");
-
-
- //Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
- marshallingContext.setIndent(3);
- marshallingContext.setOutput(response.getWriter());
- marshallingContext.marshalDocument(capabilities, "UTF-8", null);
- }
- catch (CSW202ServiceException x) {
- throw new ServletException(x);
- }
- catch (JiBXException x) {
- throw new ServletException(x);
- }
- }
+        ServletContext servletContext = this.getServletConfig().getServletContext();
+        WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+        CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
 
- /**
- * OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
- *
- * @param request
- * @param response
- * @throws ServletException
- * @throws IOException
- */
- private void handleGetRecords(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
- GetRecords getRecords = new GetRecords();
+        try {
+            Capabilities capabilities = csw202Service.getCapabilities(getCapabilities);
+            // set up JiBX marshalling context
+            IBindingFactory bfact = BindingDirectory.getFactory(Capabilities.class);
+            IMarshallingContext marshallingContext = bfact.createMarshallingContext();
+            // marshal to servlet response outputstream
+            response.setContentType("text/xml");
 
- //
- // namespace
- //
- // OGC 07-006r1: The NAMESPACE parameter is included in the KVP encoding to allow clients to bind any namespace
- // prefixes
- // that might be used for qualified names specified in other parameters.
- String namespaceParameter = RequestUtil.getParameter(request, NAMESPACE);
- if (!StringUtil.isEmpty(namespaceParameter)) {
+
+            //Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
+            marshallingContext.setIndent(3);
+            marshallingContext.setOutput(response.getWriter());
+            marshallingContext.marshalDocument(capabilities, "UTF-8", null);
+        }
+        catch (CSW202ServiceException x) {
+            throw new ServletException(x);
+        }
+        catch (JiBXException x) {
+            throw new ServletException(x);
+        }
+    }
+
+    /**
+     * OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
+     *
+     * @param request
+     * @param response
+     * @throws ServletException
+     * @throws IOException
+     */
+    private void handleGetRecords(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+            IOException {
+        GetRecords getRecords = new GetRecords();
+
+        //
+        // namespace
+        //
+        // OGC 07-006r1: The NAMESPACE parameter is included in the KVP encoding to allow clients to bind any namespace
+        // prefixes
+        // that might be used for qualified names specified in other parameters.
+        String namespaceParameter = RequestUtil.getParameter(request, NAMESPACE);
+        if (!StringUtil.isEmpty(namespaceParameter)) {
             String[] namespaces = namespaceParameter.split(",");
             List<String> resultNamespacesList = new ArrayList<String>();
             List<String> namespacesList = Arrays.asList(namespaces);
@@ -284,69 +285,69 @@
             }
             getRecords.setNamespace(resultNamespacesList);
         }
-        
- //
- // resultType
- //
- // OGC 07-006r1: CodeList with allowed values: "hits", "results" or "validate"
- String resultTypeParameter = RequestUtil.getParameter(request, RESULT_TYPE);
+
+        //
+        // resultType
+        //
+        // OGC 07-006r1: CodeList with allowed values: "hits", "results" or "validate"
+        String resultTypeParameter = RequestUtil.getParameter(request, RESULT_TYPE);
         if (!StringUtil.isEmpty(resultTypeParameter)) {
             ResultType resultType = ResultType.valueOf(resultTypeParameter);
             getRecords.setResultType(resultType);
         }
- //
- // requestId
- //
- // OGC 07-006r1: Include when client chooses to assign requestId
- String requestIDParameter = RequestUtil.getParameter(request, REQUEST_ID);
- getRecords.setRequestID(requestIDParameter);
- //
- // outputFormat
- //
- // OGC 07-006r1: Value is Mime type
- // The only value that is required to be supported is application/xml. Other supported
- // values may include
- // text/html and text/plain
- String outputFormatParameter = RequestUtil.getParameter(request, OUTPUT_FORMAT);
+        //
+        // requestId
+        //
+        // OGC 07-006r1: Include when client chooses to assign requestId
+        String requestIDParameter = RequestUtil.getParameter(request, REQUEST_ID);
+        getRecords.setRequestID(requestIDParameter);
+        //
+        // outputFormat
+        //
+        // OGC 07-006r1: Value is Mime type
+        // The only value that is required to be supported is application/xml. Other supported
+        // values may include
+        // text/html and text/plain
+        String outputFormatParameter = RequestUtil.getParameter(request, OUTPUT_FORMAT);
         getRecords.setOutputFormat(outputFormatParameter);
         //
- // outputSchema
- //
- // OGC 07-006r1: Any URI..
- String outputSchemaParameter = RequestUtil.getParameter(request, OUTPUT_SCHEMA);
+        // outputSchema
+        //
+        // OGC 07-006r1: Any URI..
+        String outputSchemaParameter = RequestUtil.getParameter(request, OUTPUT_SCHEMA);
         getRecords.setOutputSchema(outputSchemaParameter);
- //
- // startPosition
- //
- // OGC 07-006r1: Non-Zero Positive Integer. Default value is 1.
- Integer startposition = new Integer(1);
- String startPositionParameter = RequestUtil.getParameter(request, START_POSITION);
- if (startPositionParameter != null) {
- startposition = new Integer(startPositionParameter);
- }
- getRecords.setStartPosition(startposition);
- //
- // maxRecords
- //
- // OGC 07-006r1: Positive Integer. Default values is 10.
- Integer maxrecords = new Integer(10);
- String maxRecordsParameter = RequestUtil.getParameter(request, MAX_RECORDS);
- if (maxRecordsParameter != null) {
- maxrecords = new Integer(maxRecordsParameter);
- }
- getRecords.setMaxRecords(maxrecords);
+        //
+        // startPosition
+        //
+        // OGC 07-006r1: Non-Zero Positive Integer. Default value is 1.
+        Integer startposition = new Integer(1);
+        String startPositionParameter = RequestUtil.getParameter(request, START_POSITION);
+        if (startPositionParameter != null) {
+            startposition = new Integer(startPositionParameter);
+        }
+        getRecords.setStartPosition(startposition);
+        //
+        // maxRecords
+        //
+        // OGC 07-006r1: Positive Integer. Default values is 10.
+        Integer maxrecords = new Integer(10);
+        String maxRecordsParameter = RequestUtil.getParameter(request, MAX_RECORDS);
+        if (maxRecordsParameter != null) {
+            maxrecords = new Integer(maxRecordsParameter);
+        }
+        getRecords.setMaxRecords(maxrecords);
 
- //
- // Query parameters
- //
- Query query = new Query();
+        //
+        // Query parameters
+        //
+        Query query = new Query();
 
- //
- // typeNames
- //
- // OGC 07-006r1 : List of Character String, comma separated. Unordered List of object types
- // implicated in the query.
- String typeNamesParameter = RequestUtil.getParameter(request, TYPE_NAME_GET_RECORDS);
+        //
+        // typeNames
+        //
+        // OGC 07-006r1 : List of Character String, comma separated. Unordered List of object types
+        // implicated in the query.
+        String typeNamesParameter = RequestUtil.getParameter(request, TYPE_NAME_GET_RECORDS);
         if (!StringUtil.isEmpty(typeNamesParameter)) {
             String[] typeNames = typeNamesParameter.split(",");
             List<String> typeNamesList = Arrays.asList(typeNames);
@@ -359,44 +360,44 @@
             query.setTypeNames(qtypeNamesList);
         }
 
- //
- // elementSetName
- //
- // OGC 07-006r1 : List of Character String. Zero or one (Mutually exclusive with
- // ElementName).
- String elementSetNameParameter = RequestUtil.getParameter(request, ELEMENT_SET_NAME);
-         if (!StringUtil.isEmpty(elementSetNameParameter)) {
+        //
+        // elementSetName
+        //
+        // OGC 07-006r1 : List of Character String. Zero or one (Mutually exclusive with
+        // ElementName).
+        String elementSetNameParameter = RequestUtil.getParameter(request, ELEMENT_SET_NAME);
+        if (!StringUtil.isEmpty(elementSetNameParameter)) {
             ElementSetName elementSetName = new ElementSetName();
             elementSetName.setElementSet(ElementSet.valueOf(elementSetNameParameter));
             query.setElementSetName(elementSetName);
         }
 
- //
- // elementName
- //
- // OGC 07-006r1 : List of Character String. Zero or more (Mutually exclusive with
- // ElementSetName).
- String elementNameParameter = RequestUtil.getParameter(request, ELEMENT_NAME);
- if (!StringUtil.isEmpty(elementNameParameter)) {
+        //
+        // elementName
+        //
+        // OGC 07-006r1 : List of Character String. Zero or more (Mutually exclusive with
+        // ElementSetName).
+        String elementNameParameter = RequestUtil.getParameter(request, ELEMENT_NAME);
+        if (!StringUtil.isEmpty(elementNameParameter)) {
             String[] elementNames = elementNameParameter.split(",");
             List<String> elementNameList = Arrays.asList(elementNames);
             query.setElementName(elementNameList);
         }
-        
- //
- // CONSTRAINTLANGUAGE
- //
- // OGC 07-006r1 : CodeList with allowed values: CQL_TEXT or FILTER. Include when Constraint
- // included.
- String constraintLanguageParameter = RequestUtil.getParameter(request, CONSTRAINT_LANGUAGE);
- QueryConstraint queryConstraint = new QueryConstraint();
- //
- // Constraint
- //
- // OGC 07-006r1 : Predicate expression specified in the language indicated by the
- // CONSTRAINTLANGUAGE parameter
- String constraintParameter = RequestUtil.getParameter(request, CONSTRAINT);
-         if (!StringUtil.isEmpty(constraintLanguageParameter)) {
+
+        //
+        // CONSTRAINTLANGUAGE
+        //
+        // OGC 07-006r1 : CodeList with allowed values: CQL_TEXT or FILTER. Include when Constraint
+        // included.
+        String constraintLanguageParameter = RequestUtil.getParameter(request, CONSTRAINT_LANGUAGE);
+        QueryConstraint queryConstraint = new QueryConstraint();
+        //
+        // Constraint
+        //
+        // OGC 07-006r1 : Predicate expression specified in the language indicated by the
+        // CONSTRAINTLANGUAGE parameter
+        String constraintParameter = RequestUtil.getParameter(request, CONSTRAINT);
+        if (!StringUtil.isEmpty(constraintLanguageParameter)) {
             if (constraintLanguageParameter.equalsIgnoreCase(CQL_TEXT)) {
                 queryConstraint.setCQLText(constraintParameter);
             } else if (constraintLanguageParameter.equalsIgnoreCase(FILTER)) {
@@ -405,16 +406,16 @@
             query.setConstraint(queryConstraint);
         }
 
- //
- // SortBy
- //
- // OGC 07-006r1 : List of Character String, comma separated.
- // Ordered list of names of metadata elements to use for sorting the response.
- // Format of each list item is metadata_element_name:A indicating an ascending sort or
- // metadata_ element_name:D indicating descending sort.
- // Default action is to present the records in the order in which they are retrieved.
- String sortByParameter = RequestUtil.getParameter(request, SORT_BY);
-         if (!StringUtil.isEmpty(sortByParameter)) {
+        //
+        // SortBy
+        //
+        // OGC 07-006r1 : List of Character String, comma separated.
+        // Ordered list of names of metadata elements to use for sorting the response.
+        // Format of each list item is metadata_element_name:A indicating an ascending sort or
+        // metadata_ element_name:D indicating descending sort.
+        // Default action is to present the records in the order in which they are retrieved.
+        String sortByParameter = RequestUtil.getParameter(request, SORT_BY);
+        if (!StringUtil.isEmpty(sortByParameter)) {
             String[] split = sortByParameter.split(",");
             SortBy sortBy = new SortBy();
             List<SortProperty> sortPropertyList = new ArrayList<SortProperty>();
@@ -431,220 +432,240 @@
             query.setSortBy(sortBy);
         }
 
- //
- // DistributedSearch
- //
- // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
+        //
+        // DistributedSearch
+        //
+        // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
 
- //
- // hopCount
- //
- // OGC 07-006r1 : Include only if DistributedSearch parameter is included. Default value is
- // 2
- // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
+        //
+        // hopCount
+        //
+        // OGC 07-006r1 : Include only if DistributedSearch parameter is included. Default value is
+        // 2
+        // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
 
- //
- // ResponseHandler
- //
- // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
+        //
+        // ResponseHandler
+        //
+        // OGC 07-110r2: The ResponseHandler and DistributedSearch parameters shall be ignored.
 
- getRecords.setQuery(query);
+        getRecords.setQuery(query);
 
- ServletContext servletContext = this.getServletConfig().getServletContext();
- WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
+        ServletContext servletContext = this.getServletConfig().getServletContext();
+        WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+        CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
 
- try {
- GetRecordsResponse getRecordsResponse = csw202Service.getRecords(getRecords);
- // set up JiBX marshalling context
- IBindingFactory bfact = BindingDirectory.getFactory(GetRecordsResponse.class);
- IMarshallingContext marshallingContext = bfact.createMarshallingContext();
- // marshal to servlet response outputstream
- response.setContentType("text/html");
- Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
- marshallingContext.setIndent(3);
- marshallingContext.setOutput(writer);
- marshallingContext.marshalDocument(getRecordsResponse, "UTF-8", null);
- } catch (CSW202ServiceException x) {
- throw new ServletException(x);
- } catch (JiBXException x) {
- throw new ServletException(x);
- }
+        try {
+            GetRecordsResponse getRecordsResponse = csw202Service.getRecords(getRecords);
+            // set up JiBX marshalling context
+            IBindingFactory bfact = BindingDirectory.getFactory(GetRecordsResponse.class);
+            IMarshallingContext marshallingContext = bfact.createMarshallingContext();
+            // marshal to servlet response outputstream
+            response.setContentType("text/html");
+            Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
+            marshallingContext.setIndent(3);
+            marshallingContext.setOutput(writer);
+            marshallingContext.marshalDocument(getRecordsResponse, "UTF-8", null);
+        } catch (CSW202ServiceException x) {
+            throw new ServletException(x);
+        } catch (JiBXException x) {
+            throw new ServletException(x);
+        }
 
- }
+    }
 
- private void handleDescribeRecord(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- DescribeRecord describeRecord = new DescribeRecord();
- //
- // namespace
- //
- // OGC 07-006r1: If the DescribeRecord request is XML encoded, then
- // namespaces shall be declared according to the conventions of XML. If
- // the DescribeRecord request is KVP encoded, then the namespaces
- // referenced shall be declared using the NAMESPACE parameter.
- // (heikki: that's about namespaces for typenames).
- // List of Character String, comma separated. Used to specify
- // namespace(s) and their prefix(es). Format is
- // xmlns([prefix=]namespace-url).
- // If prefix is not specified, then this is the default namespace.
- // Include declarations for each namespace used in a TypeName.
- String namespaceParameter = RequestUtil.getParameter(request, NAMESPACE);
- String[] namespaces = namespaceParameter.split(",");
-        List<String> resultNamespacesList = new ArrayList<String>();
- List<String> namespacesList = Arrays.asList(namespaces);
- // the part 'xmlns(' is stripped, as is the closing bracket
- for (String namespace : namespacesList) {
- if (namespace.startsWith("xmlns(")) {
- namespace = namespace.substring("xmlns(".length());
- }
- if (namespace.endsWith(")")) {
- namespace = namespace.substring(0, namespace.length() - 1);
- }
-            resultNamespacesList.add(namespace);
- }
- describeRecord.setNamespace(resultNamespacesList);
- //
- // typeName
- //
- // OGC 07-006r1: List of Character String, comma separated.
- // One or more qualified type names to be described.
- // Default action is to describe all types known to server.
- String typeNamesParameter = RequestUtil.getParameter(request, TYPE_NAME_DESCRIBE_RECORD);
- String[] typeNames = typeNamesParameter.split(",");
- List<String> typeNamesList = Arrays.asList(typeNames);
- describeRecord.setTypeName(typeNamesList);
+    private void handleDescribeRecord(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        DescribeRecord describeRecord = new DescribeRecord();
+        //
+        // namespace
+        //
+        // OGC 07-006r1: If the DescribeRecord request is XML encoded, then
+        // namespaces shall be declared according to the conventions of XML. If
+        // the DescribeRecord request is KVP encoded, then the namespaces
+        // referenced shall be declared using the NAMESPACE parameter.
+        // (heikki: that's about namespaces for typenames).
+        // List of Character String, comma separated. Used to specify
+        // namespace(s) and their prefix(es). Format is
+        // xmlns([prefix=]namespace-url).
+        // If prefix is not specified, then this is the default namespace.
+        // Include declarations for each namespace used in a TypeName.
+        String namespaceParameter = RequestUtil.getParameter(request, NAMESPACE);
+        if (namespaceParameter != null) {
+            String[] namespaces = namespaceParameter.split(",");
+            List<String> resultNamespacesList = new ArrayList<String>();
+            List<String> namespacesList = Arrays.asList(namespaces);
+            // the part 'xmlns(' is stripped, as is the closing bracket
+            for (String namespace : namespacesList) {
+                if (namespace.startsWith("xmlns(")) {
+                    namespace = namespace.substring("xmlns(".length());
+                }
+                if (namespace.endsWith(")")) {
+                    namespace = namespace.substring(0, namespace.length() - 1);
+                }
+                resultNamespacesList.add(namespace);
+            }
+            describeRecord.setNamespace(resultNamespacesList);
+        }
 
- //
- // outputFormat
- //
- // OGC 07-006r1: A MIME type indicating the format that the output document should have.
- // Default value is application/xml.
- //
- // Ignored, only application/xml is used.
- // describeRecord.setOutputFormat(outputFormat);
+        //
+        // typeName
+        //
+        // OGC 07-006r1: List of Character String, comma separated.
+        // One or more qualified type names to be described.
+        // Default action is to describe all types known to server.
+        String typeNamesParameter = RequestUtil.getParameter(request, TYPE_NAME_DESCRIBE_RECORD);
+        if (typeNamesParameter != null) {
+            String[] typeNames = typeNamesParameter.split(",");
+            List<String> typeNamesList = Arrays.asList(typeNames);
+            describeRecord.setTypeName(typeNamesList);
+        }
 
- //
- // schemaLanguage
- //
- // OGC 07-006r1: Default value is XMLSCHEMA.
- // The schemaLanguage parameter is used to specify the schema language
- // that should be used to describe the specified types. The default
- // value is XMLSCHEMA, which indicates that the XML-Schema, schema
- // description language shall be used. Other schemas languages are
- // possible as long as the required schemaLanguage values are declared
- // in the Capabilities document.
+        //
+        // outputFormat
+        //
+        // OGC 07-006r1: A MIME type indicating the format that the output document should have.
+        // Default value is application/xml.
+        //
+        // Ignored, only application/xml is used.
+        // describeRecord.setOutputFormat(outputFormat);
 
- // We ignore this, only XML SCHEMA is supported.
- // describeRecord.setSchemaLanguage(schemaLanguage);
+        //
+        // schemaLanguage
+        //
+        // OGC 07-006r1: Default value is XMLSCHEMA.
+        // The schemaLanguage parameter is used to specify the schema language
+        // that should be used to describe the specified types. The default
+        // value is XMLSCHEMA, which indicates that the XML-Schema, schema
+        // description language shall be used. Other schemas languages are
+        // possible as long as the required schemaLanguage values are declared
+        // in the Capabilities document.
 
- ServletContext servletContext = this.getServletConfig().getServletContext();
- WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
+        // We ignore this, only XML SCHEMA is supported.
+        // describeRecord.setSchemaLanguage(schemaLanguage);
 
- try {
- DescribeRecordResponse describeRecordResponse = csw202Service.describeRecord(describeRecord);
- // set up JiBX marshalling context
- IBindingFactory bfact = BindingDirectory.getFactory(DescribeRecordResponse.class);
- IMarshallingContext marshallingContext = bfact.createMarshallingContext();
- // marshal to servlet response outputstream
- response.setContentType("application/xml");
- Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
- marshallingContext.setIndent(3);
- marshallingContext.setOutput(writer);
- marshallingContext.marshalDocument(describeRecordResponse, "UTF-8", null);
- } catch (CSW202ServiceException e) {
- throw new ServletException(e);
- } catch (JiBXException e) {
- throw new ServletException(e);
- }
- }
+        ServletContext servletContext = this.getServletConfig().getServletContext();
+        WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+        CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
 
- /**
- *
- * @param request
- * @param response
- * @throws ServletException
- * @throws IOException
- */
- private void handleGetRecordById(HttpServletRequest request, HttpServletResponse response) throws ServletException,
- IOException {
- GetRecordById getRecordById = new GetRecordById();
+        try {
+            DescribeRecordResponse describeRecordResponse = csw202Service.describeRecord(describeRecord);
+            // set up JiBX marshalling context
+            IBindingFactory bfact = BindingDirectory.getFactory(DescribeRecordResponse.class);
+            IMarshallingContext marshallingContext = bfact.createMarshallingContext();
+            // marshal to servlet response outputstream
+            response.setContentType("application/xml");
+            /*Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
+            marshallingContext.setIndent(3);
+            marshallingContext.setOutput(writer);
+            marshallingContext.marshalDocument(describeRecordResponse, "UTF-8", null);*/
 
- //
- // ElementSetName
- //
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            Writer out = new BufferedWriter(new OutputStreamWriter(outputStream));
+            marshallingContext.setOutput(out);
 
- /**
- * CodeList with allowed values: "brief", "summary" or "full"
- */
- String elementSetNameParam = RequestUtil.getParameter(request, ELEMENT_SET_NAME);
- if (!StringUtil.isEmpty(elementSetNameParam)) {
+            marshallingContext.marshalDocument(describeRecordResponse, "UTF-8", null);
+            // Process marshalling to remove GetRepositoryItemResponse and return only content
+            String result = outputStream.toString();
+            result = result.replaceAll("<", "<");
+            
+            PrintWriter writer = response.getWriter();
+            writer.write(result);
+
+        } catch (CSW202ServiceException e) {
+            try {
+                outputError(e.getFaultMessage(), response);
+            } catch (Exception x) {
+                throw new ServletException(e);
+            }
+
+        } catch (JiBXException e) {
+            throw new ServletException(e);
+        }
+    }
+
+    /**
+     * @param request
+     * @param response
+     * @throws ServletException
+     * @throws IOException
+     */
+    private void handleGetRecordById(HttpServletRequest request, HttpServletResponse response) throws ServletException,
+            IOException {
+        GetRecordById getRecordById = new GetRecordById();
+
+        //
+        // ElementSetName
+        //
+
+        /**
+         * CodeList with allowed values: "brief", "summary" or "full"
+         */
+        String elementSetNameParam = RequestUtil.getParameter(request, ELEMENT_SET_NAME);
+        if (!StringUtil.isEmpty(elementSetNameParam)) {
             ElementSetName elementSetName = new ElementSetName();
             elementSetName.setElementSet(ElementSet.valueOf(elementSetNameParam));
             getRecordById.setElementSetName(elementSetName);
         }
- //
- // Id
- //
- /**
- * The Id parameter is a comma-separated list of record identifiers for the records that a CSW shall return to
- * the client.
- */
- String idParam = RequestUtil.getParameter(request, ID);
- String[] ids = idParam.split(",");
- List<String> idList = Arrays.asList(ids);
- getRecordById.setId(idList);
+        //
+        // Id
+        //
+        /**
+         * The Id parameter is a comma-separated list of record identifiers for the records that a CSW shall return to
+         * the client.
+         */
+        String idParam = RequestUtil.getParameter(request, ID);
+        String[] ids = idParam.split(",");
+        List<String> idList = Arrays.asList(ids);
+        getRecordById.setId(idList);
 
- //
- // outputformat
- //
- String outputFormat = RequestUtil.getParameter(request, OUTPUT_FORMAT);
+        //
+        // outputformat
+        //
+        String outputFormat = RequestUtil.getParameter(request, OUTPUT_FORMAT);
         if (!StringUtil.isEmpty(outputFormat)) {
-    getRecordById.setOutputFormat(outputFormat);
+            getRecordById.setOutputFormat(outputFormat);
         }
 
- //
- // outputschema
- //
- String outputSchema = RequestUtil.getParameter(request, OUTPUT_SCHEMA);
+        //
+        // outputschema
+        //
+        String outputSchema = RequestUtil.getParameter(request, OUTPUT_SCHEMA);
         if (!StringUtil.isEmpty(outputSchema)) {
-    getRecordById.setOutputSchema(outputSchema);
+            getRecordById.setOutputSchema(outputSchema);
         }
 
- // service and version as usual are fixed values, we accept anything
- // getRecordById.setService(service);
- // getRecordById.setVersion(version);
+        // service and version as usual are fixed values, we accept anything
+        // getRecordById.setService(service);
+        // getRecordById.setVersion(version);
 
- ServletContext servletContext = this.getServletConfig().getServletContext();
- WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
- CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
+        ServletContext servletContext = this.getServletConfig().getServletContext();
+        WebApplicationContext waco = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
+        CSW202Service csw202Service = (CSW202Service) waco.getBean("csw202Service");
 
- try {
- GetRecordByIdResponse getRecordByIdResponse = csw202Service.getRecordById(getRecordById);
- // set up JiBX marshalling context
- IBindingFactory bfact = BindingDirectory.getFactory(GetRecordByIdResponse.class);
- IMarshallingContext marshallingContext = bfact.createMarshallingContext();
- // marshal to servlet response outputstream
- response.setContentType("application/xml");
- Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
- marshallingContext.setIndent(3);
- marshallingContext.setOutput(writer);
- marshallingContext.marshalDocument(getRecordByIdResponse, "UTF-8", null);
- } catch (CSW202ServiceException e) {
+        try {
+            GetRecordByIdResponse getRecordByIdResponse = csw202Service.getRecordById(getRecordById);
+            // set up JiBX marshalling context
+            IBindingFactory bfact = BindingDirectory.getFactory(GetRecordByIdResponse.class);
+            IMarshallingContext marshallingContext = bfact.createMarshallingContext();
+            // marshal to servlet response outputstream
+            response.setContentType("application/xml");
+            Writer writer = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));
+            marshallingContext.setIndent(3);
+            marshallingContext.setOutput(writer);
+            marshallingContext.marshalDocument(getRecordByIdResponse, "UTF-8", null);
+        } catch (CSW202ServiceException e) {
             try {
                 outputError(e.getFaultMessage(), response);
             } catch (Exception x) {
                 throw new ServletException(e);
             }
+        } catch (JiBXException e) {
+            throw new ServletException(e);
+        }
 
+    }
 
- } catch (JiBXException e) {
- throw new ServletException(e);
- }
-
- }
-
     private void outputError(ExceptionReport er, HttpServletResponse response) throws JiBXException, IOException {
         IBindingFactory bfact = BindingDirectory.getFactory(ExceptionReport.class);
         IMarshallingContext marshallingContext = bfact.createMarshallingContext();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
GeoNetwork-commit mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geonetwork-commit