标签: jax-ws

如何在Web服务调用期间拦截xml响应和请求?

我想知道在java webservice方法调用和响应中给出的xml中是否有一些巧妙的方法来拦截xml请求发送?我不想将这些xmls打印到标准输出,而是在某些字符串中"捕获"它们.

java jax-ws jaxb

3
推荐指数
1
解决办法
9966
查看次数

xsd:datetime和XmlGregorianCalendar导致NullPointerException

以下作品:

public Date getDate() {
    return date;
}
Run Code Online (Sandbox Code Playgroud)

并产生类似的东西:

<date>2010-03-23T17:43:50.879Z</date>
Run Code Online (Sandbox Code Playgroud)

我可以使用XmlGregorianCalendar返回xsd:date或xsd:time类型:

@XmlSchemaType(name="date")
public XmlGregorianCalendar getDate() {
    return date;
}
Run Code Online (Sandbox Code Playgroud)

它产生的东西如下:

<date>2010-03-23</date>
Run Code Online (Sandbox Code Playgroud)

但尝试返回xsd:datetime如下:

@XmlSchemaType(name="datetime")
public XmlGregorianCalendar getDate() {
     return date;
}
Run Code Online (Sandbox Code Playgroud)

导致此堆栈跟踪:

java.lang.NullPointerException
    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.checkXmlGregorianCalendarFieldRef(RuntimeBuiltinLeafInfoImpl.java:864)
    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.access$200(RuntimeBuiltinLeafInfoImpl.java:111)
    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$13.print(RuntimeBuiltinLeafInfoImpl.java:536)
...snip...
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)

根本没有提到我的代码.

我正在使用tomcat 6.0.24,java 1.6.0_16-b01

java datetime tomcat jax-ws jaxb

3
推荐指数
1
解决办法
9477
查看次数

Jax-ws,spring和SpringBeanAutowiringSupport

虽然在我的@Webservice类中我扩展了SpringBeanAutowiringSupport,但自动装配对于Spring 2.5,tomcat6来说并不起作用.

什么都没注入.

我在main方法中测试了那些bean自动装配,使用classpathcontext,一切都注入正常.但不适用于jax-ws端点.

你有想法吗?

java spring cxf jax-ws autowired

3
推荐指数
1
解决办法
2万
查看次数

具有默认值的Java JAX-RS自定义参数

假设我有这个(这只是一个例子):

@GET
@Path(value="address")
@Produces("application/json")
public Response getAddress(@QueryParam("user") User user){
  ...
}
Run Code Online (Sandbox Code Playgroud)

和用户是

class User{
...
 public static User valueOf(String user){
   if(user == null) return DEFAULT_USER;
   return dao.findById(user);
 }    
}
Run Code Online (Sandbox Code Playgroud)

如果我做/ api/address?user = amir一切正常,但想法是如果我没有为用户提供值,那么我想要使用DEFAULT_USER.但这实际上并没有调用valueOf.有没有办法来解决这个问题?

java jax-ws resteasy

3
推荐指数
1
解决办法
5000
查看次数

如何自定义JAX-WS生成的WSDL?

我正在使用JAX-WS和JAXB创建一个SOAP服务,通过注释类.我的服务实现如下所示:

@Stateless
@Local(WSApplicationService.class)
@WebService(name = "WSApplicationService", serviceName = "WSApplicationService")
@BindingType(SOAPBinding.SOAP11HTTP_BINDING)
public class WSApplicationServiceImpl implements WSApplicationService {

