@Override public ResourceMetadata<OWS> createFromLocation( Workspace workspace, ResourceLocation<OWS> location ) { return new CswMetadata( workspace, location, this ); }
@Override public OWS build() { return new CSWController( metadata, workspace, config ); }
private void sendServiceException( OWSException ex, HttpResponseBuffer response ) throws ServletException { sendException( null, getExceptionSerializer( parseVersion( "1.2.0" ) ), ex, response ); }
private void doXML( OMElement requestElement, HttpResponseBuffer response ) throws OWSException, XMLStreamException, IOException { String rootElement = requestElement.getLocalName(); CSWRequestType requestType = getRequestType( rootElement ); if ( requestType == null ) throw new IllegalArgumentException( rootElement + " is not a known request type by this CSW" ); Version requestVersion = getVersion( requestElement.getAttributeValue( new QName( "version" ) ) ); if ( requestType != CSWRequestType.GetCapabilities ) { checkVersion( requestVersion ); requestVersion = profile.checkVersion( requestVersion ); boolean supportedOperation = profile.supportsOperation( requestType ); if ( !supportedOperation ) { throw new OWSException( requestType + " is not supported by this CSW service ", INVALID_PARAMETER_VALUE ); GetCapabilitiesVersionXMLAdapter getCapabilitiesAdapter = new GetCapabilitiesVersionXMLAdapter(); getCapabilitiesAdapter.setRootElement( requestElement ); GetCapabilities cswRequest = getCapabilitiesAdapter.parse(); doGetCapabilities( cswRequest, response, true ); break; case DescribeRecord: DescribeRecordXMLAdapter describeRecordAdapter = new DescribeRecordXMLAdapter(); describeRecordAdapter.setRootElement( requestElement ); DescribeRecord cswDRRequest = describeRecordAdapter.parse( requestVersion ); describeRecordHandler.doDescribeRecord( cswDRRequest, response, profile ); break; case GetRecords: GetRecordsXMLAdapter getRecordsAdapter = new GetRecordsXMLAdapter();
try { String rootElement = KVPUtils.getRequired( normalizedKVPParams, "REQUEST" ); CSWRequestType requestType = getRequestType( rootElement ); if ( requestType == null ) throw new OWSException( rootElement + " is not a known request type by this CSW", INVALID_PARAMETER_VALUE ); Version requestVersion = getVersion( normalizedKVPParams.get( "ACCEPTVERSIONS" ) ); if ( !ArrayUtils.contains( profile.getSupportedServiceNames(), serviceAttr ) ) { StringBuilder sb = new StringBuilder(); sb.append( "Wrong service attribute: '" ).append( serviceAttr ); sb.append( "' -- must be " ); String[] serviceNames = profile.getSupportedServiceNames(); for ( int i = 0; i < serviceNames.length; i++ ) { sb.append( serviceNames[i] ); checkVersion( requestVersion ); boolean supportedOperation = profile.supportsOperation( requestType ); if ( !supportedOperation ) { throw new OWSException( requestType + " is not supported by this CSW service ", INVALID_PARAMETER_VALUE ); GetCapabilities getCapabilities = GetCapabilities202KVPAdapter.parse( normalizedKVPParams ); doGetCapabilities( getCapabilities, response, false ); break; case DescribeRecord: DescribeRecord descRec = DescribeRecordKVPAdapter.parse( normalizedKVPParams ); describeRecordHandler.doDescribeRecord( descRec, response, profile );
store = workspace.getResource( MetadataStoreProvider.class, metadataStoreId ); profile = ServiceProfileManager.createProfile( store ); validateAndSetOfferedVersions( profile.getSupportedVersions() ); LOG.info( "No SupportedVersion element provided. The version is set to default 2.0.2" ); } else { validateAndSetOfferedVersions( jaxbConfig.getSupportedVersions().getVersion() ); for ( ElementName en : elementNames ) { QName qName = new QName( en.getName().getNamespace(), en.getName().getValue() ); elNames.put( qName, new ConfiguredElementName( qName, en.getXPath() ) ); describeRecordHandler = new DescribeRecordHandler(); getRecordsHandler = new GetRecordsHandler( maxMatches, SCHEMA_LOCATION, store, elNames ); transactionHandler = new TransactionHandler(); getRecordByIdHandler = getGetRecordByIdHandler();
Set<Sections> sections = getSections( getCapabilitiesRequest ); Version negotiatedVersion = null; if ( getCapabilitiesRequest.getAcceptVersions() == null ) { negotiatedVersion = new Version( 2, 0, 2 ); } else { negotiatedVersion = negotiateVersion( getCapabilitiesRequest ); response.setContentType( profile.getAcceptFormat( getCapabilitiesRequest ) ); XMLStreamWriter xmlWriter = getXMLResponseWriter( response, null ); CapabilitiesHandler gce = profile.getCapabilitiesHandler( xmlWriter, mainMetadataConf, mainControllerConf, sections, mainMetadataConf.getServiceIdentification(), mainMetadataConf.getServiceProvider(), extendedCapabilities ); gce.export(); xmlWriter.flush();
xmlWriter.writeStartElement( soapEnvNS, "Body" ); } else { beginSOAPResponse( response ); doXML( soapDoc.getBody().getFirstElement(), response ); } catch ( XMLStreamException e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, new OWSException( e.getMessage(), e, NO_APPLICABLE_CODE ), request, version ); } catch ( OWSException e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, e, request, version ); } catch ( IOException e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, new OWSException( e.getMessage(), e, NO_APPLICABLE_CODE ), request, version ); } catch ( MissingParameterException e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, new OWSException( e.getMessage(), e, MISSING_PARAMETER_VALUE ), request, version ); } catch ( InvalidParameterValueException e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, new OWSException( e.getMessage(), e, INVALID_PARAMETER_VALUE ), request, version ); } catch ( FailedAuthentication e ) { LOG.debug( e.getMessage(), e ); sendSoapException( soapDoc, factory, response, new OWSException( e.getMessage(), e, NO_APPLICABLE_CODE ), request, version ); } catch ( Throwable t ) {
@Override public void serializeException( HttpResponseBuffer response, OWSException exception ) throws IOException, XMLStreamException { response.reset(); response.setCharacterEncoding( "UTF-8" ); response.setContentType( "application/xml" ); setExceptionStatusCode( response, exception ); serializeExceptionToXML( response.getXMLWriter(), exception ); }
private void sendSoapException( SOAPEnvelope soapDoc, SOAPFactory factory, HttpResponseBuffer response, OWSException e, ServletRequest request, SOAPVersion version ) throws OMException, ServletException { XMLExceptionSerializer serializer = getExceptionSerializer( parseVersion( "1.2.0" ) ); sendSOAPException( soapDoc.getHeader(), factory, response, e, serializer, null, null, request.getServerName(), request.getCharacterEncoding() ); }
@Override public void doXML( XMLStreamReader xmlStream, HttpServletRequest request, HttpResponseBuffer response, List<FileItem> multiParts ) throws ServletException, IOException, SecurityException { response.setContentType( "text/xml" ); try { XMLAdapter requestDoc = new XMLAdapter( xmlStream ); OMElement rootElement = requestDoc.getRootElement(); doXML( rootElement, response ); } catch ( OWSException e ) { LOG.debug( e.getMessage(), e ); sendServiceException( e, response ); } catch ( InvalidParameterValueException e ) { LOG.debug( e.getMessage(), e ); sendServiceException( new OWSException( e ), response ); } catch ( MissingParameterException e ) { LOG.debug( e.getMessage(), e ); sendServiceException( new OWSException( e ), response ); } catch ( Throwable t ) { String msg = "An unexpected error occured: " + t.getMessage(); LOG.error( msg, t ); sendServiceException( new OWSException( msg, t, NO_APPLICABLE_CODE ), response ); } }
@Override public ResourceBuilder<OWS> prepare() { try { DeegreeCSW cfg = (DeegreeCSW) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, provider.getSchema(), location.getAsStream(), workspace ); String id = cfg.getMetadataStoreId(); if ( id != null ) { dependencies.add( new DefaultResourceIdentifier( MetadataStoreProvider.class, id ) ); } else { for ( ResourceMetadata<?> md : workspace.getResourceManager( MetadataStoreManager.class ).getResourceMetadata() ) { softDependencies.add( md.getIdentifier() ); } } OWSMetadataProviderManager mmgr = workspace.getResourceManager( OWSMetadataProviderManager.class ); for ( ResourceMetadata<OWSMetadataProvider> md : mmgr.getResourceMetadata() ) { ResourceIdentifier<OWSMetadataProvider> mdId = md.getIdentifier(); if ( mdId.getId().equals( getIdentifier().getId() + "_metadata" ) ) { softDependencies.add( mdId ); } } return new CswBuilder( this, workspace, cfg ); } catch ( Exception e ) { throw new ResourceInitException( e.getLocalizedMessage(), e ); } }
@Override public XMLExceptionSerializer getExceptionSerializer( Version requestVersion ) { return new CswExceptionReportSerializer( Version.parseVersion( "1.2.0" ) ); }
/** * Extracts the qualified type names from the <code>TYPENAME</code> parameter. * * @param kvpParam * the parameters of the request, normalized * @param nsBindings * namespace bindings, may be null * @return qualified type names or null if no <code>TYPENAME</code> parameter is present * @throws InvalidParameterValueException * if the value of the <code>TYPENAME</code> attribute contains a syntactical error or uses unbound * prefices */ protected static QName[] extractTypeNames( Map<String, String> kvpParam, Map<String, String> nsBindings ) throws InvalidParameterValueException { QName[] typeNames = null; String typeNameString = kvpParam.get( "TYPENAMES" ); if ( typeNameString != null ) { String[] typeNameStrings = typeNameString.split( "," ); typeNames = new QName[typeNameStrings.length]; for ( int i = 0; i < typeNameStrings.length; i++ ) { typeNames[i] = qualifyName( typeNameStrings[i], nsBindings ); } } return typeNames; }
/** * Method for mapping the request operation to the implemented operations located in {@link CSWConstants} * * @param requestName * @return CSWRequestType * @throws OWSException */ private CSWRequestType getRequestType( String requestName ) throws OWSException { CSWRequestType requestType = null; try { requestType = (CSWRequestType) ( (ImplementationMetadata) ( (OWSProvider) getMetadata().getProvider() ).getImplementationMetadata() ).getRequestTypeByName( requestName ); } catch ( IllegalArgumentException e ) { throw new OWSException( e.getMessage(), OWSException.OPERATION_NOT_SUPPORTED ); } return requestType; }