0

클라우드에 데이터를 저장하기 위해 objectify + app 엔진 엔드 포인트를 사용하고 있습니다. 내 "포인트"개체를 만들 수있다는 객관화와 (그것은 구글지도에서 지점입니다) :Appengine, 400 잘못된 요청으로 Objectify. 클래스가 등록되지 않았습니다

package com.example.Javier.WH.backend; 

import com.google.appengine.repackaged.com.google.type.LatLng; 
import com.googlecode.objectify.annotation.Entity; 
import com.googlecode.objectify.annotation.Id; 

@Entity 
public class Point { 

@Id 
String id; 
Double latitude; 
Double longitude; 
Double ratius; 
String date; 
String title; 
String description; 

public Point(){} 

public Point(Double la, Double lo,String stitle){ 
    latitude = la; 
    longitude = lo; 
    title = stitle; 
} 

public String getId(){ 
    return id; 
} 

public void setId(String id){ 
    this.id = id; 
} 

public Double getLatitude() { 
    return latitude; 
} 

public void setLatitude(Double latitude) { 
    this.latitude = latitude; 
} 

public Double getLongitude() { 
    return longitude; 
} 

public void setLongitude(Double longitude) { 
    this.longitude = longitude; 
} 

public Double getRatius() { 
    return ratius; 
} 

public void setRatius(Double ratius) { 
    this.ratius = ratius; 
} 

public String getDate() { 
    return date; 
} 

public void setDate(String date) { 
    this.date = date; 
} 

public String getTitle() { 
    return title; 
} 

public void setTitle(String title) { 
    this.title = title; 
} 

public String getDescription() { 
    return description; 
} 

public void setDescription(String description) { 
    this.description = description; 
} 
} 

이 내 "pointEndpoint"클래스 :

package com.example.Javier.WH.backend; 

import com.google.api.server.spi.config.Api; 
import com.google.api.server.spi.config.ApiMethod; 
import com.google.api.server.spi.config.ApiNamespace; 
import com.google.api.server.spi.config.Named; 
import com.google.api.server.spi.config.Nullable; 
import com.google.api.server.spi.response.CollectionResponse; 
import com.google.api.server.spi.response.ConflictException; 
import com.google.api.server.spi.response.NotFoundException; 
import com.google.appengine.api.datastore.Cursor; 
import com.google.appengine.api.datastore.QueryResultIterator; 
import com.googlecode.objectify.cmd.Query; 

import java.util.ArrayList; 
import java.util.List; 
import java.util.logging.Logger; 

import static com.googlecode.objectify.ObjectifyService.ofy; 

@Api(
     name = "pointEndpoint", 
     version = "v1", 
     namespace = @ApiNamespace(
       ownerDomain = "backend.WH.Javier.example.com", 
       ownerName = "backend.WH.Javier.example.com", 
       packagePath = "") 
    ) 
public class PointEndpoint { 

    private static final Logger LOG = Logger.getLogger(PointEndpoint.class.getName()); 

    public PointEndpoint(){} 

    @ApiMethod(name = "listPoints") 
    public CollectionResponse<Point> listPoints(@Nullable @Named("cursor") String cursorString){ 

     Query<Point> query = ofy().load().type(Point.class); 
     if (cursorString != null && cursorString != ""){ 
      query = query.startAt(Cursor.fromWebSafeString(cursorString)); 
     } 
     List<Point> records = new ArrayList<Point>(); 
     QueryResultIterator<Point> iterator = query.iterator(); 
     int num = 0; 
     while (iterator.hasNext()){ 
      records.add(iterator.next()); 
     } 
     if (cursorString != null && cursorString != "") { 
      Cursor cursor = iterator.getCursor(); 
      if (cursor != null) { 
       cursorString = cursor.toWebSafeString(); 
      } 
     } 
     return CollectionResponse.<Point>builder().setItems(records).setNextPageToken(cursorString).build(); 
    } 

    @ApiMethod(name = "insertPoint") 
    public Point insertPoint(Point point) throws ConflictException{ 
     if(point.getId() != null){ 
      if(findRecord(point.getId()) != null){ 
       throw new ConflictException("Object already exists"); 
      } 
     } 
     ofy().save().entity(point).now(); 
     return point; 
    } 

