beautypg.com

Sample request payload – Brocade Network Advisor REST API Guide (Supporting Network Advisor 12.3.0) User Manual

Page 52

background image

38

Brocade Network Advisor REST API Guide

53-1003160-01

Zoning

4

3. Perform the attach operation by calling the following POST URI.

/resourcegroups/All/fcfabrics/fcfkey/attach

4. To detach the initiator from the same targets, the payload is the same, but the POST URI is

different.

/resourcegroups/All/fcfabrics/fcfkey/detach

Sample request payload

The following is an example request payload.

xmlns:tns="http://www.brocade.com/networkadvisor/webservices/v1/zoneservice/r

equest">

false

10:00:00:05:1E:53:0B:93

20:01:00:11:0D:C6:01:01

20:06:00:11:0D:C6:01:01

true

Sample Java code for performing the attach operation

The following is the sample Java code for performing the attach operation. This sample code
assumes that some tool has been used to generate the required code for the requests (refer to

“Binding the schema”

).

HttpURLConnection con = null;

try {

URL obj = new

URL("http://10.24.48.103/rest/resourcegroups/All/fcfabrics/10:00:00:27:F8:42:

B4:0D/attach

");

con = (HttpURLConnection) obj.openConnection();

con.setRequestMethod("POST");

con.addRequestProperty("WStoken", "wppCy/NGdC4o5gGFJjXRMv7blhc=");

con.addRequestProperty("Accept",

"application/vnd.brocade.networkadvisor+json;version=v1");

con.addRequestProperty("Content-type",

"application/vnd.brocade.networkadvisor+xml;version=v1");

JAXBContext jaxbContext =

JAXBContext.newInstance(InitiatorTargetsRequest.class);

Unmarshaller u = jaxbContext.createUnmarshaller();

Object element = u.unmarshal(new File("./InitiatorTargetsRequest.xml"));

Marshaller m = jaxbContext.createMarshaller();

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

m.marshal(element, con.getOutputStream());

System.out.println("CALLING POST

http://10.24.48.103/rest/resourcegroups/All/fcfabrics/10:00:00:27:F8:42:B4:0D

/attach");

int responseCode = con.getResponseCode();

System.out.println("REQUEST HTTPSTATUS = " + responseCode);

if (responseCode != HttpURLConnection.HTTP_OK

&& responseCode != HttpURLConnection.HTTP_NO_CONTENT

&& responseCode != HttpURLConnection.HTTP_PARTIAL

&& responseCode != HttpURLConnection.HTTP_ACCEPTED) {