java soap协议头_java – 服务器无法识别HTTP标头“SOAPAction”的值

在使用Java发送SOAP请求时遇到问题,服务器返回错误,指出无法识别HTTP头'SOAPAction'的值。虽然用SoapUI发送相同的请求能正常工作。问题在于Java代码创建的SOAP请求与SoapUI的不同。文章中展示了Java代码和相关类结构,尝试通过设置SOAPAction解决此问题,但未成功。
摘要由CSDN通过智能技术生成

当我向服务器发送SOAP请求时,它返回以下错误,尽管我使用SoapUI发送类似请求并且可以正常工作.我似乎需要将我的SOAP请求更改为我使用SoapUI发送的请求. WSDL是here.

[ truncated ] System.Web.Services.Protocols.SoapException : The value of the

HTTP header ' SOAPAction ' was not recognized by the server . \ r \ n at

System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest ( )

\ r \ n at System.Web.Servic

我正在使用Java发送以下请求

MetaSearch>falseMetaSearch>

我可以使用SoapUI发送以下请求,它可以工作

MetaSearch>falseMetaSearch>

我不知道如何使用Java创建的请求与我使用SoapUI发送的请求相同.

SearchFlights

@XmlRootElement(name = "SearchFlights")

@XmlAccessorType(XmlAccessType.FIELD)

public class SearchFlights {

@XmlElement(name = "SoapMessage")

private SoapMessage soapMessage;

getter and setter

的SOAPMessage

@XmlRootElement(name = "SoapMessage")

@XmlAccessorType(XmlAccessType.FIELD)

public class SoapMessage {

@XmlElement(name = "Username")

private String username;

@XmlElement(name = "Password")

private String password;

@XmlElement(name = "LanguageCode")

private String languageCode;

@XmlElement(name = "Request")

private Request request;

getters and setters

请求

@XmlRootElement(name = "Request")

@XmlAccessorType(XmlAccessType.FIELD)

public class Request {

@XmlElement(name = "Departure")

private String departure;

@XmlElement(name = "Destination")

private String destination;

@XmlElement(name = "DepartureDate")

private String departureDate;

@XmlElement(name = "ReturnDate")

private String returnDate;

@XmlElement(name = "NumADT")

private int numADT;

@XmlElement(name = "NumINF")

private int numInf;

@XmlElement(name = "NumCHD")

private int numCHD;

@XmlElement(name = "CurrencyCode")

private String currencyCode;

@XmlElement(name = "WaitForResult")

private boolean waitForResult;

@XmlElement(name = "NearByDepartures")

private boolean nearByDepartures;

@XmlElement(name = "NearByDestinations")

private boolean nearByDestinations;

@XmlElement(name = "RROnly")

private boolean rronly;

@XmlElement(name = "MetaSearch")

private boolean MetaSearch;

getters and setters

package-info.java

@XmlSchema(

namespace = "ElsyArres.API",elementFormDefault = XmlNsForm.QUALIFIED)

package com.myproject.flights.wegolo;

import javax.xml.bind.annotation.XmlNsForm;

import javax.xml.bind.annotation.XmlSchema;

jaxb.in​​dex

SearchFlights

Flight

Flights

Leg

Legs

Outbound

Request

Response

SoapMessage

代码发送请求

import javax.xml.soap.MessageFactory;

import javax.xml.soap.SOAPConstants;

import org.springframework.oxm.jaxb.Jaxb2Marshaller;

import org.springframework.stereotype.Service;

import org.springframework.web.client.RestClientException;

import org.springframework.web.client.RestTemplate;

import org.springframework.ws.client.core.WebServiceTemplate;

import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;

......

// populate searchFlights and other classes to create request

try {

SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(

MessageFactory.newInstance());

messageFactory.afterPropertiesSet();

WebServiceTemplate webServiceTemplate = new WebServiceTemplate(

messageFactory);

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

marshaller.setContextPath("com.myproject.flights.wegolo");

marshaller.afterPropertiesSet();

webServiceTemplate.setMarshaller(marshaller);

webServiceTemplate.afterPropertiesSet();

Response response = (Response) webServiceTemplate

.marshalSendAndReceive(

"http://www5v80.elsyarres.net/service.asmx",searchFlights);

Response msg = (Response) response;

System.err.println("Wegolo >>>"

+ msg.getFlights().getFlight().size());

} catch (Exception s) {

s.printStackTrace();

}

更新

我删除了package-info.java并设法使用建议的代码,但它仍然发送相同的标头.

Response response = (Response) webServiceTemplate

.marshalSendAndReceive(

"http://www5v80.elsyarres.net/service.asmx",searchFlights,new WebServiceMessageCallback() {

public void doWithMessage(WebServiceMessage message)

{

((SoapMessage)message).setSoapAction("http://www5v80.elsyarres.net/searchFlights");

}

}

);

d3ddb2d1c49c0534d7e4cb5b178dacd2.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值