    @ApiMethod(name = "insertString") 
    public Point insertString(@Named("string") String s) throws ConflictException{ 
     Point point = new Point(49.500087,7.829500,s); 
     if(point.getId() != null) { 
      if (findRecord(point.getId()) != null) { 
       throw new ConflictException("Object already exists"); 
      } 
     } 
     ofy().save().entity(point).now(); 
     return point; 
    } 

    @ApiMethod(name = "updatePoint") 
    public Point updatePoint(Point point) throws NotFoundException{ 
     if(findRecord(point.getId()) == null){ 
      throw new NotFoundException(("Point record does not exist")); 
     } 
     ofy().save().entity(point).now(); 
     return point; 
    } 

    @ApiMethod(name = "removePoint") 
    public void removeQuote(@Named("id") String id) throws NotFoundException{ 
     Point record = findRecord(id); 
     if(record == null){ 
      throw new NotFoundException("Point record does not exist"); 
     } 
     ofy().delete().entity(record).now(); 
    } 

    private Point findRecord(String id){ 
     return ofy().load().type(Point.class).id(id).now(); 
    } 

} 

은 "ofyService"클래스 :

package com.example.Javier.WH.backend; 

import com.googlecode.objectify.Objectify; 
import com.googlecode.objectify.ObjectifyFactory; 
import com.googlecode.objectify.ObjectifyService; 

public class OfyService { 

    static { 
     ObjectifyService.register(Point.class); 
     ObjectifyService.register(MyEndpoint.class); 
    } 

    public static Objectify ofy(){ 
     return ObjectifyService.ofy(); 
    } 

    public static ObjectifyFactory factory(){ 
     return ObjectifyService.factory(); 
    } 
} 

build.gradle :

def appEmail = "[email protected]" 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.google.appengine:gradle-appengine-plugin:1.9.34' 
    } 
} 

repositories { 
    jcenter(); 
} 

apply plugin: 'java' 
apply plugin: 'war' 
apply plugin: 'appengine' 

sourceCompatibility = JavaVersion.VERSION_1_7 
targetCompatibility = JavaVersion.VERSION_1_7 

dependencies { 
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.34' 
    compile 'com.google.appengine:appengine-endpoints:1.9.34' 
    compile 'com.google.appengine:appengine-endpoints-deps:1.9.34' 
    compile 'com.googlecode.objectify:objectify:5.0.3' 
    compile 'javax.servlet:servlet-api:2.5' 
} 

appengine { 
    downloadSdk = true 
    appcfg { 
     oauth2 = true 
      email = "${appEmail}" 
    } 
    endpoints { 
     getClientLibsOnBuild = true 
     getDiscoveryDocsOnBuild = true 
    } 
} 
,

마지막으로 web.xml 파일 : 나는 오류가 오는 곳에서 모르는

<?xml version="1.0" encoding="utf-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"> 
    <servlet> 
     <servlet-name>SystemServiceServlet</servlet-name> 
     <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class> 
     <init-param> 
      <param-name>services</param-name> 
      <param-value>com.example.Javier.WH.backend.MyEndpoint, com.example.Javier.WH.backend.PointEndpoint</param-value> 
     </init-param> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>SystemServiceServlet</servlet-name> 
     <url-pattern>/_ah/spi/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 
</web-app> 

. 당신이

ObjectifyService.register(Point.class); 
ObjectifyService.register(MyEndpoint.class); 

MyEndpoint.class 그것이 @Api하지 주석처럼 소리가 요청이

enter image description here

잘 보이지만 오류가 항상 OfyService 클래스에서

enter image description here

+1

제거 '가져 오기 정적 com.googlecode.objectify.ObjectifyService.ofy를,'수입 및 클래스를 등록 OfyService''자신을 사용 – zapl

답변

0

나타납니다 Objectify의 @Entity. 따라서 응용 프로그램 시작시 또는 OfyService의 정적 생성자가 실행될 때 예외가 발생한다고 가정합니다. 이 예외로 인해 엔티티가 등록되지 않으므로 실제 엔티티가 Objectify에 등록되어 있지 않습니다. 간단한 해결책은 @Api을 Objectify로 등록하지 않는 것입니다. @Entity -annotated 인 클래스 만 등록하십시오.

<filter> 
    <filter-name>ObjectifyFilter</filter-name> 
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>ObjectifyFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 
<listener> 
    <listener-class>com.example.Javier.WH.backend.OfyService </listener-class> 
</listener> 
0

은 web.xml 파일이 추가. 코드가 현재 완전히 사용되지 않습니다.