Example usage for javax.xml.ws Service getPort

List of usage examples for javax.xml.ws Service getPort

Introduction

In this page you can find the example usage for javax.xml.ws Service getPort.

Prototype

public <T> T getPort(Class<T> serviceEndpointInterface) 

Source Link

Document

The getPort method returns a proxy.

Usage

From source file:eu.planets_project.ifr.core.servreg.utils.client.PlanetsCommand.java

/**
 * /*w w w  .  ja va 2 s. c om*/
 * @param args
 */
public static void main(String[] args) {

    /* FIXME, point to log4j.properties instead of doing this? */
    /*
    java.util.logging.Logger.getLogger("com.sun.xml.ws.model").setLevel(java.util.logging.Level.WARNING); 
    java.util.logging.Logger.getAnonymousLogger().setLevel(java.util.logging.Level.WARNING);
    Logger sunlogger = Logger.getLogger("com.sun.xml.ws.model");
    sunlogger.setLevel(Level.WARNING);
    java.util.logging.Logger.getLogger( com.sun.xml.ws.util.Constants.LoggingDomain).setLevel(java.util.logging.Level.WARNING);
    */
    /* Lots of info please: */
    java.util.logging.Logger.getAnonymousLogger().setLevel(java.util.logging.Level.FINEST);
    java.util.logging.Logger.getLogger(com.sun.xml.ws.util.Constants.LoggingDomain)
            .setLevel(java.util.logging.Level.FINEST);
    // TODO See https://jax-ws.dev.java.net/guide/Logging.html for info on more logging to set up.
    //System.setProperty("com.sun.xml.ws.transport.local.LocalTransportPipe.dump","true");
    //System.setProperty("com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.dump","true");
    //System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump","true");
    // Doing this KILLS STREAMING. Log that.
    //System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump","true");

    URL wsdl;
    try {
        wsdl = new URL(args[0]);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return;
    }

    PlanetsServiceExplorer pse = new PlanetsServiceExplorer(wsdl);

    System.out.println(".describe(): " + pse.getServiceDescription());

    Service service = Service.create(wsdl, pse.getQName());
    //service.addPort(portName, SOAPBinding.SOAP11HTTP_MTOM_BINDING, endpointAddress)
    PlanetsService ps = (PlanetsService) service.getPort(pse.getServiceClass());

    // TODO The client wrapper code should enforce this stuff:
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) ps).getBinding();
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    ((BindingProvider) ps).getRequestContext().put(JAXWSProperties.MTOM_THRESHOLOD_VALUE, 8192);
    ((BindingProvider) ps).getRequestContext().put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    binding.setMTOMEnabled(true);
    System.out.println("Logging MTOM=" + binding.isMTOMEnabled());
    //System.out.println("Logging MTOM="+((BindingProvider)ps).getBinding().getBindingID()+" v. "+SOAPBinding.SOAP11HTTP_MTOM_BINDING);

    /* 
     * The different services are invoked in different ways...
     */
    if (pse.getQName().equals(Migrate.QNAME)) {
        System.out.println("Is a Migrate service. ");
        Migrate s = MigrateWrapper.createWrapper(wsdl);

        DigitalObject dobIn = new DigitalObject.Builder(Content.byReference(new File(args[1]))).build();

        MigrateResult result = s.migrate(dobIn, URI.create(args[2]), URI.create(args[3]), null);

        System.out.println("ServiceReport: " + result.getReport());

        DigitalObjectUtils.toFile(result.getDigitalObject(), new File("output"));

    } else if (pse.getQName().equals(Identify.QNAME)) {
        System.out.println("Is an Identify service. ");
        Identify s = new IdentifyWrapper(wsdl);

        DigitalObject dobIn = new DigitalObject.Builder(Content.byReference(new File(args[1]))).build();

        IdentifyResult result = s.identify(dobIn, null);

        System.out.println("ServiceReport: " + result.getReport());
    }
}

