- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我强调了一种情况,在这种情况下无法调用以 java.lang.Object 作为参数的 Web 服务方法。
我正在使用 Netbeans 7.1 和 Tomcat 7。
为了创建、部署和访问 Web 服务,我遵循了以下给出的步骤: http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/
网络服务端点如下:
package com.metrows;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
/**
*
* @author 298790
*/
@WebService(serviceName = "NewWebService")
public class NewWebService {
/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
/**
* Web service operation
*/
@WebMethod(operationName = "sendObjParam")
public Object sendObjParam(@WebParam(name = "paramObj") Object paramObj) {
//TODO write your implementation code here:
System.out.println("In NewWebService.sendObjParam(...) "+paramObj);
return paramObj;
}
/**
* Web service operation
*/
@WebMethod(operationName = "passCustomParams")
@Oneway
public void passCustomParams(@WebParam(name = "tenant") Tenant tenant) {
System.out.println("In NewWebService.passCustomParams(...) : tenant = " + tenant);
System.out.println(": " + tenant.getMap());
}
}
租户如下:
package com.valueobjects;
import java.util.HashMap;
/**
*
* @author 298790
*/
public class Tenant {
private String tenantId;
private String tenantName;
private HashMap map;
public String getTenantId() {
return tenantId;
}
public void setTenantId(String tenantId) {
this.tenantId = tenantId;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
public HashMap getMap() {
return map;
}
public void setMap(HashMap map) {
this.map = map;
}
}
客户端如下:
package metro_ws_client;
/**
*
* @author 298790
*/
public class Metro_WS_Client {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println(hello("Aao Thakur !!!"));
Tenant tenant = new Tenant();
tenant.setTenantId("lnt");
tenant.setMap(new Tenant.Map());
passCustomParams(tenant);
Object o = new Object();
//String s = "Shot";
sendObjParam(o);
}
private static String hello(java.lang.String name) {
metro_ws_client.NewWebService_Service service = new metro_ws_client.NewWebService_Service();
metro_ws_client.NewWebService port = service.getNewWebServicePort();
return port.hello(name);
}
private static Object sendObjParam(java.lang.Object paramObj) {
com.metrows.NewWebService_Service service = new com.metrows.NewWebService_Service();
com.metrows.NewWebService port = service.getNewWebServicePort();
return port.sendObjParam(paramObj);
}
private static void passCustomParams(com.metrows.Tenant tenant) {
com.metrows.NewWebService_Service service = new com.metrows.NewWebService_Service();
com.metrows.NewWebService port = service.getNewWebServicePort();
port.passCustomParams(tenant);
}
}
在服务器启动期间,我得到以下异常(不是完整的堆栈跟踪,因为它是重复的):
WARNING: Unable to load class [com.sun.codemodel.JArrayClass$1] to check against the @HandlesTypes annotation of one or more ServletContentInitializers.
java.lang.ClassNotFoundException: com.sun.codemodel.JArrayClass$1
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:558)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1329)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:389)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:334)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Feb 13, 2012 4:46:50 PM org.apache.catalina.startup.ContextConfig checkHandlesTypes
WARNING: Unable to load class [com.sun.codemodel.JCodeModel$1] to check against the @HandlesTypes annotation of one or more ServletContentInitializers.
java.lang.ClassNotFoundException: com.sun.codemodel.JCodeModel$1
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:558)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1329)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:389)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:334)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Feb 13, 2012 4:46:50 PM org.apache.catalina.startup.ContextConfig checkHandlesTypes
WARNING: Unable to load class [com.sun.codemodel.JExpr$3] to check against the @HandlesTypes annotation of one or more ServletContentInitializers.
java.lang.ClassNotFoundException: com.sun.codemodel.JExpr$3
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2006)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:1969)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1858)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1826)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1812)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1306)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:896)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:322)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5103)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:558)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1329)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:389)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:334)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
现在对网络方法“hello”的调用是成功的,但是当调用“sendObjParam”时出现以下异常;此外,无法在客户端中创建 java.util.Map 并将其设置在租户对象中:
Hello Aao Thakur !!! !
Exception in thread "main" javax.xml.ws.WebServiceException: java.lang.ClassCastException: java.lang.Object cannot be cast to org.w3c.dom.Element
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:185)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy32.sendObjParam(Unknown Source)
at metro_ws_client.Metro_WS_Client.sendObjParam(Metro_WS_Client.java:35)
at metro_ws_client.Metro_WS_Client.main(Metro_WS_Client.java:22)
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to org.w3c.dom.Element
at com.sun.xml.internal.bind.v2.runtime.AnyTypeBeanInfo.serializeURIs(AnyTypeBeanInfo.java:138)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:665)
at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:141)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:321)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:687)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:263)
at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:89)
at com.sun.xml.internal.bind.api.Bridge.marshal(Bridge.java:130)
at com.sun.xml.internal.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:310)
at com.sun.xml.internal.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:131)
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:98)
at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:249)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:144)
... 14 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
请指导我如何将标准 Java 对象——具体或接口(interface)、具有非原始成员的自定义对象传递给 Web 服务?
最佳答案
您传递给 Web 服务客户端方法的对象需要由 JAXB 序列化。这至少意味着它们需要用 @XMLRootElement
进行注释。这当然意味着您不能传入 new Object()
(无论如何这几乎没有用)。
关于java - 将对象传递给 JAX WS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9262911/
Apache CXF 可以完成任务。但我想在没有任何 spring 依赖的情况下组合它。提前谢谢你! 最佳答案 JAX-WS 和 JAX-RS 都是 Java EE 6 的一部分.因此,您可以在不使用
Apache CXF 可以完成任务。但我想在没有任何 spring 依赖的情况下组合它。提前谢谢你! 最佳答案 JAX-WS 和 JAX-RS 都是 Java EE 6 的一部分.因此,您可以在不使用
所以我的意思是你有一个分类特征 $X$(假设你已经把它变成了整数)并说你想使用特征 $A$ 将它嵌入到某个维度中,其中 $A$ 是 arity x n_embed . 通常的做法是什么?使用 for
所以我的意思是你有一个分类特征 $X$(假设你已经把它变成了整数)并说你想使用特征 $A$ 将它嵌入到某个维度中,其中 $A$ 是 arity x n_embed . 通常的做法是什么?使用 for
我知道网上有很多文档主要描述技术差异。 但是我很想知道您更喜欢一种特定类型而不是其他类型的常见用例是什么? 这些偏好是因为集成模式/产品支持特定类型吗? 最佳答案 谢谢你的回答。然而实际用例差异以及何
我想将 CXF 与 Google Guice 集成。我已经在我的项目中使用 Guice,并且我想避免添加额外的依赖项。 CXF 是我的选择,因为要求之一是能够向服务用户提供 XML、JSON、JSON
来自 JSR-339: For simplicity, JAX-RS implementations are NOT REQUIRED to support processing groups oth
我开始使用 JAX WS 研究 Java Web 服务。我正在阅读的书的第一章展示了如何仅使用 java SE 构建和部署简单的 jax ws web 服务。特别是,Web 服务是通过 Endpoin
在 JAX 的快速入门教程中,我发现可以使用以下代码行为可微函数 fun 高效地计算 Hessian 矩阵: from jax import jacfwd, jacrev def hessian(fu
JAX-RS 提供了 StreamingOutput 接口(interface),我们可以实现它来对我们的响应主体进行原始流处理。 public interface StreamingOutput {
有没有办法获得java.lang.reflect.Method为给定的 @Path 调用的方法(用 HttpServletRequest 注释) ? 这是我的用例:我在 Java EE 中 Filte
我接到了一家公司的任务,该任务向我发送了一台已完成所有设置的虚拟机。任务是我必须创建一个 API 来从数据库中检索人员详细信息并显示它。 问题是,当我运行应用程序时,服务器返回一个包含 hello w
我有一个 POST 方法调用,它接受很少的表单参数。我希望 JAX-RS 能够处理不存在特定表单参数的情况。 示例: @POST @Produces (MediaType.APPLICATION_JS
我有 JAX-RS 网络应用程序,我想记录从获取请求到响应的时间量。在带有 servlet 过滤器的 Spring Boot 中很容易。但是我的应用程序中的过滤器无法正常工作: @Provider p
使用以下网址。 http://doma.in/context/resource/some/.../undefined 我想获取 ../resource 之后的路径名,即 /some/.../undef
我编写了 2 个 Web 服务,一个使用 Jax-WS,一个使用 Jax-RPC。他们只是返回一个字符串。 我使用 jMeter 进行了压力测试,奇怪的是,Jax-RPC 速度更快。 我什么时候才能在
我花了几个小时在嵌入式 Jetty 9.1.0.v20131115 和 RESTEasy 3.0.5.Final 中安装自定义登录服务。我的登录服务将在数据库中查找用户并为他们分配角色。它看起来像这样
有没有办法操纵jaxws中使用的编码器。 我喜欢发送一个在网络服务请求中提交的 cdata,为此我想在这里尝试类似描述的东西:http://odedpeer.blogspot.de/2010/07/j
我想从 java 服务器 (Restful Jax-rs) 发送图像。我的客户是安卓。 @GET public Response getUserImage() { byte[] image =new
我对网络服务很陌生。我找不到 JAX-WS 和 CXF 之间的区别。 据我了解,JAX-WS是java提供的规范,CXF是实现。 如果我错了,请纠正我。 最佳答案 是的,你是对的。 JAX-WS 是基
我是一名优秀的程序员,十分优秀!