Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 测试Rest服务时出错_Java_Eclipse_Rest_Tomcat7 - Fatal编程技术网

Java 测试Rest服务时出错

Java 测试Rest服务时出错,java,eclipse,rest,tomcat7,Java,Eclipse,Rest,Tomcat7,我正在写简单的Helloworld Rest类。我正在使用eclipse和Tomcat7。我加了杰西瓶。 我已经编写了java程序来测试Rest服务。我在线程“main”com.sun.jersey.api.client.UniformInterfaceException中收到名为exception的异常: 我遵循这个教程。我已经给了正确的网址,但我仍然不知道为什么我得到这个错误 我的休息课是 包cs9322.simple.rest.hello import javax.ws.rs.GET; i

我正在写简单的Helloworld Rest类。我正在使用eclipse和Tomcat7。我加了杰西瓶。 我已经编写了java程序来测试Rest服务。我在线程“main”com.sun.jersey.api.client.UniformInterfaceException中收到名为exception的异常:

我遵循这个教程。我已经给了正确的网址,但我仍然不知道为什么我得到这个错误

我的休息课是 包cs9322.simple.rest.hello

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/helloworld")
public class HelloWorld {
@GET
@Produces(MediaType.TEXT_XML)
public String sayHelloXML() { 
   return "<?xml version=\"1.0\"?>" + "<msg>" + "Hello World in REST" + "    
}
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHelloHtml() {
    return "<html> " + "<title>" + "Hello Jersey" + "</title>"
            + "<body><h1>" + "Hello World in REST" + "</body></h1>" + "
}

}
My client class:
package cs9322.simple.rest.hello.client;
import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

public class Test {
public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
System.out.println(service.path("rest").path("helloworld").accept(
MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());    
System.out.println(service.path("rest").path("helloworld").accept(
MediaType.TEXT_XML).get(String.class));
    // Accept Header set to HTML
System.out.println(service.path("rest").path("helloworld").accept(
            MediaType.TEXT_HTML).get(String.class));

}

// Here, the Web application root ... 
// (then the remainder of the path should contain 'rest/*')
private static URI getBaseURI() {
return UriBuilder.fromUri(
"http://localhost:8080/cs9322.simple.rest.hello").build();
}

}
import javax.ws.rs.GET;
导入javax.ws.rs.Path;
导入javax.ws.rs.products;
导入javax.ws.rs.core.MediaType;
@路径(“/helloworld”)
公共类HelloWorld{
@得到
@生成(MediaType.TEXT\u XML)
公共字符串sayHelloXML(){
返回“+”+“REST中的Hello World”+“
}
@得到
@生成(MediaType.TEXT\u HTML)
公共字符串sayHelloHtml(){
返回“+”+“Hello Jersey”+“
+“+”REST中的Hello World“+”
}
}
我的客户端类:
包cs9322.simple.rest.hello.client;
导入java.net.URI;
导入javax.ws.rs.core.MediaType;
导入javax.ws.rs.core.UriBuilder;
导入com.sun.jersey.api.client.client;
导入com.sun.jersey.api.client.ClientResponse;
导入com.sun.jersey.api.client.WebResource;
导入com.sun.jersey.api.client.config.ClientConfig;
导入com.sun.jersey.api.client.config.DefaultClientConfig;
公开课考试{
公共静态void main(字符串[]args){
ClientConfig=newdefaultclientconfig();
Client=Client.create(config);
WebResource服务=client.resource(getBaseURI());
System.out.println(service.path(“rest”).path(“helloworld”).accept(
get(ClientResponse.class.toString());
System.out.println(service.path(“rest”).path(“helloworld”).accept(
get(String.class));
//接受设置为HTML的标题
System.out.println(service.path(“rest”).path(“helloworld”).accept(
get(String.class));
}
//在这里,Web应用程序根目录。。。
//(那么路径的其余部分应该包含“rest/*”)
私有静态URI getBaseURI(){
返回UriBuilder.fromUri(
"http://localhost:8080/cs9322.simple.rest.hellobuild();
}
}

也许这会有所帮助。服务返回的内容是否与您期望的不同?请先在google和stackoverflow中使用ie XML而不是JSON,然后提问可能会发布一些代码和完整的堆栈跟踪,这样我们才能真正帮助您?我已经参考了这个问题bt仍然错误是nt Debugged stackoverflow.com/questions/1250223/…–ashokhein 1小时前