Hi everyone,
I try to learn java and I want to make a ‘account panel’ where you can manage your wow account, like change password, teleport characters etc.
I need SOAP connection, may be somebody can explain or show how to pass those parameters in java:
‘uri’ => ‘urn:’. $soap_uri .‘’,
‘user_agent’ => ‘aframework’,
‘style’ => SOAP_RPC,
‘login’ => $soapUser,
‘password’ => $soapPass,
‘trace’ => 1,
‘exceptions’ => 0
with PHP it is very easy
final class SOAP {
private $conn = null;
function __construct($user, $pass, $host, $port, $uri) {
if(!$this->connect($user, $pass, $host, $port, $uri))
die(‘SOAP UNABLE CONNECT’);
}
private function connect($soapUser, $soapPass, $soapHost, $soapPort, $soap_uri) {
$this->conn = new SoapClient(null, array(
'uri' => 'urn:'. $soap_uri .'',
'user_agent' => 'aframework',
'style' => SOAP_RPC,
'login' => $soapUser,
'password' => $soapPass,
'trace' => 1,
'exceptions' => 0
)
);
if(is_soap_fault($this->conn)) {
$client = $this->conn;
throw new Exception('SOAP Error | Faultcode: '. $client->faultcode .' | Faultstring: '. $client->faultstring);
}
return true;
}
function disconnect() {
if($this->conn != null)
$this->conn = null;
else
return false;
return true;
}
function fetch($command) {
$client = $this->conn;
if($client == null)
return false;
$params = func_get_args();
array_shift($params);
$command = vsprintf($command, $params);
$client->executeCommand(new SoapParam($command, 'command'));
if(is_soap_fault($client))
throw new Exception('SOAP Error | Faultcode: '. $client->faultcode .' | Faultstring: '. $client->faultstring);
return $this->getResult($client->__getLastResponse());
}
private function getResult($XMLResponse) {
// echo 'SOAP:' . $XMLResponse;
$start = strpos($XMLResponse, '<?xml');
$end = strrpos($XMLResponse, '>');
$soapdata = substr($XMLResponse, $start, $end - $start + 1);
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $soapdata, $vals, $index);
xml_parser_free($xml_parser);
$result = array_key_exists('RESULT', $index) ? $vals[$index['RESULT'][0]]['value'] : null;
if(empty($result))
return 'SOAP DO NOT RESPOND!';
return $result;
}
}
Java code:
[CODE]
package com.example.newapp.framework.soap;
import javax.xml.soap.;
import javax.xml.transform.;
import javax.xml.transform.stream.*;
public class SOAP {
public static void main(String args[]) {
try {
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// soapConnection.
// Send SOAP Message to SOAP Server
// String url = “http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx”;
String url = “http://localhost:7878”;
// ‘uri’ => ‘urn:’. $soap_uri .‘’,
// ‘user_agent’ => ‘aframework’,
// ‘style’ => SOAP_RPC,
// ‘login’ => $soapUser,
// ‘password’ => $soapPass,
// ‘trace’ => 1,
// ‘exceptions’ => 0
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
// <?xml version="1.0" encoding="UTF-8"?>
// <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”
// xmlns:SOAP-ENC=“http://schemas.xmlsoap.org/soap/encoding/”
// xmlns:xsi=“http://www.w3.org/1999/XMLSchema-instance”
// xmlns:xsd=“http://www.w3.org/1999/XMLSchema”
// xmlns:ns1=“urn:TC”>
// <SOAP-ENV:Body SOAP-ENV:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”>
// SOAP-ENV:Fault
// SOAP-ENV:Client
// Method ‘example:VerifyEmail’ not implemented: method name or namespace not recognized
// </SOAP-ENV:Fault>
// </SOAP-ENV:Body>
// </SOAP-ENV:Envelope>
// Process the SOAP Response
printSOAPResponse(soapResponse);
soapConnection.close();
} catch (Exception e) {
System.err.println("Error occurred while sending SOAP Request to Server");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest() throws Exception {
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
String serverURI = "http://ws.cdyne.com/";
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("example", serverURI);
/*
Constructed SOAP Request Message:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<example:VerifyEmail>
<example:email>[email protected]</example:email>
<example:LicenseKey>123</example:LicenseKey>
</example:VerifyEmail>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("VerifyEmail", "example");
SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("email", "example");
soapBodyElem1.addTextNode("[email protected]");
SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("LicenseKey", "example");
soapBodyElem2.addTextNode("123");
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", serverURI + "VerifyEmail");
soapMessage.saveChanges();
/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();
return soapMessage;
}
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
}[/CODE]