From source file:net.cloudkit.enterprises.ws.SuperPassParaProxyTest.java

public static void main(String[] args) throws Exception {

    // CodeLists_Const???XML?
    // MFT2008? RMFT8ChangeReasonCode (AlphaNumber)
    // 001   ?/*from w w  w.j  a  v  a  2 s. c o m*/
    // 002   
    // 003   ?
    // 004   ????
    // 005   ????
    // 006   ??????
    // 007   ????
    // 008   ????
    // 009   ??????
    // 010   ????
    // 011   ???
    // 012   ?
    // 013   ?
    // 014   ?
    // 015   ??
    // 999   
    //
    // MFT2008 RMFT8DeclareTypeCode (AlphaNumber)
    // MT1401   ??
    // MT2401   ???
    // MT5401   ??
    // MT5402   ??
    // MT3402   ?
    // MT7402   ??
    // MT8401   ??
    // MT8402   ??
    // MT8403   ???
    // MT8404   ???
    // MT4401   ??
    // MT4402   ??
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // MFT2008 RMFT8DeclareTypeCodeStat (AlphaNumber)
    // MT1401   ??
    // MT2401   ???
    // MT5401   ??
    // MT5402   ??
    // MT3402   ?
    // MT7402   ??
    // MT8401   ??
    // MT8402   ??
    // MT8403   ???
    // MT8404   ???
    // MT4401   ??
    // MT4402   ??
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // MFT2008 RMFT8FunctionTypeCode (AlphaNumber)
    // 2   
    // 3   
    // T   
    // 5   ?
    // 9   ???
    // 0   ???
    // 11   
    //
    // MFT2008 (AlphaNumber) RMFT8ReponseTypeCode
    // M1   M1-
    // M2   M2-??
    // M3   QP
    // 01   01-?
    // 02   02-
    // 03   03-?
    // 11   11-
    // 12   12-
    // 13   13-??
    // T   T-
    // D   D-?
    // E1   E1-??
    // E2   E2-?
    // E3   E3-??
    // E4   E4-?
    //
    // ?  (AlphaNumber) MasterAffirmSign
    // 0   
    // 1   ?
    // 2   ?
    //
    // ? ? (AlphaNumber) DeclareType
    // 0   
    // 1   
    //
    // MFT2008?? RMFT8MobileTypeCode (AlphaNumber)
    // MT4403   ??
    // MT4404   ??
    // MT4405   ??
    // MT4406   ??
    //
    // ?  RMFT8MobileFuncCode (AlphaNumber)
    // M1   
    // M2   ??
    // M3   QP
    // 2   
    // 3   
    // T   
    // 5   ?
    // 9   ?
    // 0   (??)
    // 11   

    URL url = new URL("http://ceesb.chinaport.gov.cn/SuperPassParaProxy/Proxy_Services/SuperPass_Proxy?wsdl");
    QName qname = new QName("http://www.cneport.com/webservices/superpass", "SuperPass");
    Service service = Service.create(url, qname);
    SuperPass superPass = service.getPort(SuperPass.class);

    /*
    String serviceName = "eport.superpass.pub.para.CustomsFlagStatus";
    byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">c1f4bb</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"IcCode\">8800000246746</Key><Key name=\"OperatorName\"></Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>".getBytes();
    byte[] requestData = "<?xml version=\"1.0\"?>\n<CustomsFlagStatusRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<CustomsCode>5300</CustomsCode>\n</CustomsFlagStatusRequest>".getBytes();
    */

    // ??
    String serviceName = "eport.superpass.pub.para.LoadIntoMemory";
    byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">b6c29b</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"SessionId\">2015-7-14</Key><Key name=\"IcCode\">8910000270086</Key><Key name=\"OperatorName\">??</Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>"
            .getBytes();
    // ? MFT8TrayType
    // SELECT TRAY_CODE,TRAY_NAME FROM MFT8_TRAY_TYPE ORDER BY TRAY_CODE
    // ??? RMFT8TransportType
    // SELECT CODE, NAME FROM mft8_transport_type ORDER BY CODE
    // ? RMFT8CustomsCode
    // SELECT customs_CODE, customs_NAME FROM customs ORDER BY customs_CODE
    // ??(CN003) RMFT8PortCode
    // SELECT CODE, CHNAME FROM mft8_location_name ORDER BY CODE
    // ? RMFT8Curr
    // SELECT CODE, NAME FROM MFT8_ROAD_CURR ORDER BY CODE
    // ? RMFT8ReceiptPlace
    // SELECT CODE, NAME FROM mft8_entity ORDER BY CODE
    // ? RMFT8CountryCode
    // SELECT CODE, NAME FROM mft8_country_code ORDER BY CODE
    // ?? RMFT8CustomStatus
    // SELECT CODE, NAME FROM MFT8_ROAD_CUSTOMS_STATUS ORDER BY CODE
    // ?? RMFT8TransPayCode
    // SELECT CODE, NAME FROM MFT8_ROAD_PAYMENT_METHOD ORDER BY CODE
    // ??(CN005) RMFT8WrapTypeCode
    // SELECT CODE, NAME FROM mft8_packaging ORDER BY CODE
    // ??? RMFT8TransLicCode
    // SELECT CODE, NAME FROM MFT8_CONTR_CAR_COND ORDER BY CODE
    // ?? RMFT8PortWorkCode
    // SELECT CODE, NAME FROM MFT8_HAND_INSTR ORDER BY CODE
    // ?? RMFT8CommunicationCode
    // SELECT CODE, NAME FROM mft8_communi_type ORDER BY CODE
    // ? RMFT8PostCode
    // SELECT CODE, NAME FROM mft8_post_code ORDER BY CODE
    //  RMFT8EquipSizeCode
    // SELECT CODE, SHAPE,LENGTH,HEIGHT,WIDTH FROM mft8_equip_size_type ORDER BY CODE
    // ??? RMFT8EquipSupCode
    // SELECT CODE, NAME FROM MFT8_EQUIP_SUP ORDER BY CODE
    // ?? RMFT8EquipFullCode
    // SELECT CODE, NAME FROM mft8_equip_full ORDER BY CODE
    // ?? RMFT8EquipSealCode
    // SELECT CODE, NAME FROM mft8_seal_agency ORDER BY CODE
    // ??? RMFT8DanGoodsCode
    // SELECT CODE, CHNAME FROM mft8_dan_goods ORDER BY CODE
    // ? RMFT8CusProCode
    // SELECT CODE, NAME FROM mft8_cus_procedure ORDER BY CODE
    // ?/? RMFT8TransportSplitCode
    // SELECT CODE, NAME FROM mft8_indication ORDER BY CODE
    // ?? RMFT8DamageAreaCode
    // SELECT CODE, NAME FROM MFT8_DAMAGE_AREA ORDER BY CODE
    // ?? RMFT8DamageTypeCode
    // SELECT CODE, NAME FROM MFT8_DAMAGE_TYPE_DES ORDER BY CODE
    // IATA?(UN005) RMFT8IATACode
    // SELECT CODE, NAME FROM mft8_iata_code ORDER BY CODE
    // ????(UN009) RMFT8LocodePort
    // SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE
    // RMFT8ComplexCode
    // SELECT CODE_TS, G_NAME FROM complex ORDER BY CODE_TS
    byte[] requestData = "<?xml version=\"1.0\"?>\n<LoadIntoMemoryRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<QuerySql>SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE</QuerySql>\n</LoadIntoMemoryRequest>"
            .getBytes();

    Holder<byte[]> responseData = new Holder<byte[]>();
    System.out.println(new String(superPass.service(serviceName, requestContext, requestData, responseData)));

    // deflate 
    DeflateCompressorInputStream gis = new DeflateCompressorInputStream(
            new ByteArrayInputStream(responseData.value));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int count;
    byte data[] = new byte[1024];
    while ((count = gis.read(data, 0, 1024)) != -1) {
        baos.write(data, 0, count);
    }
    gis.close();

    data = baos.toByteArray();
    baos.flush();
    baos.close();

    System.out.println(new String(data));
    // System.out.println(new String(responseData.value, "UTF-8"));
}

