501没有实现OData

时间:2017-03-08 17:46:56

标签: spring-boot odata

我正在尝试构建排序OData服务。我的ODataServiceFactory实现如下所示: EdmProvider edm = new SortMetaData(); ODataSingleProcessor sortProcessor = new SortProcessor(); return createODataSingleProcessorService(edm, sortProcessor);

在EDM中,我正在准备EntitySet,EntitySetContainer并将它们添加到架构中。当我在本地访问localhost / odata.svc / $ metadata时,我会看到元数据:

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="com.sudhi.learning">
<EntityType Name="SortNumber">
<Key>
<PropertyRef Name="number_id"/>
</Key>
<Property Name="number_id" Type="Edm.Int16"/>
</EntityType>
<EntityContainer Name="ODataSortNumbersContainer" m:IsDefaultEntityContainer="true">
<EntitySet Name="SortNumbers" EntityType="com.sudhi.learning.SortNumber"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

到目前为止一切顺利。现在,如果我尝试将localhost / odata.svc / SortNumbers放入我的EntitySet,我会假设它会触发我在ODataSingleProcessor类中重新定义的readEntity方法:

public class SortProcessor extends ODataSingleProcessor{

    @Override
    public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
        EdmEntitySet entitySet = uriInfo.getStartEntitySet();
        URI serviceRoot = getContext().getPathInfo().getServiceRoot();
        ODataEntityProviderPropertiesBuilder properties = EntityProviderWriteProperties.serviceRoot(serviceRoot);
        return EntityProvider.writeEntry(contentType, entitySet, Randomizer.fillRandomNumbers(), properties.build());
    }
}

但是一旦我点击了URL,我就得到了501未实现的错误。我正在使用Spring Boot应用程序,我已经使用SpringServletRegistrationBean添加了我自己的servlet,如下所示:

@Configuration
public class ServletHandler {
    @Bean
    public ServletRegistrationBean getODataServletRegistrationBean() {
        ServletRegistrationBean odataServletRegistrationBean = new ServletRegistrationBean(new CXFNonSpringJaxrsServlet(), "/odata.svc/*");
        Map<String, String> initParameters = new HashMap<String, String>();
        initParameters.put("javax.ws.rs.Application", "org.apache.olingo.odata2.core.rest.app.ODataApplication");
        initParameters.put("org.apache.olingo.odata2.service.factory", "com.sudhi.learning.SortServiceFactory");
        odataServletRegistrationBean.setInitParameters(initParameters);
        return odataServletRegistrationBean;
    }
}

我认为在设置servlet时我缺少一些设置但不太确定。 需要帮助!!

1 个答案:

答案 0 :(得分:0)

解决了这个问题。我没有重新定义ReadEntitySet ......