Eclipse 使用SOAPUI作为一种网关
我想问您是否可以在SOAPUI中更改模拟响应,并将其链接到模拟服务所基于的真实web服务操作 我需要这样做,因为在SOAPUI中,我可以访问外部Web服务;但出于安全/配置方面的原因,我无法在Eclipse的本地代码中访问此外部Web服务(我在Eclipse中尝试了几种代理配置,但都没有成功) 我要做的是将到达模拟服务的请求传递到原始web服务,并返回响应,而不进行任何操作。您可以在SOAPUI中创建模拟服务,将请求重定向到第三方服务,如下所示: 首先在项目中创建mockService:右键单击项目>新建SOAP mockService 然后在其上创建模拟操作:右键单击您的模拟服务>新建模拟操作 在mockOperation中创建了一个请求,打开它并将下面的代码作为响应:Eclipse 使用SOAPUI作为一种网关,eclipse,web-services,groovy,soapui,Eclipse,Web Services,Groovy,Soapui,我想问您是否可以在SOAPUI中更改模拟响应,并将其链接到模拟服务所基于的真实web服务操作 我需要这样做,因为在SOAPUI中,我可以访问外部Web服务;但出于安全/配置方面的原因,我无法在Eclipse的本地代码中访问此外部Web服务(我在Eclipse中尝试了几种代理配置,但都没有成功) 我要做的是将到达模拟服务的请求传递到原始web服务,并返回响应,而不进行任何操作。您可以在SOAPUI中创建模拟服务,将请求重定向到第三方服务,如下所示: 首先在项目中创建mockService:右键单击
${myResponse}
。此名称绑定到一个变量,该变量将用脚本填充
最后打开mockOperation并使用以下脚本点击第三方服务重定向原始请求:
final HttpURLConnection connection = 'http://yourService:8080'.toURL().openConnection()
connection.setDoOutput(true)
// copy the headers
mockRequest.getRequestHeaders().each { name, value ->
connection.setRequestProperty(name,value.toString())
}
// write the request
connection.outputStream.withWriter { Writer writer ->
writer << mockRequest.requestContent
}
// get the response
String response = connection.inputStream.withReader { Reader reader -> reader.text }
// set the response in your variable
requestContext.myResponse = response
final-HttpURLConnection='1〕http://yourService:8080'.toURL().openConnection()
connection.setDoOutput(真)
//复制标题
mockRequest.getRequestHeaders()。每个{名称,值->
connection.setRequestProperty(名称、值.toString())
}
//写下请求
connection.outputStream.withWriter{Writer-Writer->
writer reader.text}
//在变量中设置响应
requestContext.myResponse=response
希望这能有所帮助,我最终将“分派”改为脚本并添加了以下脚本:
// import all the namespaces to trim the lines of codes
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.impl.wsdl.WsdlSubmitContext
import com.eviware.soapui.impl.wsdl.WsdlSubmit
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.mock.MockResponse
// get reference to project
WsdlProject project = (WsdlProject)mockOperation.mockService.project
// get reference to request
WsdlRequest request = (WsdlRequest)project.interfaces["TheRealWebService"].operations["TheRealOperation"].getRequestByName("TheRealRequest")
// set request content from incoming mockRequest
request.setRequestContent(mockRequest.getRequestContent())
// submit request asynchronously
WsdlSubmit submit=request.submit( new WsdlSubmitContext( request ), false )
// wait for the response
Response response = submit.getResponse();
// get reference to MockResponse
MockResponse mockResponse=mockOperation.getMockResponseByName("Response1")
// set the mock response content from response received by the request.
mockResponse.setResponseContent(response.getContentAsString())
你查过soapui的吗?是的,我查过,但我还没有找到我需要的东西。这似乎是一个正确的答案;但我得到一个java.net.SocketException:套接字未连接。(我尝试了几次代理设置都没有成功)@webmeiker我知道你可能无法。。。但是你能分享服务的url来复制你的
java.net.SocketException
?没关系,我会给你奖金的。谢谢你的时间@webmeiker谢谢:)
。。。但是这对你不起作用?如果你需要更多的帮助,告诉我。我在这里提出一个新问题:(以防你想再次帮助我)