From source file:eu.planets_project.tb.impl.services.util.DiscoveryUtils.java

/**
 * A generic method that can be used as a short-cut for instanciating Planets services.
 * //from w  ww .j  av a2  s . c  o  m
 * e.g. Migrate m = DiscoveryUtils.createServiceClass( Migrate.class, wsdlLocation);
 * 
 * If the given WSDL points to one of the older 'Basic' service forms, it will be wrapped up 
 * to present the new API and hide the old one.
 * 
 * @param <T> Any recognised service class (extends PlanetsService).
 * @param serviceClass The class of the Planets service to instanciate, e.g. Identify.class
 * @param wsdlLocation The location of the WSDL.
 * @return A new instance of the the given class, wrapping the referenced service.
 */
public static <T> T createServiceObject(Class<T> serviceClass, URL wsdlLocation) {
    PlanetsServiceExplorer se = new PlanetsServiceExplorer(wsdlLocation);
    Service service;
    if (serviceClass == null || wsdlLocation == null)
        return null;

    service = Service.create(wsdlLocation, se.getQName());
    return (T) service.getPort(serviceClass);
}

From source file:org.semispace.ws.client.SemiSpaceProxy.java

protected static WsSpace readSpaceServiceAsStandardPort(String endpointAddress) {
    QName SERVICE_NAME = new QName("http://ws.semispace.org/", "WsSpace");
    QName PORT_NAME = new QName("http://ws.semispace.org/", "WsSpacePort");

    Service service = Service.create(SERVICE_NAME);

    // Add a port to the Service
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);

    WsSpace hw = service.getPort(WsSpace.class);
    return hw;/*from   w  ww.  ja v  a 2  s. c  o  m*/
}

