本文整理汇总了Java中javax.xml.soap.SOAPConnection类的典型用法代码示例。如果您正苦于以下问题:Java SOAPConnection类的具体用法?Java SOAPConnection怎么用?Java SOAPConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SOAPConnection类属于javax.xml.soap包,在下文中一共展示了SOAPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callWebService
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
public void callWebService(String iccid, String businessValue) throws SOAPException, IOException, XWSSecurityException, Exception {
SOAPMessage request = createTerminalRequest(iccid, businessValue);
request = secureMessage(request);
// TODO
logger.info("Edit Terminal Request: ");
request.writeTo(System.out);
System.out.println("");
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(request, url);
// TODO
logger.info("Edit Terminal Response: ");
response.writeTo(System.out);
System.out.println("");
if (!response.getSOAPBody().hasFault()) {
writeTerminalResponse(response);
} else {
SOAPFault fault = response.getSOAPBody().getFault();
logger.error("Received SOAP Fault");
logger.error("SOAP Fault Code :" + fault.getFaultCode());
logger.error("SOAP Fault String :" + fault.getFaultString());
}
}
示例2: processRequest
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
// blocking
public <T> T processRequest(Object request, Class<T> responseClass, String soapUri, boolean needsAuthentification)
throws Exception {
SOAPConnection soapConnection = null;
try {
soapConnection = soapConnectionFactory.createConnection();
SOAPMessage soapMessage = processSoapMessage(request, needsAuthentification);
SOAPMessage soapResponse = soapConnection.call(soapMessage, soapUri);
// get new each time? - no
Unmarshaller unmarshaller = getUnmarshaller(responseClass);
return (T) unmarshaller.unmarshal(soapResponse.getSOAPBody().extractContentAsDocument());
} finally {
if (soapConnection != null) {
soapConnection.close();
}
}
}
示例3: callWebService
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
public String callWebService(String msisdn) throws SOAPException, IOException, XWSSecurityException, GetTermalIccidException {
SOAPMessage request = createTerminalRequest(msisdn);
request = secureMessage(request);
// TODO
logger.info("Get Terminals by msisdn Request: ");
request.writeTo(System.out);
System.out.println("");
SOAPConnection connection = connectionFactory.createConnection();
SOAPMessage response = connection.call(request, url);
// TODO
logger.info("Get Terminals by msisdn Response: ");
response.writeTo(System.out);
System.out.println("");
if (!response.getSOAPBody().hasFault()) {
return writeTerminalResponse(response);
} else {
SOAPFault fault = response.getSOAPBody().getFault();
logger.error("Received SOAP Fault");
logger.error("SOAP Fault Code :" + fault.getFaultCode());
logger.error("SOAP Fault String :" + fault.getFaultString());
throw new GetTermalIccidException(fault.getFaultCode() + "," + fault.getFaultString());
}
}
示例4: registerPatients
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
public Collection<ValidationErrorMessage> registerPatients(String username, String passwordHash, String url, Collection<Subject> subjects)
throws Exception {
log.info("Register patients initialized by: " + username + " on: " + url);
Collection<ValidationErrorMessage> ret = new ArrayList<>();
for (Subject subject : subjects) {
SOAPMessage soapMessage = requestFactory.createCreateSubject(username, passwordHash, subject);
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
SOAPMessage soapResponse = soapConnection.call(soapMessage, url + "/ws/studySubject/v1");
String error = parseRegisterSubjectsResponse(soapResponse);
if (error != null) {
String detailedErrorMessage = "Registering subject " + subject.getSsid() + " against instance " + url + " failed, OC error: " + error;
log.error(detailedErrorMessage);
ret.add(new ValidationErrorMessage(detailedErrorMessage));
}
}
log.info("Registered subjects against instance " + url + " completed, number of subjects:" +
subjects.size());
return ret;
}
示例5: testSendReceiveMessageWithEmptyNSPrefix
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Validated @Test
public void testSendReceiveMessageWithEmptyNSPrefix() throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPPart sPart = request.getSOAPPart();
SOAPEnvelope env = sPart.getEnvelope();
SOAPBody body = env.getBody();
//Namespace prefix is empty
body.addBodyElement(new QName("http://fakeNamespace2.org","echo"))
.addTextNode("This is some text");
SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage response = sCon.call(request, getAddress());
assertFalse(response.getAttachments().hasNext());
assertEquals(0, response.countAttachments());
String requestStr = printSOAPMessage(request);
String responseStr = printSOAPMessage(response);
assertTrue(responseStr.indexOf("echo") > -1);
sCon.close();
}
示例6: invoke
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
/**
* Marshals the inout arguments into a SOAPMessage
* and invokes the WebService.
* @param arguments the arguments for the WebService.
* @return the reply from the WebService.
* @throws SOAPException if any SOAP error occurs.
* @throws SOAPFaultException if any SOAPFault occurs.
* @throws JAXBException if any XML (un)marshalling error occurs.
*/
public Object invoke(Object... arguments) throws SOAPException, SOAPFaultException, JAXBException {
SOAPConnection connection = null;
try {
// Create a connection
connection = SOAPConnectionFactory.newInstance().createConnection();
// Create the SOAPMessage
SOAPMessage message = createSOAPMessage(arguments);
// Invoke the WebService
SOAPMessage response = invoke(connection, message);
// Unmarshal the response
return unmarshalResponse(response);
} finally {
// Always close the connection
if (connection != null) {
connection.close();
}
}
}
示例7: sendSoapMessage
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
/**
* sendSoapMessage Connect to the service, will log the request and response
*
* @param webServiceKey
* the key to locate which web service to use
* @param request
* - SoapMessage to send to the service
* @return - SoapMessage response
* @throws MalformedURLException
* - if there was an error creating the endpoint Connection
* @throws SOAPException
* - if there was an error creating the SOAP Connection
*/
public SOAPMessage sendSoapMessage(String webServiceKey, SOAPMessage request) throws MalformedURLException, SOAPException {
SOAPMessage response = null;
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
try {
WebService service = getWebService(webServiceKey);
logSOAPMessage(request, "SOAP Request");
URL endpoint = new URL(service.getEndPoint());
response = connection.call(request, endpoint);
logSOAPMessage(response, "SOAP Response");
} catch (Exception e) {
throw e;
} finally {
connection.close();
}
return response;
}
示例8: sendReceive
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
public SOAPMessage sendReceive(SOAPMessage msg, String URLAddress)
throws SOAPException, MalformedURLException{
setProxyFromINI(true);
URL endPoint = new URL(URLAddress);
SOAPMessage reply=null;
// TODO: set proxy ako treba
SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();
SOAPConnection con = factory.createConnection();
if(con==null){
if(MessagingEnvironment.DEBUG==1)
System.out.println("SOAPConnection failure!");
}else{
reply = con.call(msg, endPoint);
con.close();
if(MessagingEnvironment.DEBUG==1)
System.out.println("\nSending to: "+URLAddress+" success");
}
setProxyFromINI(false);
return reply;
}
示例9: testSoapConnectionGet
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testSoapConnectionGet() throws Exception
{
final String serviceURL = baseURL + "/greetMe";
SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
SOAPConnection con = conFac.createConnection();
URL endpoint = new URL(serviceURL);
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage msg = msgFactory.createMessage();
msg.getSOAPBody().addBodyElement(new QName("http://www.jboss.org/jbossws/saaj", "greetMe"));
SOAPMessage response = con.call(msg, endpoint);
QName greetMeResp = new QName("http://www.jboss.org/jbossws/saaj", "greetMeResponse");
Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(greetMeResp);
SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
assertNotNull(soapElement);
assertEquals(1, response.countAttachments());
}
示例10: testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ() throws Exception
{
try
{
//<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:throwSoapFaultException xmlns:ns2="http://server.exception.samples.jaxws.ws.test.jboss.org/"/></soap:Body></soap:Envelope>
SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
SOAPConnection con = conFac.createConnection();
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage msg = msgFactory.createMessage();
msg.getSOAPBody().addBodyElement(new QName(targetNS, "throwSoapFaultException"));
SOAPMessage response = con.call(msg, new URL(targetEndpoint + "Servlet"));
Element el = (Element)response.getSOAPBody().getChildElements().next();
assertEquals("Fault", el.getLocalName());
}
catch (Exception e)
{
fail(e);
}
}
示例11: testProviderMessage
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testProviderMessage() throws Exception
{
SOAPMessage reqMsg = getRequestMessage();
SOAPEnvelope reqEnv = reqMsg.getSOAPPart().getEnvelope();
URL epURL = baseURL;
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage resMsg = con.call(reqMsg, epURL);
SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = resEnv.getHeader();
if (soapHeader != null)
soapHeader.detachNode();
assertEquals(reqEnv, resEnv);
}
示例12: testProviderMessageNullResponse
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception
{
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));
URL epURL = baseURL;
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
SOAPMessage resMsg = con.call(reqMsg, epURL);
if (resMsg != null)
{
SOAPPart soapPart = resMsg.getSOAPPart();
//verify there's either nothing in the reply or at least the response body is empty
if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null)
{
SOAPBody soapBody = soapPart.getEnvelope().getBody();
assertFalse(soapBody.getChildElements().hasNext());
}
}
}
示例13: testLegalMessageAccess
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testLegalMessageAccess() throws Exception
{
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
String reqEnv =
"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
" <env:Header/>" +
" <env:Body>" +
" <ns1:echoString xmlns:ns1='" + targetNS + "'>" +
" <arg0>Hello</arg0>" +
" </ns1:echoString>" +
" </env:Body>" +
"</env:Envelope>";
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
URL epURL = new URL(baseURL + "/TestService");
SOAPMessage resMsg = con.call(reqMsg, epURL);
QName qname = new QName(targetNS, "echoStringResponse");
SOAPElement soapElement = (SOAPElement)resMsg.getSOAPBody().getChildElements(qname).next();
soapElement = (SOAPElement)soapElement.getChildElements(new QName("return")).next();
assertEquals("Hello", soapElement.getValue());
}
示例14: testIllegalMessageAccess
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception
{
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
String reqEnv =
"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
" <env:Header/>" +
" <env:Body>" +
" <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" +
" <String_1>Hello</String_1>" +
" </ns1:noWebMethod>" +
" </env:Body>" +
"</env:Envelope>";
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
URL epURL = new URL(baseURL + "/TestService");
SOAPMessage resMsg = con.call(reqMsg, epURL);
SOAPFault soapFault = resMsg.getSOAPBody().getFault();
assertNotNull("Expected SOAPFault", soapFault);
String faultString = soapFault.getFaultString();
assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
示例15: testSendMultipartSoapMessage
import javax.xml.soap.SOAPConnection; //导入依赖的package包/类
@Test
@RunAsClient
public void testSendMultipartSoapMessage() throws Exception {
final MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
final SOAPMessage msg = msgFactory.createMessage();
final SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(
new QName("urn:ledegen:soap-attachment:1.0", "echoImage"));
bodyElement.addTextNode("cid:" + IN_IMG_NAME);
final AttachmentPart ap = msg.createAttachmentPart();
ap.setDataHandler(getResource("saaj/jbws3857/" + IN_IMG_NAME));
ap.setContentId(IN_IMG_NAME);
msg.addAttachmentPart(ap);
final SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
final SOAPConnection connection = conFactory.createConnection();
final SOAPMessage response = connection.call(msg, new URL("http://" + baseURL.getHost()+ ":" + baseURL.getPort() + "/" + PROJECT_NAME + "/testServlet"));
final String contentTypeWeHaveSent = getBodyElementTextValue(response);
assertContentTypeStarts("multipart/related", contentTypeWeHaveSent);
}