NutzCN Logo
问答 接口只能使用get请求获取数据,使用post请求会报错。所有接口都是这样
发布于 14天前 作者 xzx534142447 83 次浏览 复制 上一个帖子 下一个帖子
标签:

报错如下

org.nutz.json.JsonException: !Json syntax error nearby [row:1,col:1 char 't'], reason: 'Unexpect String = type=1'
	at org.nutz.json.impl.JsonTokenScan.readObject(JsonCompileImplV2.java:300)
	at org.nutz.json.impl.JsonTokenScan.read(JsonCompileImplV2.java:356)
	at org.nutz.json.impl.JsonCompileImplV2.parse(JsonCompileImplV2.java:26)
	at org.nutz.json.Json.fromJson(Json.java:42)
	at org.nutz.mvc.adaptor.JsonAdaptor.getReferObject(JsonAdaptor.java:41)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:224)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.liqi.health.cloudhospital.LogTimeProcessor.process(LogTimeProcessor.java:23)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.liqi.health.cloudhospital.system.filter.EncodingFilter.doFilter(EncodingFilter.java:36)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
	at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

详细代码如下

@At("/getTerminalInitConfig_v1")
    @Ok("json")
	@AdaptBy(type=JsonAdaptor.class)
	public Object getTerminaInitConfig_v1(){
		Map<String,Object> result = new HashMap<String,Object>();

		SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateStr = dFormat.format(new Date());
		
		result.put("webInitUrl", "localhost:8080");
		
		result.put("syncDateTime", dateStr);
		result.put("commitOrderInfoUrl", "");
		result.put("commitTransactionDataUrl", "");
		
		return result;
	}
3 回复

JsonException 使用JsonAdaptor适配器,但提交的数据不是Json格式

自己写个提交转型

public class GraphQLAdaptor extends PairAdaptor {

        protected ParamInjector evalInjector(Type type, Param param) {
            if (param == null || "..".equals(param.value())) {

                return new GraphQLInjector(type);
            }
            return super.evalInjector(type, param);
        }

        public Object getReferObject(ServletContext sc,
                                     HttpServletRequest req,
                                     HttpServletResponse resp, String[] pathArgs) {
            try {
                Reader reader = Streams.utf8r(req.getInputStream());
                return Streams.read(reader).toString();
            }
            catch (Exception e) {
                throw Lang.wrapThrow(e);
            }
      
public class GraphQLInjector implements ParamInjector {
    public GraphQLInjector(Type type) {
        this.type = type;
    }

    private Type type;




    @SuppressWarnings("unchecked")
    public Object get(    ServletContext sc,
                          HttpServletRequest req,
                          HttpServletResponse resp,
                          Object refer) {


        return refer;
    }
}
	@At("/graphql")
	@Ok("json")
	@POST
	@AdaptBy(type = GraphQLAdaptor.class)
	public Object graphql(@Param("..")String sql ,
			HttpServletRequest req) {
		init();

		GraphQL graphQL = new GraphQL.Builder(schema).build();

        ExecutionResult result = graphQL.execute(sql);

		return result;

	}
添加回复
请先登陆
回到顶部