/**
*
* Copyright (c) Microsoft and contributors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.
package com.microsoft.windowsazure.management.network;
import com.microsoft.windowsazure.core.ServiceOperations;
import com.microsoft.windowsazure.core.pipeline.apache.CustomHttpDelete;
import com.microsoft.windowsazure.core.utils.BOMInputStream;
import com.microsoft.windowsazure.core.utils.StreamUtils;
import com.microsoft.windowsazure.core.utils.XmlUtility;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.network.models.GatewayConnectDisconnectOrTestParameters;
import com.microsoft.windowsazure.management.network.models.GatewayConnectivityState;
import com.microsoft.windowsazure.management.network.models.GatewayCreateParameters;
import com.microsoft.windowsazure.management.network.models.GatewayEvent;
import com.microsoft.windowsazure.management.network.models.GatewayGenerateVpnClientPackageParameters;
import com.microsoft.windowsazure.management.network.models.GatewayGetDeviceConfigurationScriptParameters;
import com.microsoft.windowsazure.management.network.models.GatewayGetDeviceConfigurationScriptResponse;
import com.microsoft.windowsazure.management.network.models.GatewayGetOperationStatusResponse;
import com.microsoft.windowsazure.management.network.models.GatewayGetResponse;
import com.microsoft.windowsazure.management.network.models.GatewayGetSharedKeyResponse;
import com.microsoft.windowsazure.management.network.models.GatewayListConnectionsResponse;
import com.microsoft.windowsazure.management.network.models.GatewayListSupportedDevicesResponse;
import com.microsoft.windowsazure.management.network.models.GatewayOperationResponse;
import com.microsoft.windowsazure.management.network.models.GatewayOperationStatus;
import com.microsoft.windowsazure.management.network.models.GatewayResetSharedKeyParameters;
import com.microsoft.windowsazure.management.network.models.GatewaySetSharedKeyParameters;
import com.microsoft.windowsazure.management.network.models.GatewayType;
import com.microsoft.windowsazure.tracing.ClientRequestTrackingHandler;
import com.microsoft.windowsazure.tracing.CloudTracing;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.util.Calendar;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.xml.bind.DatatypeConverter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/**
* The Network Management API includes operations for managing the gateways for
* your subscription. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154113.aspx for more
* information)
*/
public class GatewayOperationsImpl implements ServiceOperations<NetworkManagementClientImpl>, GatewayOperations {
/**
* Initializes a new instance of the GatewayOperationsImpl class.
*
* @param client Reference to the service client.
*/
GatewayOperationsImpl(NetworkManagementClientImpl client) {
this.client = client;
}
private NetworkManagementClientImpl client;
/**
* Gets a reference to the
* microsoft.windowsazure.management.network.NetworkManagementClientImpl.
* @return The Client value.
*/
public NetworkManagementClientImpl getClient() {
return this.client;
}
/**
* To connect to, disconnect from, or test your connection to a local
* network site, access the connection resource representing the local
* network and specify Connect, Disconnect or Test to perform the desired
* operation. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkSiteName Required. The name of the site to connect to.
* @param parameters Required. Parameters supplied to the Begin Connect
* Disconnect Or Testing Gateway operation.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginConnectDisconnectOrTestingAsync(final String networkName, final String localNetworkSiteName, final GatewayConnectDisconnectOrTestParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginConnectDisconnectOrTesting(networkName, localNetworkSiteName, parameters);
}
});
}
/**
* To connect to, disconnect from, or test your connection to a local
* network site, access the connection resource representing the local
* network and specify Connect, Disconnect or Test to perform the desired
* operation. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkSiteName Required. The name of the site to connect to.
* @param parameters Required. Parameters supplied to the Begin Connect
* Disconnect Or Testing Gateway operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginConnectDisconnectOrTesting(String networkName, String localNetworkSiteName, GatewayConnectDisconnectOrTestParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (localNetworkSiteName == null) {
throw new NullPointerException("localNetworkSiteName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkSiteName", localNetworkSiteName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "beginConnectDisconnectOrTestingAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/connection/" + localNetworkSiteName.trim();
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpPut httpRequest = new HttpPut(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document requestDoc = documentBuilder.newDocument();
Element updateConnectionElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "UpdateConnection");
requestDoc.appendChild(updateConnectionElement);
Element operationElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Operation");
operationElement.appendChild(requestDoc.createTextNode(parameters.getOperation().toString()));
updateConnectionElement.appendChild(operationElement);
if (parameters.getIPAddress() != null) {
Element iPAddressElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "IPAddress");
iPAddressElement.appendChild(requestDoc.createTextNode(parameters.getIPAddress().getHostAddress()));
updateConnectionElement.appendChild(iPAddressElement);
}
DOMSource domSource = new DOMSource(requestDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);
requestContent = stringWriter.toString();
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_ACCEPTED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
documentBuilderFactory2.setNamespaceAware(true);
DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Begin Creating Virtual network Gateway operation creates a new
* network gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Begin Creating
* Virtual Network Gateway operation.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginCreatingAsync(final String networkName, final GatewayCreateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginCreating(networkName, parameters);
}
});
}
/**
* The Begin Creating Virtual network Gateway operation creates a new
* network gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Begin Creating
* Virtual Network Gateway operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginCreating(String networkName, GatewayCreateParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "beginCreatingAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpPost httpRequest = new HttpPost(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document requestDoc = documentBuilder.newDocument();
Element createGatewayParametersElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "CreateGatewayParameters");
requestDoc.appendChild(createGatewayParametersElement);
Element gatewayTypeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "gatewayType");
gatewayTypeElement.appendChild(requestDoc.createTextNode(parameters.getGatewayType().toString()));
createGatewayParametersElement.appendChild(gatewayTypeElement);
DOMSource domSource = new DOMSource(requestDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);
requestContent = stringWriter.toString();
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_CREATED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
documentBuilderFactory2.setNamespaceAware(true);
DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Begin Deleting Virtual Network Gateway operation deletes a network
* gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginDeletingAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginDeleting(networkName);
}
});
}
/**
* The Begin Deleting Virtual Network Gateway operation deletes a network
* gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginDeleting(String networkName) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "beginDeletingAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
CustomHttpDelete httpRequest = new CustomHttpDelete(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_ACCEPTED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Begin Failover Virtual Network Gateway operation causes a network
* gateway failover for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network in Azure.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginFailoverAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginFailover(networkName);
}
});
}
/**
* The Begin Failover Virtual Network Gateway operation causes a network
* gateway failover for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network in Azure.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginFailover(String networkName) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "beginFailoverAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
CustomHttpDelete httpRequest = new CustomHttpDelete(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = "<" + "?" + "xml version=\"1.0\" encoding=\"utf-8\"" + "?" + "><UpdateGateway xmlns=\"http://schemas.microsoft.com/windowsazure\"><UpdateGatewayOperation>Failover</UpdateGatewayOperation></UpdateGateway>";
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_ACCEPTED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Begin Reset Virtual Network Gateway Shared Key operation resets the
* shared key on the virtual network gateway for the specified virtual
* network connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. Parameters supplied to the Begin Virtual
* Network Gateway Reset Shared Key request.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginResetSharedKeyAsync(final String networkName, final String localNetworkName, final GatewayResetSharedKeyParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginResetSharedKey(networkName, localNetworkName, parameters);
}
});
}
/**
* The Begin Reset Virtual Network Gateway Shared Key operation resets the
* shared key on the virtual network gateway for the specified virtual
* network connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. Parameters supplied to the Begin Virtual
* Network Gateway Reset Shared Key request.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginResetSharedKey(String networkName, String localNetworkName, GatewayResetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (localNetworkName == null) {
throw new NullPointerException("localNetworkName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkName", localNetworkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "beginResetSharedKeyAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/connection/" + localNetworkName.trim() + "/sharedkey";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpPut httpRequest = new HttpPut(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document requestDoc = documentBuilder.newDocument();
Element resetSharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "ResetSharedKey");
requestDoc.appendChild(resetSharedKeyElement);
Element keyLengthElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "KeyLength");
keyLengthElement.appendChild(requestDoc.createTextNode(Integer.toString(parameters.getKeyLength())));
resetSharedKeyElement.appendChild(keyLengthElement);
DOMSource domSource = new DOMSource(requestDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);
requestContent = stringWriter.toString();
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_ACCEPTED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
documentBuilderFactory2.setNamespaceAware(true);
DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Begin Set Virtual Network Gateway Shared Key operation sets the
* shared key on the virtual network gateway for the specified virtual
* network connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. Parameters supplied to the Begin Virtual
* Network Gateway Set Shared Key request.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> beginSetSharedKeyAsync(final String networkName, final String localNetworkName, final GatewaySetSharedKeyParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return beginSetSharedKey(networkName, localNetworkName, parameters);
}
});
}
/**
* The Begin Set Virtual Network Gateway Shared Key operation sets the
* shared key on the virtual network gateway for the specified virtual
* network connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. Parameters supplied to the Begin Virtual
* Network Gateway Set Shared Key request.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse beginSetSharedKey(String networkName, String localNetworkName, GatewaySetSharedKeyParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (localNetworkName == null) {
throw new NullPointerException("localNetworkName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkName", localNetworkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "beginSetSharedKeyAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/connection/" + localNetworkName.trim() + "/sharedkey";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpPost httpRequest = new HttpPost(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document requestDoc = documentBuilder.newDocument();
Element sharedKeyElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "SharedKey");
requestDoc.appendChild(sharedKeyElement);
if (parameters.getValue() != null) {
Element valueElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Value");
valueElement.appendChild(requestDoc.createTextNode(parameters.getValue()));
sharedKeyElement.appendChild(valueElement);
}
DOMSource domSource = new DOMSource(requestDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);
requestContent = stringWriter.toString();
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_ACCEPTED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
documentBuilderFactory2.setNamespaceAware(true);
DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* To connect to, disconnect from, or test your connection to a local
* network site, access the connection resource representing the local
* network and specify Connect, Disconnect or Test to perform the desired
* operation. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkSiteName Required. The name of the site to connect to.
* @param parameters Required. Parameters supplied to the Connect Disconnect
* Or Testing Gateway operation.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> connectDisconnectOrTestAsync(final String networkName, final String localNetworkSiteName, final GatewayConnectDisconnectOrTestParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return connectDisconnectOrTest(networkName, localNetworkSiteName, parameters);
}
});
}
/**
* To connect to, disconnect from, or test your connection to a local
* network site, access the connection resource representing the local
* network and specify Connect, Disconnect or Test to perform the desired
* operation. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154107.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkSiteName Required. The name of the site to connect to.
* @param parameters Required. Parameters supplied to the Connect Disconnect
* Or Testing Gateway operation.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse connectDisconnectOrTest(String networkName, String localNetworkSiteName, GatewayConnectDisconnectOrTestParameters parameters) throws InterruptedException, ExecutionException, ServiceException, IOException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkSiteName", localNetworkSiteName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "connectDisconnectOrTestAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginConnectDisconnectOrTestingAsync(networkName, localNetworkSiteName, parameters).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
/**
* The Create Virtual network Gateway operation creates a new network
* gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Create Virtual
* Network Gateway operation.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> createAsync(final String networkName, final GatewayCreateParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return create(networkName, parameters);
}
});
}
/**
* The Create Virtual network Gateway operation creates a new network
* gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154119.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Create Virtual
* Network Gateway operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse create(String networkName, GatewayCreateParameters parameters) throws IOException, ServiceException, ParserConfigurationException, SAXException, InterruptedException, ExecutionException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "createAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginCreatingAsync(networkName, parameters).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
/**
* The Delete Virtual Network Gateway operation deletes a network gateway
* for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> deleteAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return delete(networkName);
}
});
}
/**
* The Delete Virtual Network Gateway operation deletes a network gateway
* for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154129.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse delete(String networkName) throws IOException, ServiceException, ParserConfigurationException, SAXException, InterruptedException, ExecutionException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "deleteAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginDeletingAsync(networkName).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
/**
* The Failover Virtual Network Gateway operation causes a network gateway
* failover for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network in Azure.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> failoverAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return failover(networkName);
}
});
}
/**
* The Failover Virtual Network Gateway operation causes a network gateway
* failover for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154118.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network in Azure.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse failover(String networkName) throws InterruptedException, ExecutionException, ServiceException, IOException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "failoverAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginFailoverAsync(networkName).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
/**
* The Generate VPN Client Package operation creates a VPN client package
* for the specified virtual network and gateway in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/dn205126.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Generate VPN
* Client Package operation.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayOperationResponse> generateVpnClientPackageAsync(final String networkName, final GatewayGenerateVpnClientPackageParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayOperationResponse>() {
@Override
public GatewayOperationResponse call() throws Exception {
return generateVpnClientPackage(networkName, parameters);
}
});
}
/**
* The Generate VPN Client Package operation creates a VPN client package
* for the specified virtual network and gateway in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/dn205126.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. Parameters supplied to the Generate VPN
* Client Package operation.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayOperationResponse generateVpnClientPackage(String networkName, GatewayGenerateVpnClientPackageParameters parameters) throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "generateVpnClientPackageAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/vpnclientpackage";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpPost httpRequest = new HttpPost(url);
// Set Headers
httpRequest.setHeader("Content-Type", "application/xml");
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Serialize Request
String requestContent = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document requestDoc = documentBuilder.newDocument();
Element vpnClientParametersElement = requestDoc.createElementNS("", "VpnClientParameters");
requestDoc.appendChild(vpnClientParametersElement);
Element processorArchitectureElement = requestDoc.createElementNS("", "ProcessorArchitecture");
processorArchitectureElement.appendChild(requestDoc.createTextNode(parameters.getProcessorArchitecture().toString()));
vpnClientParametersElement.appendChild(processorArchitectureElement);
DOMSource domSource = new DOMSource(requestDoc);
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(domSource, streamResult);
requestContent = stringWriter.toString();
StringEntity entity = new StringEntity(requestContent);
httpRequest.setEntity(entity);
httpRequest.setHeader("Content-Type", "application/xml");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_CREATED) {
ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayOperationResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayOperationResponse();
DocumentBuilderFactory documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
documentBuilderFactory2.setNamespaceAware(true);
DocumentBuilder documentBuilder2 = documentBuilderFactory2.newDocumentBuilder();
Document responseDoc = documentBuilder2.parse(new BOMInputStream(responseContent));
Element gatewayOperationAsyncResponseElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperationAsyncResponse");
if (gatewayOperationAsyncResponseElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationAsyncResponseElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setOperationId(idInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Get Virtual Network Gateway operation gets information about the
* network gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154109.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public Future<GatewayGetResponse> getAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetResponse>() {
@Override
public GatewayGetResponse call() throws Exception {
return get(networkName);
}
});
}
/**
* The Get Virtual Network Gateway operation gets information about the
* network gateway for the specified virtual network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154109.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public GatewayGetResponse get(String networkName) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "getAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayGetResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayGetResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element gatewayElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Gateway");
if (gatewayElement != null) {
Element stateElement = XmlUtility.getElementByTagNameNS(gatewayElement, "http://schemas.microsoft.com/windowsazure", "State");
if (stateElement != null) {
String stateInstance;
stateInstance = stateElement.getTextContent();
result.setState(stateInstance);
}
Element vIPAddressElement = XmlUtility.getElementByTagNameNS(gatewayElement, "http://schemas.microsoft.com/windowsazure", "VIPAddress");
if (vIPAddressElement != null) {
InetAddress vIPAddressInstance;
vIPAddressInstance = InetAddress.getByName(vIPAddressElement.getTextContent());
result.setVipAddress(vIPAddressInstance);
}
Element lastEventElement = XmlUtility.getElementByTagNameNS(gatewayElement, "http://schemas.microsoft.com/windowsazure", "LastEvent");
if (lastEventElement != null) {
GatewayEvent lastEventInstance = new GatewayEvent();
result.setLastEvent(lastEventInstance);
Element timestampElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Timestamp");
if (timestampElement != null) {
Calendar timestampInstance;
timestampInstance = DatatypeConverter.parseDateTime(timestampElement.getTextContent());
lastEventInstance.setTimestamp(timestampInstance);
}
Element idElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Id");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
lastEventInstance.setId(idInstance);
}
Element messageElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Message");
if (messageElement != null) {
String messageInstance;
messageInstance = messageElement.getTextContent();
lastEventInstance.setMessage(messageInstance);
}
Element dataElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Data");
if (dataElement != null) {
String dataInstance;
dataInstance = dataElement.getTextContent();
lastEventInstance.setData(dataInstance);
}
}
Element gatewayTypeElement = XmlUtility.getElementByTagNameNS(gatewayElement, "http://schemas.microsoft.com/windowsazure", "GatewayType");
if (gatewayTypeElement != null) {
GatewayType gatewayTypeInstance;
gatewayTypeInstance = GatewayType.valueOf(gatewayTypeElement.getTextContent());
result.setGatewayType(gatewayTypeInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Get Device Configuration Script operation returns a script that you
* can use to configure local VPN devices to connect to the gateway. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154115.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. The parameters for the Get Device
* Configuration Script operation.
* @return The configuration script returned from the get device
* configuration script operation.
*/
@Override
public Future<GatewayGetDeviceConfigurationScriptResponse> getDeviceConfigurationScriptAsync(final String networkName, final GatewayGetDeviceConfigurationScriptParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetDeviceConfigurationScriptResponse>() {
@Override
public GatewayGetDeviceConfigurationScriptResponse call() throws Exception {
return getDeviceConfigurationScript(networkName, parameters);
}
});
}
/**
* The Get Device Configuration Script operation returns a script that you
* can use to configure local VPN devices to connect to the gateway. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154115.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param parameters Required. The parameters for the Get Device
* Configuration Script operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return The configuration script returned from the get device
* configuration script operation.
*/
@Override
public GatewayGetDeviceConfigurationScriptResponse getDeviceConfigurationScript(String networkName, GatewayGetDeviceConfigurationScriptParameters parameters) throws IOException, ServiceException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (parameters == null) {
throw new NullPointerException("parameters");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "getDeviceConfigurationScriptAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/vpndeviceconfigurationscript" + "?";
if (parameters.getVendor() != null) {
url = url + "vendor=" + URLEncoder.encode(parameters.getVendor() != null ? parameters.getVendor().trim() : "", "UTF-8");
}
if (parameters.getPlatform() != null) {
url = url + "&" + "platform=" + URLEncoder.encode(parameters.getPlatform() != null ? parameters.getPlatform().trim() : "", "UTF-8");
}
if (parameters.getOSFamily() != null) {
url = url + "&" + "OSfamily=" + URLEncoder.encode(parameters.getOSFamily() != null ? parameters.getOSFamily().trim() : "", "UTF-8");
}
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayGetDeviceConfigurationScriptResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayGetDeviceConfigurationScriptResponse();
result.setConfigurationScript(StreamUtils.toString(responseContent));
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Get Virtual Network Gateway Operation Status gets information on the
* status of network gateway operations in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154112.aspx for
* more information)
*
* @param operationId Required. The ID of the network operation.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> getOperationStatusAsync(final String operationId) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return getOperationStatus(operationId);
}
});
}
/**
* The Get Virtual Network Gateway Operation Status gets information on the
* status of network gateway operations in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154112.aspx for
* more information)
*
* @param operationId Required. The ID of the network operation.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse getOperationStatus(String operationId) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (operationId == null) {
throw new NullPointerException("operationId");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("operationId", operationId);
CloudTracing.enter(invocationId, this, "getOperationStatusAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/operation/" + operationId.trim();
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayGetOperationStatusResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayGetOperationStatusResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element gatewayOperationElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "GatewayOperation");
if (gatewayOperationElement != null) {
Element idElement = XmlUtility.getElementByTagNameNS(gatewayOperationElement, "http://schemas.microsoft.com/windowsazure", "ID");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
result.setId(idInstance);
}
Element statusElement = XmlUtility.getElementByTagNameNS(gatewayOperationElement, "http://schemas.microsoft.com/windowsazure", "Status");
if (statusElement != null) {
GatewayOperationStatus statusInstance;
statusInstance = GatewayOperationStatus.valueOf(statusElement.getTextContent());
result.setStatus(statusInstance);
}
Element httpStatusCodeElement = XmlUtility.getElementByTagNameNS(gatewayOperationElement, "http://schemas.microsoft.com/windowsazure", "HttpStatusCode");
if (httpStatusCodeElement != null) {
Integer httpStatusCodeInstance;
httpStatusCodeInstance = Integer.valueOf(httpStatusCodeElement.getTextContent());
result.setHttpStatusCode(httpStatusCodeInstance);
}
Element errorElement = XmlUtility.getElementByTagNameNS(gatewayOperationElement, "http://schemas.microsoft.com/windowsazure", "Error");
if (errorElement != null) {
GatewayGetOperationStatusResponse.ErrorDetails errorInstance = new GatewayGetOperationStatusResponse.ErrorDetails();
result.setError(errorInstance);
Element codeElement = XmlUtility.getElementByTagNameNS(errorElement, "http://schemas.microsoft.com/windowsazure", "Code");
if (codeElement != null) {
String codeInstance;
codeInstance = codeElement.getTextContent();
errorInstance.setCode(codeInstance);
}
Element messageElement = XmlUtility.getElementByTagNameNS(errorElement, "http://schemas.microsoft.com/windowsazure", "Message");
if (messageElement != null) {
String messageInstance;
messageInstance = messageElement.getTextContent();
errorInstance.setMessage(messageInstance);
}
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Get Virtual Network Gateway Shared Key operation gets the shared key
* on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154122.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @return The response to the get shared key request.
*/
@Override
public Future<GatewayGetSharedKeyResponse> getSharedKeyAsync(final String networkName, final String localNetworkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetSharedKeyResponse>() {
@Override
public GatewayGetSharedKeyResponse call() throws Exception {
return getSharedKey(networkName, localNetworkName);
}
});
}
/**
* The Get Virtual Network Gateway Shared Key operation gets the shared key
* on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154122.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response to the get shared key request.
*/
@Override
public GatewayGetSharedKeyResponse getSharedKey(String networkName, String localNetworkName) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
if (localNetworkName == null) {
throw new NullPointerException("localNetworkName");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkName", localNetworkName);
CloudTracing.enter(invocationId, this, "getSharedKeyAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/connection/" + localNetworkName.trim() + "/sharedkey";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayGetSharedKeyResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayGetSharedKeyResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element sharedKeyElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "SharedKey");
if (sharedKeyElement != null) {
Element valueElement = XmlUtility.getElementByTagNameNS(sharedKeyElement, "http://schemas.microsoft.com/windowsazure", "Value");
if (valueElement != null) {
String valueInstance;
valueInstance = valueElement.getTextContent();
result.setSharedKey(valueInstance);
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The List Connections operation returns a list of the local network
* connections that can be accessed through the gateway. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154120.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @return The response to a ListConnections request to a Virtual Network
* Gateway.
*/
@Override
public Future<GatewayListConnectionsResponse> listConnectionsAsync(final String networkName) {
return this.getClient().getExecutorService().submit(new Callable<GatewayListConnectionsResponse>() {
@Override
public GatewayListConnectionsResponse call() throws Exception {
return listConnections(networkName);
}
});
}
/**
* The List Connections operation returns a list of the local network
* connections that can be accessed through the gateway. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154120.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response to a ListConnections request to a Virtual Network
* Gateway.
*/
@Override
public GatewayListConnectionsResponse listConnections(String networkName) throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
if (networkName == null) {
throw new NullPointerException("networkName");
}
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
CloudTracing.enter(invocationId, this, "listConnectionsAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/" + networkName.trim() + "/gateway/connections";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayListConnectionsResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayListConnectionsResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element connectionsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc, "http://schemas.microsoft.com/windowsazure", "Connections");
if (connectionsSequenceElement != null) {
for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(connectionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Connection").size(); i1 = i1 + 1) {
org.w3c.dom.Element connectionsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(connectionsSequenceElement, "http://schemas.microsoft.com/windowsazure", "Connection").get(i1));
GatewayListConnectionsResponse.GatewayConnection connectionInstance = new GatewayListConnectionsResponse.GatewayConnection();
result.getConnections().add(connectionInstance);
Element localNetworkSiteNameElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "LocalNetworkSiteName");
if (localNetworkSiteNameElement != null) {
String localNetworkSiteNameInstance;
localNetworkSiteNameInstance = localNetworkSiteNameElement.getTextContent();
connectionInstance.setLocalNetworkSiteName(localNetworkSiteNameInstance);
}
Element connectivityStateElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "ConnectivityState");
if (connectivityStateElement != null) {
GatewayConnectivityState connectivityStateInstance;
connectivityStateInstance = GatewayConnectivityState.valueOf(connectivityStateElement.getTextContent());
connectionInstance.setConnectivityState(connectivityStateInstance);
}
Element lastEventElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "LastEvent");
if (lastEventElement != null) {
GatewayEvent lastEventInstance = new GatewayEvent();
connectionInstance.setLastEvent(lastEventInstance);
Element timestampElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Timestamp");
if (timestampElement != null) {
Calendar timestampInstance;
timestampInstance = DatatypeConverter.parseDateTime(timestampElement.getTextContent());
lastEventInstance.setTimestamp(timestampInstance);
}
Element idElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Id");
if (idElement != null) {
String idInstance;
idInstance = idElement.getTextContent();
lastEventInstance.setId(idInstance);
}
Element messageElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Message");
if (messageElement != null) {
String messageInstance;
messageInstance = messageElement.getTextContent();
lastEventInstance.setMessage(messageInstance);
}
Element dataElement = XmlUtility.getElementByTagNameNS(lastEventElement, "http://schemas.microsoft.com/windowsazure", "Data");
if (dataElement != null) {
String dataInstance;
dataInstance = dataElement.getTextContent();
lastEventInstance.setData(dataInstance);
}
}
Element ingressBytesTransferredElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "IngressBytesTransferred");
if (ingressBytesTransferredElement != null) {
long ingressBytesTransferredInstance;
ingressBytesTransferredInstance = DatatypeConverter.parseLong(ingressBytesTransferredElement.getTextContent());
connectionInstance.setIngressBytesTransferred(ingressBytesTransferredInstance);
}
Element egressBytesTransferredElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "EgressBytesTransferred");
if (egressBytesTransferredElement != null) {
long egressBytesTransferredInstance;
egressBytesTransferredInstance = DatatypeConverter.parseLong(egressBytesTransferredElement.getTextContent());
connectionInstance.setEgressBytesTransferred(egressBytesTransferredInstance);
}
Element lastConnectionEstablishedElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "LastConnectionEstablished");
if (lastConnectionEstablishedElement != null) {
Calendar lastConnectionEstablishedInstance;
lastConnectionEstablishedInstance = DatatypeConverter.parseDateTime(lastConnectionEstablishedElement.getTextContent());
connectionInstance.setLastConnectionEstablished(lastConnectionEstablishedInstance);
}
Element allocatedIPAddressesSequenceElement = XmlUtility.getElementByTagNameNS(connectionsElement, "http://schemas.microsoft.com/windowsazure", "AllocatedIPAddresses");
if (allocatedIPAddressesSequenceElement != null) {
for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(allocatedIPAddressesSequenceElement, "http://schemas.microsoft.com/windowsazure", "string").size(); i2 = i2 + 1) {
org.w3c.dom.Element allocatedIPAddressesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(allocatedIPAddressesSequenceElement, "http://schemas.microsoft.com/windowsazure", "string").get(i2));
connectionInstance.getAllocatedIPAddresses().add(allocatedIPAddressesElement.getTextContent());
}
}
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The List Virtual Network Gateway Supported Devices operation lists the
* supported, on-premise network devices that can connect to the gateway.
* (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154102.aspx
* for more information)
*
* @return The response to the list supported devices request.
*/
@Override
public Future<GatewayListSupportedDevicesResponse> listSupportedDevicesAsync() {
return this.getClient().getExecutorService().submit(new Callable<GatewayListSupportedDevicesResponse>() {
@Override
public GatewayListSupportedDevicesResponse call() throws Exception {
return listSupportedDevices();
}
});
}
/**
* The List Virtual Network Gateway Supported Devices operation lists the
* supported, on-premise network devices that can connect to the gateway.
* (see http://msdn.microsoft.com/en-us/library/windowsazure/jj154102.aspx
* for more information)
*
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return The response to the list supported devices request.
*/
@Override
public GatewayListSupportedDevicesResponse listSupportedDevices() throws IOException, ServiceException, ParserConfigurationException, SAXException {
// Validate
// Tracing
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
CloudTracing.enter(invocationId, this, "listSupportedDevicesAsync", tracingParameters);
}
// Construct URL
String url = "/" + (this.getClient().getCredentials().getSubscriptionId() != null ? this.getClient().getCredentials().getSubscriptionId().trim() : "") + "/services/networking/supporteddevices";
String baseUrl = this.getClient().getBaseUri().toString();
// Trim '/' character from the end of baseUrl and beginning of url.
if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
}
if (url.charAt(0) == '/') {
url = url.substring(1);
}
url = baseUrl + "/" + url;
// Create HTTP transport objects
HttpGet httpRequest = new HttpGet(url);
// Set Headers
httpRequest.setHeader("x-ms-version", "2014-05-01");
// Send Request
HttpResponse httpResponse = null;
try {
if (shouldTrace) {
CloudTracing.sendRequest(invocationId, httpRequest);
}
httpResponse = this.getClient().getHttpClient().execute(httpRequest);
if (shouldTrace) {
CloudTracing.receiveResponse(invocationId, httpResponse);
}
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse, httpResponse.getEntity());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
// Create Result
GatewayListSupportedDevicesResponse result = null;
// Deserialize Response
InputStream responseContent = httpResponse.getEntity().getContent();
result = new GatewayListSupportedDevicesResponse();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));
Element vpnDeviceListElement = XmlUtility.getElementByTagNameNS(responseDoc, "", "VpnDeviceList");
if (vpnDeviceListElement != null) {
Attr versionAttribute = vpnDeviceListElement.getAttributeNodeNS("", "version");
if (versionAttribute != null) {
result.setVersion(versionAttribute.getValue());
}
if (vpnDeviceListElement != null) {
for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(vpnDeviceListElement, "", "Vendor").size(); i1 = i1 + 1) {
org.w3c.dom.Element vendorsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(vpnDeviceListElement, "", "Vendor").get(i1));
GatewayListSupportedDevicesResponse.Vendor vendorInstance = new GatewayListSupportedDevicesResponse.Vendor();
result.getVendors().add(vendorInstance);
Attr nameAttribute = vendorsElement.getAttributeNodeNS("", "name");
if (nameAttribute != null) {
vendorInstance.setName(nameAttribute.getValue());
}
if (vendorsElement != null) {
for (int i2 = 0; i2 < com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(vendorsElement, "", "Platform").size(); i2 = i2 + 1) {
org.w3c.dom.Element platformsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(vendorsElement, "", "Platform").get(i2));
GatewayListSupportedDevicesResponse.Platform platformInstance = new GatewayListSupportedDevicesResponse.Platform();
vendorInstance.getPlatforms().add(platformInstance);
Attr nameAttribute2 = platformsElement.getAttributeNodeNS("", "name");
if (nameAttribute2 != null) {
platformInstance.setName(nameAttribute2.getValue());
}
if (platformsElement != null) {
for (int i3 = 0; i3 < com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(platformsElement, "", "OSFamily").size(); i3 = i3 + 1) {
org.w3c.dom.Element oSFamiliesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility.getElementsByTagNameNS(platformsElement, "", "OSFamily").get(i3));
GatewayListSupportedDevicesResponse.OSFamily oSFamilyInstance = new GatewayListSupportedDevicesResponse.OSFamily();
platformInstance.getOSFamilies().add(oSFamilyInstance);
Attr nameAttribute3 = oSFamiliesElement.getAttributeNodeNS("", "name");
if (nameAttribute3 != null) {
oSFamilyInstance.setName(nameAttribute3.getValue());
}
}
}
}
}
}
}
}
result.setStatusCode(statusCode);
if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
return result;
} finally {
if (httpResponse != null && httpResponse.getEntity() != null) {
httpResponse.getEntity().getContent().close();
}
}
}
/**
* The Reset Virtual Network Gateway Shared Key operation resets the shared
* key on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. The parameters to the Virtual Network Gateway
* Reset Shared Key request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> resetSharedKeyAsync(final String networkName, final String localNetworkName, final GatewayResetSharedKeyParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return resetSharedKey(networkName, localNetworkName, parameters);
}
});
}
/**
* The Reset Virtual Network Gateway Shared Key operation resets the shared
* key on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. The parameters to the Virtual Network Gateway
* Reset Shared Key request.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse resetSharedKey(String networkName, String localNetworkName, GatewayResetSharedKeyParameters parameters) throws InterruptedException, ExecutionException, ServiceException, IOException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkName", localNetworkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "resetSharedKeyAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginResetSharedKeyAsync(networkName, localNetworkName, parameters).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
/**
* The Set Virtual Network Gateway Shared Key operation sets the shared key
* on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. The parameters to the Virtual Network Gateway
* Set Shared Key request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public Future<GatewayGetOperationStatusResponse> setSharedKeyAsync(final String networkName, final String localNetworkName, final GatewaySetSharedKeyParameters parameters) {
return this.getClient().getExecutorService().submit(new Callable<GatewayGetOperationStatusResponse>() {
@Override
public GatewayGetOperationStatusResponse call() throws Exception {
return setSharedKey(networkName, localNetworkName, parameters);
}
});
}
/**
* The Set Virtual Network Gateway Shared Key operation sets the shared key
* on the virtual network gateway for the specified virtual network
* connection to the specified local network in Azure. (see
* http://msdn.microsoft.com/en-us/library/windowsazure/jj154114.aspx for
* more information)
*
* @param networkName Required. The name of the virtual network for this
* gateway.
* @param localNetworkName Required. The name of the local network.
* @param parameters Required. The parameters to the Virtual Network Gateway
* Set Shared Key request.
* @throws InterruptedException Thrown when a thread is waiting, sleeping,
* or otherwise occupied, and the thread is interrupted, either before or
* during the activity. Occasionally a method may wish to test whether the
* current thread has been interrupted, and if so, to immediately throw
* this exception. The following code can be used to achieve this effect:
* @throws ExecutionException Thrown when attempting to retrieve the result
* of a task that aborted by throwing an exception. This exception can be
* inspected using the Throwable.getCause() method.
* @throws ServiceException Thrown if the server returned an error for the
* request.
* @throws IOException Thrown if there was an error setting up tracing for
* the request.
* @return The response body contains the status of the specified
* asynchronous operation, indicating whether it has succeeded, is in
* progress, or has failed. Note that this status is distinct from the HTTP
* status code returned for the Get Operation Status operation itself. If
* the asynchronous operation succeeded, the response body includes the
* HTTP status code for the successful request. If the asynchronous
* operation failed, the response body includes the HTTP status code for
* the failed request, and also includes error information regarding the
* failure.
*/
@Override
public GatewayGetOperationStatusResponse setSharedKey(String networkName, String localNetworkName, GatewaySetSharedKeyParameters parameters) throws InterruptedException, ExecutionException, ServiceException, IOException {
NetworkManagementClient client2 = this.getClient();
boolean shouldTrace = CloudTracing.getIsEnabled();
String invocationId = null;
if (shouldTrace) {
invocationId = Long.toString(CloudTracing.getNextInvocationId());
HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
tracingParameters.put("networkName", networkName);
tracingParameters.put("localNetworkName", localNetworkName);
tracingParameters.put("parameters", parameters);
CloudTracing.enter(invocationId, this, "setSharedKeyAsync", tracingParameters);
}
try {
if (shouldTrace) {
client2 = this.getClient().withRequestFilterLast(new ClientRequestTrackingHandler(invocationId)).withResponseFilterLast(new ClientRequestTrackingHandler(invocationId));
}
GatewayOperationResponse response = client2.getGatewaysOperations().beginSetSharedKeyAsync(networkName, localNetworkName, parameters).get();
GatewayGetOperationStatusResponse result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
int delayInSeconds = 30;
if (client2.getLongRunningOperationInitialTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationInitialTimeout();
}
while ((result.getStatus() != GatewayOperationStatus.InProgress) == false) {
Thread.sleep(delayInSeconds * 1000);
result = client2.getGatewaysOperations().getOperationStatusAsync(response.getOperationId()).get();
delayInSeconds = 30;
if (client2.getLongRunningOperationRetryTimeout() >= 0) {
delayInSeconds = client2.getLongRunningOperationRetryTimeout();
}
}
if (shouldTrace) {
CloudTracing.exit(invocationId, result);
}
if (result.getStatus() != GatewayOperationStatus.Successful) {
if (result.getError() != null) {
ServiceException ex = new ServiceException(result.getError().getCode() + " : " + result.getError().getMessage());
ex.setErrorCode(result.getError().getCode());
ex.setErrorMessage(result.getError().getMessage());
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
} else {
ServiceException ex = new ServiceException("");
if (shouldTrace) {
CloudTracing.error(invocationId, ex);
}
throw ex;
}
}
return result;
} finally {
if (client2 != null && shouldTrace) {
client2.close();
}
}
}
}