From source file:org.semispace.ws.client.SemiSpaceTokenProxy.java

protected static TokenWsSpace readSpaceServiceAsStandardPort(String endpointAddress) {
    QName SERVICE_NAME = new QName("http://ws.semispace.org/", "TokenWsSpace");
    QName PORT_NAME = new QName("http://ws.semispace.org/", "TokenWsSpacePort");

    Service service = Service.create(SERVICE_NAME);

    // Add a port to the Service
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);

    TokenWsSpace hw = service.getPort(TokenWsSpace.class);
    return hw;//  www  . j  a  v  a2 s. c  om
}

From source file:org.jboss.as.test.integration.ws.authentication.EJBEndpointSecuredWSDLAccessTestCase.java

@Test
public void createService() throws Exception {
    QName serviceName = new QName("http://jbossws.org/authenticationForWSDL", "EJB3ServiceForWSDL");
    URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3-for-wsdl/EJB3ServiceForWSDL?wsdl");

    try {/*from  w ww .ja  v  a2s.  c  om*/
        Service service = Service.create(wsdlURL, serviceName);
        EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
        Assert.fail("Proxy shouldn't be created because WSDL access should be secured");
    } catch (WebServiceException e) {
        // failure is expected
    }
}

From source file:mitm.common.ws.AbstractWSProxyFactory.java

private T internalCreateProxy() {
    QName SERVICE_NAME = new QName(nsURI, localPart);
    Service service = Service.create(wsdlURL, SERVICE_NAME);

    T proxy = service.getPort(persistentClass);

    /*//from  w ww .  j  a va 2 s  .  com
     * Make request context multithread safe. See http://markmail.org/message/lgldei2zt4trlyr6
     */
    ((BindingProvider) proxy).getRequestContext().put("thread.local.request.context", Boolean.TRUE);

    Client client = ClientProxy.getClient(proxy);

    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

    httpClientPolicy.setConnectionTimeout(connectTimeOut);
    httpClientPolicy.setReceiveTimeout(receiveTimeOut);

    http.setClient(httpClientPolicy);

    Endpoint endpoint = client.getEndpoint();

    Map<String, Object> outProps = new HashMap<String, Object>();

    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordMode.getMode());

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);

    return proxy;
}