  @Override
  @WebMethod
  @WebResult(name = "reference")
  public long submitApplication(@WebParam(name = "application") ApplicationSubmission application) throws SOAPException {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

在提出这个问题之后,我了解到没有办法使用JAXB注释指定对输入数据的某些限制.但是,我需要将某些String属性限制为模式(主要是邮政编码和电话号码).因此,我希望自定义上面的类生成的WSDL.我找不到访问WSDL的方法.有没有办法覆盖或自定义JAX-WS生成的WSDL?

customization wsdl jax-ws jaxb

3
推荐指数
1
解决办法
5743
查看次数

Webservice响应命名空间与WSDL定义不匹配

我正在尝试使用JAX-WS连接到Web服务,JAX-WS的WSDL定义与从Web服务收到的实际响应不完全匹配.基本上,WSDL指示所有元素都是"urn:HPD_IncidentInterface_WS"命名空间的一部分,但实际的响应元素位于"urn:Port"命名空间中.这会导致JAX-WS抛出以下异常:

com.sun.xml.internal.ws.streaming.XMLStreamReaderException:意外的XML标记.预期:{urn:HPD_IncidentInterface_WS} HelpDesk_QueryList_ServiceResponse但找到:{urn:Port} HelpDesk_QueryList_ServiceResponse

我解决此问题的计划是下载WSDL,修改它以匹配实际响应中的命名空间,然后使用wsimport重新生成JAX-WS代码.但是,我很难弄清楚如何修改WSDL以使响应命名空间正确.基于我到目前为止所研究的内容,看起来我需要使用包含urn:port targetNamespace的wsdl:definition创建一个新的WSDL文件,然后将其导入到原始的WSDL文件中,但我不能似乎正确的语法.任何人都可以帮我纠正WSDL以匹配实际的Web服务响应吗?

以下是引用urn:Port命名空间的响应示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:HelpDesk_QueryList_ServiceResponse xmlns:ns0="urn:Port">
         <ns0:getListValues>
            <ns0:Assigned_Group>APP-eBiz-EP-L2</ns0:Assigned_Group>
            <ns0:Assigned_Group_Shift_Name/>
            <ns0:Assigned_Support_Company>Acme</ns0:Assigned_Support_Company>
            <ns0:Assigned_Support_Organization>Applications - eBusinessServices</ns0:Assigned_Support_Organization>
            <ns0:Assignee>Geoff Denning</ns0:Assignee>
            <ns0:Categorization_Tier_1>Issue</ns0:Categorization_Tier_1>
            <ns0:Categorization_Tier_2>Failure</ns0:Categorization_Tier_2>
            <ns0:Categorization_Tier_3/>
            <ns0:City>Mountain View</ns0:City>
            <ns0:Closure_Manufacturer/>
            <ns0:Closure_Product_Category_Tier1/>
            <ns0:Closure_Product_Category_Tier2/>
            <ns0:Closure_Product_Category_Tier3/>
            <ns0:Closure_Product_Model_Version/>
            <ns0:Closure_Product_Name/>
            <ns0:Company>Acme</ns0:Company>
            <ns0:Contact_Company>Acme</ns0:Contact_Company>
            <ns0:Contact_Sensitivity>Standard</ns0:Contact_Sensitivity>
            <ns0:Country>United States</ns0:Country>
            <ns0:Department>Mgmt Information Systems</ns0:Department>
            <ns0:Summary>Test summary</ns0:Summary>
            <ns0:Notes>Refer to the attached error screenshot.</ns0:Notes>
            <ns0:First_Name>Geoff</ns0:First_Name>
            <ns0:Impact>4-Minor/Localized</ns0:Impact>
            <ns0:Incident_Number>INC000000773346</ns0:Incident_Number>
            <ns0:Internet_E-mail>geoff@acme.com</ns0:Internet_E-mail>
            <ns0:Last_Name>Denning</ns0:Last_Name>
            <ns0:Manufacturer/>
            <ns0:Middle_Initial/>
            <ns0:Organization>IT-eBusiness</ns0:Organization>
            <ns0:Phone_Number>000-0000</ns0:Phone_Number>
            <ns0:Priority>Low</ns0:Priority>
            <ns0:Priority_Weight>2</ns0:Priority_Weight>
            <ns0:Product_Categorization_Tier_1>Software-Application</ns0:Product_Categorization_Tier_1>
            <ns0:Product_Categorization_Tier_2>eBusiness Services</ns0:Product_Categorization_Tier_2>
            <ns0:Product_Categorization_Tier_3>Test</ns0:Product_Categorization_Tier_3>
            <ns0:Product_Model_Version/>
            <ns0:Product_Name/>
            <ns0:Region>Americas</ns0:Region>
            <ns0:Reported_Source>Email</ns0:Reported_Source>
            <ns0:Resolution/>
            <ns0:Resolution_Category/>
            <ns0:Resolution_Category_Tier_2/>
            <ns0:Resolution_Category_Tier_3/>
            <ns0:Service_Type>User Service Restoration</ns0:Service_Type>
            <ns0:Site>Mountain View, …
Run Code Online (Sandbox Code Playgroud)

java websphere wsdl web-services jax-ws

3
推荐指数
1
解决办法
2万
查看次数

使用SimpleJaxWsServiceExporter的Spring Webservice

基于http://www.subshel​​l.com/en/subshel​​l/blog/article-Publishing-Webservices-with-Java-6-and-Spring-WS100.html我尝试在Tomcat 7上使用SimpleJaxWsServiceExporter运行Webservice.

浏览器中的localhost:8081/WSTest/TourWS?wsdl导致错误404.

TourWS.java

@WebService
@SOAPBinding(style=Style.DOCUMENT)
public interface TourWS {
@WebMethod
public void declareTours(ArrayList<TourWSEntity> tours);
@WebMethod
public void declareTour(TourWSEntity tour);
@WebMethod
public String whoAmI();
Run Code Online (Sandbox Code Playgroud)

}

TourWSImpl.java

@WebService(serviceName="TourWS")
public class TourWSImpl implements TourWS {
public TourWSImpl(){}

@Override
public void declareTours(ArrayList<TourWSEntity> tours) {
    // impl
}

@Override
public void declareTour(TourWSEntity tour) {
    // impl
}

@Override
public String whoAmI(){
    return "JAX-WS Web Service - TourWS";
}
Run Code Online (Sandbox Code Playgroud)

弹簧-WS-servlet.xml中

<beans ...>
<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:8081/" />
</bean>
<bean id="tourWSImpl" class="tour.spring.ws.impl.TourWSImpl" /> …
Run Code Online (Sandbox Code Playgroud)

spring web-services jax-ws

3
推荐指数
1
解决办法
5417
查看次数

如何使用wsimport生成@HandlerChain

我正在使用wsimport(JAX-WS 2.1.3)从WSDL生成Java,并且需要使它生成@HandlerChain注释.所以我创建了一个JAX-WS绑定文件:

<jaxws:bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:javaee="http://java.sun.com/xml/ns/javaee"
wsdlLocation="../etc/MessageStudio.wsdl">

<jaxws:bindings node="wsdl:definitions">
    <javaee:handler-chain>
        <javaee:handler-chain-name>StrongmailHandlers</javaee:handler-chain-name>               
            <javaee:handler>
                <javaee:handler-name>OrganizationTokenHandler</javaee:handler-name>         
                <javaee:handler-class>com.bossmedia.strongmailadapter.deliveryadapter.OrganizationTokenHandler</javaee:handler-class>           
            </javaee:handler>                     
    </javaee:handler-chain>
</jaxws:bindings>
Run Code Online (Sandbox Code Playgroud)

并运行wsimport Ant任务:

 <wsimport 
        wsdl="../etc/MessageStudio.wsdl"
        sourcedestdir="../src/gen"
        destdir="../classes"
        verbose="false"
        binding="../etc/jaxws.bindings.xml">
 </wsimport>
Run Code Online (Sandbox Code Playgroud)

但是我没有注释,也没有处理程序链XML文件.谷歌搜索只找到我改变包,方法和参数的解决方案以及我复制XML 的JAX-WS RI页面.

你能帮助我找到我配置中的缺陷或其他方式,缺少修改生成的代码,让我的处理程序进入链中吗?

java jax-ws handlers wsimport

3
推荐指数
1
解决办法
5452
查看次数

无法找到JAX-WS架构http://jax-ws.dev.java.net/spring/servlet.xsd

我正在使用Spring框架实现JAX-WS.

以下是我的Spring applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://jax-ws.dev.java.net/spring/core
    http://jax-ws.dev.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    http://jax-ws.dev.java.net/spring/servlet.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    ">
Run Code Online (Sandbox Code Playgroud)

但是,Eclipse抱怨道:

引用文件包含错误(http://jax-ws.dev.java.net/spring/servlet.xsd).

经过调查,我找到了URL:http: //jax-ws.dev.java.net/spring/servlet.xsd 不存在.相反,它似乎转移到:http: //jax-ws.java.net/spring/servlet.xsd(您可以在浏览器中打开此链接)

因此,我更新XSD架构URL从 http://jax-ws.dev.java.net/spring/servlet.xsdhttp://jax-ws.java.net/spring/servlet.xsd

现在我的applicationContext.xml看起来像这样:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns:ws="http://jax-ws.dev.java.net/spring/core"
xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://jax-ws.dev.java.net/spring/core
    http://jax-ws.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    http://jax-ws.java.net/spring/servlet.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    ">
Run Code Online (Sandbox Code Playgroud)

实际上,通过此更改,Eclipse错误消失了.问题是在Tomcat 7中启动Web服务后,我得到以下运行时错误:

org.xml.sax.SAXParseException; lineNumber:20; columnNumber:29; schema_reference.4:无法读取模式文档" http://jax-ws.java.net/spring/servlet.xsd ",因为1)找不到该文档; 2)文件无法阅读; 3)文档的根元素不是.at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:99) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:433)

请指教.

非常感谢你.问候,

java spring web-services jax-ws

3
推荐指数
1
解决办法
1万
查看次数

Jax-WS Web服务如何工作?每个请求一个端点?

我试图了解Jax-WS Web服务如何工作,但无法找到有关它们细节的任何资源.举例来说:

我使用Jax-WS注释创建了一个非常简单的Java Web服务,就像这样

@WebService(name = "MyService", serviceName = "MyService", portName = "MyServicePort")
public class MyService {

    private int val;

    public MyService() {
        val = 0;
    }

    @WebMethod(action = "setVal")
    public void setVal(@WebParam(name = "arg") int arg) {
        val = arg;
    }

    @WebMethod(action = "getVal")
    public int getVal() {
        return val;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我从中生成一个Web服务(比如说使用WS-Gen),那么构建一个客户端并从单个客户端进行以下调用:setVal(5),getVal()将返回给客户端的值是什么?为什么?

如果客户端A呼叫setVal(5),而客户端B呼叫getVal(),将返回给客户端的值是什么?为什么?

当然,我可以自己构建一个Web服务并对其进行测试,但我希望能够通过探索来解决问题.Jax-Ws是否为每个请求创建了带注释类的新实例?它是否以某种方式将相同的源映射到相同的带注释的类实例?它只是将所有请求映射到带注释的类的单例实例吗?是否存在以某种方式选择的有限注释类实例池?

java web-services jax-ws

3
推荐指数
1
解决办法
1619
查看次数