From source file:eu.planets_project.tb.gui.backing.exp.view.EmulationInspector.java

/** */
private void initViewResultBean() {
    if (this.experiment == null)
        return;/*from w w  w  .  ja va  2  s .c  o  m*/
    if (this.sessionId == null || "".equals(this.sessionId)) {
        return;
    }
    // Look up this session id in the experiment:
    List<ExecutionRecordImpl> executionRecords = new ArrayList<ExecutionRecordImpl>();
    for (BatchExecutionRecordImpl batch : experiment.getExperimentExecutable().getBatchExecutionRecords()) {
        for (ExecutionRecordImpl run : batch.getRuns()) {
            executionRecords.add(run);
        }
    }
    List<ViewResultBean> vrbs = ViewResultBean.createResultsFromExecutionRecords(executionRecords);
    // Look for a match:
    for (ViewResultBean vrb : vrbs) {
        if (this.sessionId.equals(vrb.getSessionId())) {
            this.vrb = vrb;
        }
    }

    // Also fire up the connection to the service:
    try {
        Service serv = Service.create(vrb.getEndpoint(), CreateView.QNAME);
        this.viewService = serv.getPort(CreateView.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java

/**
 * Runs the XCDLComparator on two given xcdls and returns the comparison result.
 * @param xcdl1//from   w w w  .  j a v  a2 s .  c  o  m
 * @param xcdl2
 * @return
 * @throws Exception
 */
private String runXCDLComparator(String xcdl1, String xcdl2) throws Exception {

    URL url = null;
    try {
        url = new URL(URL_XCDLCOMPARATOR);

        Service service = Service.create(url, new QName(PlanetsServices.NS, Compare.NAME));
        Compare comparator = service.getPort(Compare.class);

        //the service call and it's result
        DigitalObject x1 = new DigitalObject.Builder(Content.byValue(xcdl1.getBytes())).build();
        DigitalObject x2 = new DigitalObject.Builder(Content.byValue(xcdl2.getBytes())).build();
        List<Property> result = comparator.compare(x1, x2, null).getProperties();

        if (result == null) {
            throw new Exception("XCDL comparison failed - please check service logs for details");
        }

        return result.toString();

    } catch (MalformedURLException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:eu.planets_project.tb.impl.services.mockups.workflow.WorkflowDroidXCDLExtractorComparator.java

/**
 * Runs droid on a given File and returns an Array of PronomIDs
 * @param f1/*from  w  w  w  .jav  a 2s  . c  om*/
 * @return
 * @throws Exception
 */
private String[] runDroid(File f1) throws Exception {
    //Step1: identify using droid - returns a status and a list of IDs
    URL url = null;
    try {
        url = new URL(URL_DROID);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        throw e;
    }
    Service service = Service.create(url, new QName(PlanetsServices.NS, Identify.NAME));
    Identify droid = service.getPort(Identify.class);
    byte[] array = FileUtils.readFileToByteArray(f1);

    //invoke the service and extract results
    IdentifyResult identify = droid.identify(new DigitalObject.Builder(Content.byValue(array)).build(), null);
    List<URI> result = identify.getTypes();
    String status = identify.getReport().getMessage();

    if (!status.equals("Positive")) {
        throw new Exception("Service execution failed");
    }
    if (result.size() < 1) {
        throw new Exception("The specified file type is currently not supported by this workflow");
    }

    String[] strings = new String[result.size()];
    for (int i = 0; i < result.size(); i++) {
        String string = result.get(i).toASCIIString();
        //received 1..n Pronom IDs
        strings[i] = string;
    }
    return strings;
}